Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Unified Diff: third_party/WebKit/Source/modules/imagebitmap/ImageBitmapRenderingContext.cpp

Issue 1598923002: Add ImageBitmapRenderingContext (experimental) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another missing adoptRef Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..bc5612619ee910980c9c740422295a099f78f112
--- /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();
+ 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
+ RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(skImage->width(), skImage->height()));
+ if (!surface) {
+ // silent failure
+ m_image.clear();
+ return;
+ }
+ surface->getCanvas()->drawImage(skImage.get(), 0, 0);
+ m_image = StaticBitmapImage::create(adoptRef(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

Powered by Google App Engine
This is Rietveld 408576698