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

Side by Side Diff: third_party/WebKit/Source/modules/offscreencanvas/OffscreenCanvasModules.cpp

Issue 2255683005: Determine if OffscreenCanvas is paintable in different rendering contexts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Canvas2DTypecast
Patch Set: Created 4 years, 4 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/offscreencanvas/OffscreenCanvasModules.h" 5 #include "modules/offscreencanvas/OffscreenCanvasModules.h"
6 6
7 #include "core/html/canvas/CanvasContextCreationAttributes.h" 7 #include "core/html/canvas/CanvasContextCreationAttributes.h"
8 #include "core/offscreencanvas/OffscreenCanvas.h" 8 #include "core/offscreencanvas/OffscreenCanvas.h"
9 #include "modules/imagebitmap/ImageBitmapRenderingContext.h"
9 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" 10 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h"
11 #include "modules/webgl/WebGLRenderingContextBase.h"
12 #include "platform/graphics/ImageBuffer.h"
10 13
11 namespace blink { 14 namespace blink {
12 15
13 void OffscreenCanvasModules::getContext(ScriptState* scriptState, OffscreenCanva s& offscreenCanvas, const String& id, const CanvasContextCreationAttributes& att ributes, ExceptionState& exceptionState, OffscreenRenderingContext& result) 16 void OffscreenCanvasModules::getContext(ScriptState* scriptState, OffscreenCanva s& offscreenCanvas, const String& id, const CanvasContextCreationAttributes& att ributes, ExceptionState& exceptionState, OffscreenRenderingContext& result)
14 { 17 {
15 if (offscreenCanvas.isNeutered()) { 18 if (offscreenCanvas.isNeutered()) {
16 exceptionState.throwDOMException(InvalidStateError, "OffscreenCanvas obj ect is detached"); 19 exceptionState.throwDOMException(InvalidStateError, "OffscreenCanvas obj ect is detached");
17 return; 20 return;
18 } 21 }
19 22
20 CanvasRenderingContext* context = offscreenCanvas.getCanvasRenderingContext( scriptState, id, attributes); 23 CanvasRenderingContext* context = offscreenCanvas.getCanvasRenderingContext( scriptState, id, attributes);
21 if (context) 24 if (context)
22 context->setOffscreenCanvasGetContextResult(result); 25 context->setOffscreenCanvasGetContextResult(result);
23 } 26 }
24 27
28 bool OffscreenCanvasModules::isPaintable(OffscreenCanvas& offscreenCanvas)
Justin Novosad 2016/08/19 14:55:47 There is a cleaner way to implement this: put a pu
29 {
30 CanvasRenderingContext* context = offscreenCanvas.renderingContext();
31 if (!context)
32 return ImageBuffer::canCreateImageBuffer(offscreenCanvas.size());
33
34 if (context->is2d())
35 return toOffscreenCanvasRenderingContext2D(context)->imageBuffer();
36 if (context->is3d())
37 return toWebGLRenderingContextBase(context)->drawingBuffer();
38 if (context->getContextType() == CanvasRenderingContext::ContextImageBitmap)
39 return toImageBitmapRenderingContext(context)->image();
40
41 NOTREACHED();
42 return false;
43 }
44
25 } // namespace blink 45 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698