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

Side by Side Diff: third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp

Issue 2326633002: Adds filter support for offscreen canvas (Closed)
Patch Set: Code using ConversionData 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/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" 5 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h"
6 6
7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC ontextOrWebGL2RenderingContext.h" 7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC ontextOrWebGL2RenderingContext.h"
8 #include "core/frame/ImageBitmap.h" 8 #include "core/frame/ImageBitmap.h"
9 #include "core/frame/Settings.h" 9 #include "core/frame/Settings.h"
10 #include "core/workers/WorkerGlobalScope.h" 10 #include "core/workers/WorkerGlobalScope.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 } 46 }
47 47
48 void OffscreenCanvasRenderingContext2D::commit(ScriptState* scriptState, 48 void OffscreenCanvasRenderingContext2D::commit(ScriptState* scriptState,
49 ExceptionState& exceptionState) { 49 ExceptionState& exceptionState) {
50 UseCounter::Feature feature = UseCounter::OffscreenCanvasCommit2D; 50 UseCounter::Feature feature = UseCounter::OffscreenCanvasCommit2D;
51 UseCounter::count(scriptState->getExecutionContext(), feature); 51 UseCounter::count(scriptState->getExecutionContext(), feature);
52 if (getOffscreenCanvas()->getAssociatedCanvasId() < 0) { 52 if (getOffscreenCanvas()->getAssociatedCanvasId() < 0) {
53 // If an OffscreenCanvas has no associated canvas Id, it indicates that 53 // If an OffscreenCanvas has no associated canvas Id, it indicates that
54 // it is not an OffscreenCanvas created by transfering control from html 54 // it is not an OffscreenCanvas created by transfering control from html
55 // canvas. 55 // canvas.
56 exceptionState.throwDOMException(InvalidStateError, 56 exceptionState.throwDOMException(
57 "Commit() was called on a context whose " 57 InvalidStateError,
58 "OffscreenCanvas is not associated with a " 58 "Commit() was called on a context whose OffscreenCanvas is not "
59 "canvas element."); 59 "associated with a canvas element.");
60 return; 60 return;
61 } 61 }
62 double commitStartTime = WTF::monotonicallyIncreasingTime(); 62 double commitStartTime = WTF::monotonicallyIncreasingTime();
63 RefPtr<StaticBitmapImage> image = this->transferToStaticBitmapImage(); 63 RefPtr<StaticBitmapImage> image = this->transferToStaticBitmapImage();
64 getOffscreenCanvas()->getOrCreateFrameDispatcher()->dispatchFrame( 64 getOffscreenCanvas()->getOrCreateFrameDispatcher()->dispatchFrame(
65 std::move(image), commitStartTime); 65 std::move(image), commitStartTime);
66 } 66 }
67 67
68 // BaseRenderingContext2D implementation 68 // BaseRenderingContext2D implementation
69 bool OffscreenCanvasRenderingContext2D::originClean() const { 69 bool OffscreenCanvasRenderingContext2D::originClean() const {
70 return getOffscreenCanvas()->originClean(); 70 return getOffscreenCanvas()->originClean();
71 } 71 }
72 72
73 void OffscreenCanvasRenderingContext2D::setOriginTainted() { 73 void OffscreenCanvasRenderingContext2D::setOriginTainted() {
74 return getOffscreenCanvas()->setOriginTainted(); 74 return getOffscreenCanvas()->setOriginTainted();
75 } 75 }
76 76
77 bool OffscreenCanvasRenderingContext2D::wouldTaintOrigin( 77 bool OffscreenCanvasRenderingContext2D::wouldTaintOrigin(
78 CanvasImageSource* source, 78 CanvasImageSource* source,
79 ExecutionContext* executionContext) { 79 ExecutionContext* executionContext) {
80 if (executionContext->isWorkerGlobalScope()) { 80 if (executionContext->isWorkerGlobalScope()) {
81 // We only support passing in ImageBitmap and OffscreenCanvases as source 81 // We only support passing in ImageBitmap and OffscreenCanvases as
82 // images in drawImage() or createPattern() in a OffscreenCanvas2d in 82 // source images in drawImage() or createPattern() in a
83 // worker. 83 // OffscreenCanvas2d in worker.
84 DCHECK(source->isImageBitmap() || source->isOffscreenCanvas()); 84 DCHECK(source->isImageBitmap() || source->isOffscreenCanvas());
85 } 85 }
86 86
87 return CanvasRenderingContext::wouldTaintOrigin( 87 return CanvasRenderingContext::wouldTaintOrigin(
88 source, executionContext->getSecurityOrigin()); 88 source, executionContext->getSecurityOrigin());
89 } 89 }
90 90
91 int OffscreenCanvasRenderingContext2D::width() const { 91 int OffscreenCanvasRenderingContext2D::width() const {
92 return getOffscreenCanvas()->width(); 92 return getOffscreenCanvas()->width();
93 } 93 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 211
212 AffineTransform OffscreenCanvasRenderingContext2D::baseTransform() const { 212 AffineTransform OffscreenCanvasRenderingContext2D::baseTransform() const {
213 if (!m_imageBuffer) 213 if (!m_imageBuffer)
214 return AffineTransform(); // identity 214 return AffineTransform(); // identity
215 return m_imageBuffer->baseTransform(); 215 return m_imageBuffer->baseTransform();
216 } 216 }
217 217
218 void OffscreenCanvasRenderingContext2D::didDraw(const SkIRect& dirtyRect) {} 218 void OffscreenCanvasRenderingContext2D::didDraw(const SkIRect& dirtyRect) {}
219 219
220 bool OffscreenCanvasRenderingContext2D::stateHasFilter() { 220 bool OffscreenCanvasRenderingContext2D::stateHasFilter() {
221 // TODO: crbug.com/593838 make hasFilter accept nullptr 221 return state().hasFilterForOffscreenCanvas(getOffscreenCanvas()->size());
222 // return state().hasFilter(nullptr, nullptr, IntSize(width(), height()),
223 // this);
224 return false;
225 } 222 }
226 223
227 sk_sp<SkImageFilter> OffscreenCanvasRenderingContext2D::stateGetFilter() { 224 sk_sp<SkImageFilter> OffscreenCanvasRenderingContext2D::stateGetFilter() {
228 // TODO: make getFilter accept nullptr 225 return state().getFilterForOffscreenCanvas(getOffscreenCanvas()->size());
229 // return state().getFilter(nullptr, nullptr, IntSize(width(), height()), 226 }
230 // this); 227
231 return nullptr; 228 void OffscreenCanvasRenderingContext2D::setFilter(const String& filterString) {
229 BaseRenderingContext2D::setFilter(filterString);
232 } 230 }
233 231
234 void OffscreenCanvasRenderingContext2D::validateStateStack() const { 232 void OffscreenCanvasRenderingContext2D::validateStateStack() const {
235 #if DCHECK_IS_ON() 233 #if DCHECK_IS_ON()
236 if (SkCanvas* skCanvas = existingDrawingCanvas()) { 234 if (SkCanvas* skCanvas = existingDrawingCanvas()) {
237 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()), 235 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()),
238 m_stateStack.size() + 1); 236 m_stateStack.size() + 1);
239 } 237 }
240 #endif 238 #endif
241 } 239 }
242 240
243 bool OffscreenCanvasRenderingContext2D::isContextLost() const { 241 bool OffscreenCanvasRenderingContext2D::isContextLost() const {
244 return false; 242 return false;
245 } 243 }
246 244
247 bool OffscreenCanvasRenderingContext2D::isPaintable() const { 245 bool OffscreenCanvasRenderingContext2D::isPaintable() const {
248 return this->imageBuffer(); 246 return this->imageBuffer();
249 } 247 }
250 } 248 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698