OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef OffscreenCanvas_h | 5 #ifndef OffscreenCanvas_h |
6 #define OffscreenCanvas_h | 6 #define OffscreenCanvas_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
10 #include "bindings/core/v8/ScriptWrappable.h" | 10 #include "bindings/core/v8/ScriptWrappable.h" |
| 11 #include "core/events/EventTarget.h" |
11 #include "core/html/HTMLCanvasElement.h" | 12 #include "core/html/HTMLCanvasElement.h" |
12 #include "core/html/canvas/CanvasImageSource.h" | 13 #include "core/html/canvas/CanvasImageSource.h" |
13 #include "core/offscreencanvas/ImageEncodeOptions.h" | 14 #include "core/offscreencanvas/ImageEncodeOptions.h" |
14 #include "platform/geometry/IntSize.h" | 15 #include "platform/geometry/IntSize.h" |
15 #include "platform/graphics/OffscreenCanvasFrameDispatcher.h" | 16 #include "platform/graphics/OffscreenCanvasFrameDispatcher.h" |
16 #include "platform/heap/Handle.h" | 17 #include "platform/heap/Handle.h" |
17 #include <memory> | 18 #include <memory> |
18 | 19 |
19 namespace blink { | 20 namespace blink { |
20 | 21 |
21 class CanvasContextCreationAttributes; | 22 class CanvasContextCreationAttributes; |
22 class ImageBitmap; | 23 class ImageBitmap; |
23 class | 24 class |
24 OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingCon
text; | 25 OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingCon
text; |
25 typedef OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2Renderin
gContext | 26 typedef OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2Renderin
gContext |
26 OffscreenRenderingContext; | 27 OffscreenRenderingContext; |
27 | 28 |
28 class CORE_EXPORT OffscreenCanvas final | 29 class CORE_EXPORT OffscreenCanvas final : public EventTargetWithInlineData, |
29 : public GarbageCollectedFinalized<OffscreenCanvas>, | 30 public CanvasImageSource { |
30 public ScriptWrappable, | |
31 public CanvasImageSource { | |
32 DEFINE_WRAPPERTYPEINFO(); | 31 DEFINE_WRAPPERTYPEINFO(); |
33 | 32 |
34 public: | 33 public: |
35 static OffscreenCanvas* create(unsigned width, unsigned height); | 34 static OffscreenCanvas* create(unsigned width, unsigned height); |
| 35 ~OffscreenCanvas() override {} |
36 | 36 |
37 // IDL attributes | 37 // IDL attributes |
38 unsigned width() const { return m_size.width(); } | 38 unsigned width() const { return m_size.width(); } |
39 unsigned height() const { return m_size.height(); } | 39 unsigned height() const { return m_size.height(); } |
40 void setWidth(unsigned, ExceptionState&); | 40 void setWidth(unsigned, ExceptionState&); |
41 void setHeight(unsigned, ExceptionState&); | 41 void setHeight(unsigned, ExceptionState&); |
42 | 42 |
43 // API Methods | 43 // API Methods |
44 ImageBitmap* transferToImageBitmap(ScriptState*, ExceptionState&); | 44 ImageBitmap* transferToImageBitmap(ScriptState*, ExceptionState&); |
45 ScriptPromise convertToBlob(ScriptState*, | 45 ScriptPromise convertToBlob(ScriptState*, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 m_localId = localId; | 82 m_localId = localId; |
83 m_nonceHigh = nonceHigh; | 83 m_nonceHigh = nonceHigh; |
84 m_nonceLow = nonceLow; | 84 m_nonceLow = nonceLow; |
85 } | 85 } |
86 uint32_t clientId() const { return m_clientId; } | 86 uint32_t clientId() const { return m_clientId; } |
87 uint32_t sinkId() const { return m_sinkId; } | 87 uint32_t sinkId() const { return m_sinkId; } |
88 uint32_t localId() const { return m_localId; } | 88 uint32_t localId() const { return m_localId; } |
89 uint64_t nonceHigh() const { return m_nonceHigh; } | 89 uint64_t nonceHigh() const { return m_nonceHigh; } |
90 uint64_t nonceLow() const { return m_nonceLow; } | 90 uint64_t nonceLow() const { return m_nonceLow; } |
91 | 91 |
| 92 void setExecutionContext(ExecutionContext* context) { |
| 93 m_executionContext = context; |
| 94 } |
| 95 |
| 96 // EventTarget implementation |
| 97 const AtomicString& interfaceName() const final { |
| 98 return EventTargetNames::OffscreenCanvas; |
| 99 } |
| 100 ExecutionContext* getExecutionContext() const { |
| 101 return m_executionContext.get(); |
| 102 } |
| 103 |
92 // CanvasImageSource implementation | 104 // CanvasImageSource implementation |
93 PassRefPtr<Image> getSourceImageForCanvas(SourceImageStatus*, | 105 PassRefPtr<Image> getSourceImageForCanvas(SourceImageStatus*, |
94 AccelerationHint, | 106 AccelerationHint, |
95 SnapshotReason, | 107 SnapshotReason, |
96 const FloatSize&) const final; | 108 const FloatSize&) const final; |
97 bool wouldTaintOrigin(SecurityOrigin*) const final { return !m_originClean; } | 109 bool wouldTaintOrigin(SecurityOrigin*) const final { return !m_originClean; } |
98 bool isOffscreenCanvas() const final { return true; } | 110 bool isOffscreenCanvas() const final { return true; } |
99 FloatSize elementSize(const FloatSize& defaultObjectSize) const final { | 111 FloatSize elementSize(const FloatSize& defaultObjectSize) const final { |
100 return FloatSize(width(), height()); | 112 return FloatSize(width(), height()); |
101 } | 113 } |
102 bool isOpaque() const final; | 114 bool isOpaque() const final; |
103 bool isAccelerated() const final; | 115 bool isAccelerated() const final; |
104 int sourceWidth() final { return width(); } | 116 int sourceWidth() final { return width(); } |
105 int sourceHeight() final { return height(); } | 117 int sourceHeight() final { return height(); } |
106 | 118 |
107 DECLARE_VIRTUAL_TRACE(); | 119 DECLARE_VIRTUAL_TRACE(); |
108 | 120 |
109 private: | 121 private: |
110 explicit OffscreenCanvas(const IntSize&); | 122 explicit OffscreenCanvas(const IntSize&); |
111 | 123 |
112 using ContextFactoryVector = | 124 using ContextFactoryVector = |
113 Vector<std::unique_ptr<CanvasRenderingContextFactory>>; | 125 Vector<std::unique_ptr<CanvasRenderingContextFactory>>; |
114 static ContextFactoryVector& renderingContextFactories(); | 126 static ContextFactoryVector& renderingContextFactories(); |
115 static CanvasRenderingContextFactory* getRenderingContextFactory(int); | 127 static CanvasRenderingContextFactory* getRenderingContextFactory(int); |
116 | 128 |
117 Member<CanvasRenderingContext> m_context; | 129 Member<CanvasRenderingContext> m_context; |
| 130 WeakMember<ExecutionContext> m_executionContext; |
118 | 131 |
119 enum { | 132 enum { |
120 kNoPlaceholderCanvas = -1, // DOMNodeIds starts from 0, using -1 to | 133 kNoPlaceholderCanvas = -1, // DOMNodeIds starts from 0, using -1 to |
121 // indicate no associated canvas element. | 134 // indicate no associated canvas element. |
122 }; | 135 }; |
123 int m_placeholderCanvasId = kNoPlaceholderCanvas; | 136 int m_placeholderCanvasId = kNoPlaceholderCanvas; |
124 | 137 |
125 IntSize m_size; | 138 IntSize m_size; |
126 bool m_isNeutered = false; | 139 bool m_isNeutered = false; |
127 | 140 |
(...skipping 11 matching lines...) Expand all Loading... |
139 uint32_t m_clientId = 0; | 152 uint32_t m_clientId = 0; |
140 uint32_t m_sinkId = 0; | 153 uint32_t m_sinkId = 0; |
141 uint32_t m_localId = 0; | 154 uint32_t m_localId = 0; |
142 uint64_t m_nonceHigh = 0; | 155 uint64_t m_nonceHigh = 0; |
143 uint64_t m_nonceLow = 0; | 156 uint64_t m_nonceLow = 0; |
144 }; | 157 }; |
145 | 158 |
146 } // namespace blink | 159 } // namespace blink |
147 | 160 |
148 #endif // OffscreenCanvas_h | 161 #endif // OffscreenCanvas_h |
OLD | NEW |