blob: 85f604991d1cba97304fdfed20d0e5963696f80e [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context_host.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context.h"
#include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h"
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h"
#include "third_party/skia/include/core/SkSurface.h"
namespace blink {
CanvasRenderingContextHost::CanvasRenderingContextHost() = default;
scoped_refptr<StaticBitmapImage>
CanvasRenderingContextHost::CreateTransparentImage(const IntSize& size) const {
if (!IsValidImageSize(size))
return nullptr;
CanvasColorParams color_params = CanvasColorParams();
if (RenderingContext())
color_params = RenderingContext()->ColorParams();
SkImageInfo info = SkImageInfo::Make(
size.Width(), size.Height(), color_params.GetSkColorType(),
kPremul_SkAlphaType, color_params.GetSkColorSpaceForSkSurfaces());
sk_sp<SkSurface> surface =
SkSurface::MakeRaster(info, info.minRowBytes(), nullptr);
if (!surface)
return nullptr;
return StaticBitmapImage::Create(surface->makeImageSnapshot());
}
bool CanvasRenderingContextHost::IsPaintable() const {
return (RenderingContext() && RenderingContext()->IsPaintable()) ||
IsValidImageSize(Size());
}
void CanvasRenderingContextHost::RestoreCanvasMatrixClipStack(
PaintCanvas* canvas) const {
if (RenderingContext())
RenderingContext()->RestoreCanvasMatrixClipStack(canvas);
}
} // namespace blink