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

Side by Side Diff: third_party/WebKit/Source/modules/imagebitmap/ImageBitmapRenderingContext.cpp

Issue 2459233002: Consolidate implementation of ImageBitmapRenderingContext (Closed)
Patch Set: fix a layout test failure Created 4 years, 1 month 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/imagebitmap/ImageBitmapRenderingContext.h" 5 #include "modules/imagebitmap/ImageBitmapRenderingContext.h"
6 6
7 #include "bindings/modules/v8/RenderingContext.h" 7 #include "bindings/modules/v8/RenderingContext.h"
8 #include "core/frame/ImageBitmap.h" 8 #include "core/frame/ImageBitmap.h"
9 #include "platform/graphics/GraphicsContext.h" 9 #include "platform/graphics/GraphicsContext.h"
10 #include "platform/graphics/StaticBitmapImage.h" 10 #include "platform/graphics/StaticBitmapImage.h"
11 #include "third_party/skia/include/core/SkImage.h" 11 #include "third_party/skia/include/core/SkImage.h"
12 #include "third_party/skia/include/core/SkSurface.h" 12 #include "third_party/skia/include/core/SkSurface.h"
13 13
14 namespace blink { 14 namespace blink {
15 15
16 ImageBitmapRenderingContext::ImageBitmapRenderingContext( 16 ImageBitmapRenderingContext::ImageBitmapRenderingContext(
17 HTMLCanvasElement* canvas, 17 HTMLCanvasElement* canvas,
18 const CanvasContextCreationAttributes& attrs, 18 const CanvasContextCreationAttributes& attrs,
19 Document& document) 19 Document& document)
20 : CanvasRenderingContext(canvas, nullptr, attrs) {} 20 : CanvasRenderingContext(canvas, nullptr, attrs) {}
21 21
22 ImageBitmapRenderingContext::~ImageBitmapRenderingContext() {} 22 ImageBitmapRenderingContext::~ImageBitmapRenderingContext() {}
23 23
24 void ImageBitmapRenderingContext::setCanvasGetContextResult( 24 void ImageBitmapRenderingContext::setCanvasGetContextResult(
25 RenderingContext& result) { 25 RenderingContext& result) {
26 result.setImageBitmapRenderingContext(this); 26 result.setImageBitmapRenderingContext(this);
27 } 27 }
28 28
29 void ImageBitmapRenderingContext::transferFromImageBitmap( 29 void ImageBitmapRenderingContext::transferFromImageBitmap(
30 ImageBitmap* imageBitmap) { 30 ImageBitmap* imageBitmap,
31 ExceptionState& exceptionState) {
31 if (!imageBitmap) { 32 if (!imageBitmap) {
32 m_image.release(); 33 m_image.release();
33 return; 34 return;
34 } 35 }
35 36
37 if (imageBitmap->isNeutered()) {
38 exceptionState.throwDOMException(InvalidStateError,
39 "The input ImageBitmap has been detached");
40 return;
41 }
42
36 m_image = imageBitmap->bitmapImage(); 43 m_image = imageBitmap->bitmapImage();
37 if (!m_image) 44 if (!m_image)
38 return; 45 return;
39 46
40 sk_sp<SkImage> skImage = m_image->imageForCurrentFrame(); 47 sk_sp<SkImage> skImage = m_image->imageForCurrentFrame();
41 if (skImage->isTextureBacked()) { 48 if (skImage->isTextureBacked()) {
42 // TODO(junov): crbug.com/585607 Eliminate this readback and use an 49 // TODO(junov): crbug.com/585607 Eliminate this readback and use an
43 // ExternalTextureLayer 50 // ExternalTextureLayer
44 sk_sp<SkSurface> surface = 51 sk_sp<SkSurface> surface =
45 SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height()); 52 SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height());
46 if (!surface) { 53 if (!surface) {
47 // silent failure 54 // silent failure
48 m_image.clear(); 55 m_image.clear();
49 return; 56 return;
50 } 57 }
51 surface->getCanvas()->drawImage(skImage, 0, 0); 58 surface->getCanvas()->drawImage(skImage, 0, 0);
52 m_image = StaticBitmapImage::create(surface->makeImageSnapshot()); 59 m_image = StaticBitmapImage::create(surface->makeImageSnapshot());
53 } 60 }
54 canvas()->didDraw( 61 canvas()->didDraw(
55 FloatRect(FloatPoint(), FloatSize(m_image->width(), m_image->height()))); 62 FloatRect(FloatPoint(), FloatSize(m_image->width(), m_image->height())));
63 imageBitmap->close();
56 } 64 }
57 65
58 bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r) { 66 bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r) {
59 if (!m_image) 67 if (!m_image)
60 return true; 68 return true;
61 69
62 // With impl-side painting, it is unsafe to use a gpu-backed SkImage 70 // With impl-side painting, it is unsafe to use a gpu-backed SkImage
63 ASSERT(!m_image->imageForCurrentFrame()->isTextureBacked()); 71 ASSERT(!m_image->imageForCurrentFrame()->isTextureBacked());
64 gc.drawImage(m_image.get(), r, nullptr, creationAttributes().alpha() 72 gc.drawImage(m_image.get(), r, nullptr, creationAttributes().alpha()
65 ? SkXfermode::kSrcOver_Mode 73 ? SkXfermode::kSrcOver_Mode
66 : SkXfermode::kSrc_Mode); 74 : SkXfermode::kSrc_Mode);
67 75
68 return true; 76 return true;
69 } 77 }
70 78
71 CanvasRenderingContext* ImageBitmapRenderingContext::Factory::create( 79 CanvasRenderingContext* ImageBitmapRenderingContext::Factory::create(
72 HTMLCanvasElement* canvas, 80 HTMLCanvasElement* canvas,
73 const CanvasContextCreationAttributes& attrs, 81 const CanvasContextCreationAttributes& attrs,
74 Document& document) { 82 Document& document) {
75 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled()) 83 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled())
76 return nullptr; 84 return nullptr;
77 return new ImageBitmapRenderingContext(canvas, attrs, document); 85 return new ImageBitmapRenderingContext(canvas, attrs, document);
78 } 86 }
79 87
80 void ImageBitmapRenderingContext::stop() { 88 void ImageBitmapRenderingContext::stop() {
81 m_image.clear(); 89 m_image.clear();
82 } 90 }
83 91
84 } // blink 92 } // blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698