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

Side by Side Diff: third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.h

Issue 2490443002: Make OffscreenCanvas an EventTarget (Closed)
Patch Set: keep a Member<ExecutionContext> in OffscreenCanvas 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 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 m_localId = localId; 77 m_localId = localId;
78 m_nonceHigh = nonceHigh; 78 m_nonceHigh = nonceHigh;
79 m_nonceLow = nonceLow; 79 m_nonceLow = nonceLow;
80 } 80 }
81 uint32_t clientId() const { return m_clientId; } 81 uint32_t clientId() const { return m_clientId; }
82 uint32_t sinkId() const { return m_sinkId; } 82 uint32_t sinkId() const { return m_sinkId; }
83 uint32_t localId() const { return m_localId; } 83 uint32_t localId() const { return m_localId; }
84 uint64_t nonceHigh() const { return m_nonceHigh; } 84 uint64_t nonceHigh() const { return m_nonceHigh; }
85 uint64_t nonceLow() const { return m_nonceLow; } 85 uint64_t nonceLow() const { return m_nonceLow; }
86 86
87 void setExecutionContext(ExecutionContext* context) {
88 m_executionContext = context;
89 }
90
91 // EventTarget implementation
92 const AtomicString& interfaceName() const final {
93 return EventTargetNames::OffscreenCanvas;
94 }
95 ExecutionContext* getExecutionContext() const {
96 return m_executionContext.get();
97 }
98
87 // CanvasImageSource implementation 99 // CanvasImageSource implementation
88 PassRefPtr<Image> getSourceImageForCanvas(SourceImageStatus*, 100 PassRefPtr<Image> getSourceImageForCanvas(SourceImageStatus*,
89 AccelerationHint, 101 AccelerationHint,
90 SnapshotReason, 102 SnapshotReason,
91 const FloatSize&) const final; 103 const FloatSize&) const final;
92 bool wouldTaintOrigin(SecurityOrigin*) const final { return !m_originClean; } 104 bool wouldTaintOrigin(SecurityOrigin*) const final { return !m_originClean; }
93 bool isOffscreenCanvas() const final { return true; } 105 bool isOffscreenCanvas() const final { return true; }
94 FloatSize elementSize(const FloatSize& defaultObjectSize) const final { 106 FloatSize elementSize(const FloatSize& defaultObjectSize) const final {
95 return FloatSize(width(), height()); 107 return FloatSize(width(), height());
96 } 108 }
97 bool isOpaque() const final; 109 bool isOpaque() const final;
98 bool isAccelerated() const final; 110 bool isAccelerated() const final;
99 int sourceWidth() final { return width(); } 111 int sourceWidth() final { return width(); }
100 int sourceHeight() final { return height(); } 112 int sourceHeight() final { return height(); }
101 113
102 DECLARE_VIRTUAL_TRACE(); 114 DECLARE_VIRTUAL_TRACE();
103 115
104 private: 116 private:
105 explicit OffscreenCanvas(const IntSize&); 117 explicit OffscreenCanvas(const IntSize&);
106 118
107 using ContextFactoryVector = 119 using ContextFactoryVector =
108 Vector<std::unique_ptr<CanvasRenderingContextFactory>>; 120 Vector<std::unique_ptr<CanvasRenderingContextFactory>>;
109 static ContextFactoryVector& renderingContextFactories(); 121 static ContextFactoryVector& renderingContextFactories();
110 static CanvasRenderingContextFactory* getRenderingContextFactory(int); 122 static CanvasRenderingContextFactory* getRenderingContextFactory(int);
111 123
112 Member<CanvasRenderingContext> m_context; 124 Member<CanvasRenderingContext> m_context;
125 Member<ExecutionContext> m_executionContext;
Justin Novosad 2016/11/14 19:45:08 Nit: This reference is not need for lifetime manag
xidachen 2016/11/14 19:56:38 Changed to WeakMember. But still need to trace it,
113 int m_canvasId = -1; // DOMNodeIds starts from 0, using -1 to indicate no 126 int m_canvasId = -1; // DOMNodeIds starts from 0, using -1 to indicate no
114 // associated canvas element. 127 // associated canvas element.
115 128
116 IntSize m_size; 129 IntSize m_size;
117 bool m_isNeutered = false; 130 bool m_isNeutered = false;
118 131
119 bool m_originClean; 132 bool m_originClean;
120 bool m_disableReadingFromCanvas = false; 133 bool m_disableReadingFromCanvas = false;
121 134
122 bool isPaintable() const; 135 bool isPaintable() const;
123 136
124 std::unique_ptr<OffscreenCanvasFrameDispatcher> m_frameDispatcher; 137 std::unique_ptr<OffscreenCanvasFrameDispatcher> m_frameDispatcher;
125 // cc::SurfaceId is broken into three integer components as this can be used 138 // cc::SurfaceId is broken into three integer components as this can be used
126 // in transfer of OffscreenCanvas across threads 139 // in transfer of OffscreenCanvas across threads
127 // If this object is not created via 140 // If this object is not created via
128 // HTMLCanvasElement.transferControlToOffscreen(), 141 // HTMLCanvasElement.transferControlToOffscreen(),
129 // then the following members would remain as initialized zero values. 142 // then the following members would remain as initialized zero values.
130 uint32_t m_clientId = 0; 143 uint32_t m_clientId = 0;
131 uint32_t m_sinkId = 0; 144 uint32_t m_sinkId = 0;
132 uint32_t m_localId = 0; 145 uint32_t m_localId = 0;
133 uint64_t m_nonceHigh = 0; 146 uint64_t m_nonceHigh = 0;
134 uint64_t m_nonceLow = 0; 147 uint64_t m_nonceLow = 0;
135 }; 148 };
136 149
137 } // namespace blink 150 } // namespace blink
138 151
139 #endif // OffscreenCanvas_h 152 #endif // OffscreenCanvas_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698