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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "modules/imagebitmap/ImageBitmapRenderingContext.h"
6
7 #include "core/frame/ImageBitmap.h"
8 #include "platform/graphics/GraphicsContext.h"
9 #include "platform/graphics/StaticBitmapImage.h"
10 #include "third_party/skia/include/core/SkImage.h"
11 #include "third_party/skia/include/core/SkSurface.h"
12
13 namespace blink {
14
15 ImageBitmapRenderingContext::ImageBitmapRenderingContext(HTMLCanvasElement* canv as, CanvasContextCreationAttributes attrs, Document& document)
16 : CanvasRenderingContext(canvas)
17 , m_hasAlpha(attrs.alpha())
18 { }
19
20 ImageBitmapRenderingContext::~ImageBitmapRenderingContext() { }
21
22 void ImageBitmapRenderingContext::transferImageBitmap(ImageBitmap* imageBitmap)
23 {
24 m_image = imageBitmap->bitmapImage();
25 if (!m_image)
26 return;
27
28 RefPtr<SkImage> skImage = m_image->imageForCurrentFrame();
29 if (skImage->isTextureBacked()) {
30 // TODO(junov): crbug.com/585607 Eliminate this readback and use an Exte rnalTextureLayer
31 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(skIma ge->width(), skImage->height()));
32 if (!surface) {
33 // silent failure
34 m_image.clear();
35 return;
36 }
37 surface->getCanvas()->drawImage(skImage.get(), 0, 0);
38 m_image = StaticBitmapImage::create(adoptRef(surface->newImageSnapshot() ));
39 }
40 canvas()->didDraw(FloatRect(FloatPoint(), FloatSize(m_image->width(), m_imag e->height())));
41 }
42
43 bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r)
44 {
45 if (!m_image)
46 return true;
47
48 // With impl-side painting, it is unsafe to use a gpu-backed SkImage
49 ASSERT(!m_image->imageForCurrentFrame()->isTextureBacked());
50 gc.drawImage(m_image.get(), r, m_hasAlpha ? SkXfermode::kSrcOver_Mode : SkXf ermode::kSrc_Mode);
51
52 return true;
53 }
54
55 PassOwnPtrWillBeRawPtr<CanvasRenderingContext> ImageBitmapRenderingContext::Fact ory::create(HTMLCanvasElement* canvas, const CanvasContextCreationAttributes& at trs, Document& document)
56 {
57 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled())
58 return nullptr;
59 return adoptPtrWillBeNoop(new ImageBitmapRenderingContext(canvas, attrs, doc ument));
60 }
61
62 void ImageBitmapRenderingContext::stop()
63 {
64 m_image.clear();
65 }
66
67 } // blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698