Chromium Code Reviews| Index: third_party/WebKit/Source/modules/imagebitmap/ImageBitmapRenderingContext.cpp |
| diff --git a/third_party/WebKit/Source/modules/imagebitmap/ImageBitmapRenderingContext.cpp b/third_party/WebKit/Source/modules/imagebitmap/ImageBitmapRenderingContext.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2f40f009b02a31d88d893cec860301035e9ff54c |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/imagebitmap/ImageBitmapRenderingContext.cpp |
| @@ -0,0 +1,67 @@ |
| +// Copyright 2016 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 "modules/imagebitmap/ImageBitmapRenderingContext.h" |
| + |
| +#include "core/frame/ImageBitmap.h" |
| +#include "platform/graphics/GraphicsContext.h" |
| +#include "platform/graphics/StaticBitmapImage.h" |
| +#include "third_party/skia/include/core/SkImage.h" |
| +#include "third_party/skia/include/core/SkSurface.h" |
| + |
| +namespace blink { |
| + |
| +ImageBitmapRenderingContext::ImageBitmapRenderingContext(HTMLCanvasElement* canvas, CanvasContextCreationAttributes attrs, Document& document) |
| + : CanvasRenderingContext(canvas) |
| + , m_hasAlpha(attrs.alpha()) |
| +{ } |
| + |
| +ImageBitmapRenderingContext::~ImageBitmapRenderingContext() { } |
| + |
| +void ImageBitmapRenderingContext::transferImageBitmap(ImageBitmap* imageBitmap) |
| +{ |
| + m_image = imageBitmap->bitmapImage(); |
|
Stephen White
2016/02/10 15:34:55
colorPicker->pickColorColorPickPick(). :)
Justin Novosad
2016/02/10 15:50:21
LOL!!! The old days...
|
| + if (!m_image) |
| + return; |
| + |
| + RefPtr<SkImage> skImage = m_image->imageForCurrentFrame(); |
| + if (skImage->isTextureBacked()) { |
| + // TODO(junov): crbug.com/585607 Eliminate this readback and use an ExternalTextureLayer |
|
Stephen White
2016/02/10 15:34:55
Should we do this check only for display-list canv
Justin Novosad
2016/02/10 15:50:21
It is not display list canvas that is the problem,
Stephen White
2016/02/10 15:56:08
Right, but isn't impl-side rasterization only util
Justin Novosad
2016/02/10 16:09:29
There is no "display list mode". The concept of di
Stephen White
2016/02/10 16:11:34
Acknowledged. These are not the nits you're lookin
|
| + RefPtr<SkSurface> surface = SkSurface::NewRasterN32Premul(skImage->width(), skImage->height()); |
| + if (!surface) { |
| + // silent failure |
|
Stephen White
2016/02/10 15:34:55
Is a silent failure spec-compliant? If not, please
Justin Novosad
2016/02/10 15:50:21
The handling of general OOM failures is not specif
Stephen White
2016/02/10 15:56:08
Acknowledged.
|
| + m_image.clear(); |
| + return; |
| + } |
| + surface->getCanvas()->drawImage(skImage.get(), 0, 0); |
| + m_image = StaticBitmapImage::create(surface->newImageSnapshot()); |
| + } |
| + canvas()->didDraw(FloatRect(FloatPoint(), FloatSize(m_image->width(), m_image->height()))); |
| +} |
| + |
| +bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r) |
| +{ |
| + if (!m_image) |
| + return true; |
| + |
| + // With impl-side painting, it is unsafe to use a gpu-backed SkImage |
| + ASSERT(!m_image->imageForCurrentFrame()->isTextureBacked()); |
| + gc.drawImage(m_image.get(), r, m_hasAlpha ? SkXfermode::kSrcOver_Mode : SkXfermode::kSrc_Mode); |
| + |
| + return true; |
| +} |
| + |
| +PassOwnPtrWillBeRawPtr<CanvasRenderingContext> ImageBitmapRenderingContext::Factory::create(HTMLCanvasElement* canvas, const CanvasContextCreationAttributes& attrs, Document& document) |
| +{ |
| + if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled()) |
| + return nullptr; |
| + return adoptPtrWillBeNoop(new ImageBitmapRenderingContext(canvas, attrs, document)); |
| +} |
| + |
| +void ImageBitmapRenderingContext::stop() |
| +{ |
| + m_image.clear(); |
| +} |
| + |
| +} // blink |