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

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

Issue 2727133002: Remove ColorBehavior argument to Image::imageForCurrentFrame (Closed)
Patch Set: Rebase Created 3 years, 9 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
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"
(...skipping 26 matching lines...) Expand all
37 if (imageBitmap->isNeutered()) { 37 if (imageBitmap->isNeutered()) {
38 exceptionState.throwDOMException(InvalidStateError, 38 exceptionState.throwDOMException(InvalidStateError,
39 "The input ImageBitmap has been detached"); 39 "The input ImageBitmap has been detached");
40 return; 40 return;
41 } 41 }
42 42
43 m_image = imageBitmap->bitmapImage(); 43 m_image = imageBitmap->bitmapImage();
44 if (!m_image) 44 if (!m_image)
45 return; 45 return;
46 46
47 // TODO(ccameron): Determine the correct color behavior here. 47 sk_sp<SkImage> skImage = m_image->imageForCurrentFrame();
48 // ImageBitmapRenderingContext.
49 // https://crbug.com/672306
50 sk_sp<SkImage> skImage =
51 m_image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget());
52 if (skImage->isTextureBacked()) { 48 if (skImage->isTextureBacked()) {
53 // TODO(junov): crbug.com/585607 Eliminate this readback and use an 49 // TODO(junov): crbug.com/585607 Eliminate this readback and use an
54 // ExternalTextureLayer 50 // ExternalTextureLayer
55 sk_sp<SkSurface> surface = 51 sk_sp<SkSurface> surface =
56 SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height()); 52 SkSurface::MakeRasterN32Premul(skImage->width(), skImage->height());
57 if (!surface) { 53 if (!surface) {
58 // silent failure 54 // silent failure
59 m_image.clear(); 55 m_image.clear();
60 return; 56 return;
61 } 57 }
62 surface->getCanvas()->drawImage(skImage, 0, 0); 58 surface->getCanvas()->drawImage(skImage, 0, 0);
63 m_image = StaticBitmapImage::create(surface->makeImageSnapshot()); 59 m_image = StaticBitmapImage::create(surface->makeImageSnapshot());
64 } 60 }
65 didDraw(skImage->bounds()); 61 didDraw(skImage->bounds());
66 imageBitmap->close(); 62 imageBitmap->close();
67 } 63 }
68 64
69 bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r) { 65 bool ImageBitmapRenderingContext::paint(GraphicsContext& gc, const IntRect& r) {
70 if (!m_image) 66 if (!m_image)
71 return true; 67 return true;
72 68
73 // With impl-side painting, it is unsafe to use a gpu-backed SkImage 69 // With impl-side painting, it is unsafe to use a gpu-backed SkImage
74 DCHECK( 70 DCHECK(!m_image->imageForCurrentFrame()->isTextureBacked());
75 !m_image->imageForCurrentFrame(ColorBehavior::transformToGlobalTarget())
76 ->isTextureBacked());
77 gc.drawImage(m_image.get(), r, nullptr, creationAttributes().alpha() 71 gc.drawImage(m_image.get(), r, nullptr, creationAttributes().alpha()
78 ? SkBlendMode::kSrcOver 72 ? SkBlendMode::kSrcOver
79 : SkBlendMode::kSrc); 73 : SkBlendMode::kSrc);
80 74
81 return true; 75 return true;
82 } 76 }
83 77
84 CanvasRenderingContext* ImageBitmapRenderingContext::Factory::create( 78 CanvasRenderingContext* ImageBitmapRenderingContext::Factory::create(
85 HTMLCanvasElement* canvas, 79 HTMLCanvasElement* canvas,
86 const CanvasContextCreationAttributes& attrs, 80 const CanvasContextCreationAttributes& attrs,
87 Document& document) { 81 Document& document) {
88 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled()) 82 if (!RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled())
89 return nullptr; 83 return nullptr;
90 return new ImageBitmapRenderingContext(canvas, attrs, document); 84 return new ImageBitmapRenderingContext(canvas, attrs, document);
91 } 85 }
92 86
93 void ImageBitmapRenderingContext::stop() { 87 void ImageBitmapRenderingContext::stop() {
94 m_image.clear(); 88 m_image.clear();
95 } 89 }
96 90
97 } // blink 91 } // blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698