 Chromium Code Reviews
 Chromium Code Reviews Issue 2594843002:
  Implementing promise-based commit for driving OffscreenCanvas animations  (Closed)
    
  
    Issue 2594843002:
  Implementing promise-based commit for driving OffscreenCanvas animations  (Closed) 
  | 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/events/EventTarget.h" | 
| 12 #include "core/html/HTMLCanvasElement.h" | 12 #include "core/html/HTMLCanvasElement.h" | 
| 13 #include "core/html/canvas/CanvasImageSource.h" | 13 #include "core/html/canvas/CanvasImageSource.h" | 
| 14 #include "core/offscreencanvas/ImageEncodeOptions.h" | 14 #include "core/offscreencanvas/ImageEncodeOptions.h" | 
| 15 #include "platform/geometry/IntSize.h" | 15 #include "platform/geometry/IntSize.h" | 
| 16 #include "platform/graphics/OffscreenCanvasFrameDispatcher.h" | 16 #include "platform/graphics/OffscreenCanvasFrameDispatcher.h" | 
| 17 #include "platform/heap/Handle.h" | 17 #include "platform/heap/Handle.h" | 
| 18 #include <memory> | 18 #include <memory> | 
| 19 | 19 | 
| 20 namespace blink { | 20 namespace blink { | 
| 21 | 21 | 
| 22 class CanvasContextCreationAttributes; | 22 class CanvasContextCreationAttributes; | 
| 23 class ImageBitmap; | 23 class ImageBitmap; | 
| 24 class | 24 class | 
| 25 OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingCon text; | 25 OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2RenderingCon text; | 
| 26 typedef OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2Renderin gContext | 26 typedef OffscreenCanvasRenderingContext2DOrWebGLRenderingContextOrWebGL2Renderin gContext | 
| 27 OffscreenRenderingContext; | 27 OffscreenRenderingContext; | 
| 28 | 28 | 
| 29 class CORE_EXPORT OffscreenCanvas final : public EventTargetWithInlineData, | 29 class CORE_EXPORT OffscreenCanvas final | 
| 30 public CanvasImageSource, | 30 : public EventTargetWithInlineData, | 
| 31 public ImageBitmapSource { | 31 public CanvasImageSource, | 
| 32 public ImageBitmapSource, | |
| 33 public OffscreenCanvasFrameDispatcherClient { | |
| 32 DEFINE_WRAPPERTYPEINFO(); | 34 DEFINE_WRAPPERTYPEINFO(); | 
| 35 USING_PRE_FINALIZER(OffscreenCanvas, dispose); | |
| 33 | 36 | 
| 34 public: | 37 public: | 
| 35 static OffscreenCanvas* create(unsigned width, unsigned height); | 38 static OffscreenCanvas* create(unsigned width, unsigned height); | 
| 36 ~OffscreenCanvas() override {} | 39 ~OffscreenCanvas() override; | 
| 40 void dispose(); | |
| 37 | 41 | 
| 38 // IDL attributes | 42 // IDL attributes | 
| 39 unsigned width() const { return m_size.width(); } | 43 unsigned width() const { return m_size.width(); } | 
| 40 unsigned height() const { return m_size.height(); } | 44 unsigned height() const { return m_size.height(); } | 
| 41 void setWidth(unsigned); | 45 void setWidth(unsigned); | 
| 42 void setHeight(unsigned); | 46 void setHeight(unsigned); | 
| 43 | 47 | 
| 44 // API Methods | 48 // API Methods | 
| 45 ImageBitmap* transferToImageBitmap(ScriptState*, ExceptionState&); | 49 ImageBitmap* transferToImageBitmap(ScriptState*, ExceptionState&); | 
| 46 ScriptPromise convertToBlob(ScriptState*, | 50 ScriptPromise convertToBlob(ScriptState*, | 
| (...skipping 19 matching lines...) Expand all Loading... | |
| 66 CanvasRenderingContext* renderingContext() { return m_context; } | 70 CanvasRenderingContext* renderingContext() { return m_context; } | 
| 67 | 71 | 
| 68 static void registerRenderingContextFactory( | 72 static void registerRenderingContextFactory( | 
| 69 std::unique_ptr<CanvasRenderingContextFactory>); | 73 std::unique_ptr<CanvasRenderingContextFactory>); | 
| 70 | 74 | 
| 71 bool originClean() const; | 75 bool originClean() const; | 
| 72 void setOriginTainted() { m_originClean = false; } | 76 void setOriginTainted() { m_originClean = false; } | 
| 73 // TODO(crbug.com/630356): apply the flag to WebGL context as well | 77 // TODO(crbug.com/630356): apply the flag to WebGL context as well | 
| 74 void setDisableReadingFromCanvasTrue() { m_disableReadingFromCanvas = true; } | 78 void setDisableReadingFromCanvasTrue() { m_disableReadingFromCanvas = true; } | 
| 75 | 79 | 
| 76 OffscreenCanvasFrameDispatcher* getOrCreateFrameDispatcher(); | |
| 77 | |
| 78 void setFrameSinkId(uint32_t clientId, uint32_t sinkId) { | 80 void setFrameSinkId(uint32_t clientId, uint32_t sinkId) { | 
| 79 m_clientId = clientId; | 81 m_clientId = clientId; | 
| 80 m_sinkId = sinkId; | 82 m_sinkId = sinkId; | 
| 81 } | 83 } | 
| 82 uint32_t clientId() const { return m_clientId; } | 84 uint32_t clientId() const { return m_clientId; } | 
| 83 uint32_t sinkId() const { return m_sinkId; } | 85 uint32_t sinkId() const { return m_sinkId; } | 
| 84 | 86 | 
| 85 void setExecutionContext(ExecutionContext* context) { | 87 void setExecutionContext(ExecutionContext* context) { | 
| 86 m_executionContext = context; | 88 m_executionContext = context; | 
| 87 } | 89 } | 
| 88 | 90 | 
| 91 ScriptPromise commit(RefPtr<StaticBitmapImage>, | |
| 92 bool isWebGLSoftwareRendering, | |
| 93 ScriptState*); | |
| 94 | |
| 95 void detachContext() { m_context = nullptr; } | |
| 96 | |
| 97 // OffscreenCanvasFrameDispatcherClient implementation | |
| 98 void beginFrame() final; | |
| 99 | |
| 89 // EventTarget implementation | 100 // EventTarget implementation | 
| 90 const AtomicString& interfaceName() const final { | 101 const AtomicString& interfaceName() const final { | 
| 91 return EventTargetNames::OffscreenCanvas; | 102 return EventTargetNames::OffscreenCanvas; | 
| 92 } | 103 } | 
| 93 ExecutionContext* getExecutionContext() const { | 104 ExecutionContext* getExecutionContext() const { | 
| 94 return m_executionContext.get(); | 105 return m_executionContext.get(); | 
| 95 } | 106 } | 
| 96 | 107 | 
| 97 // ImageBitmapSource implementation | 108 // ImageBitmapSource implementation | 
| 98 IntSize bitmapSourceSize() const final; | 109 IntSize bitmapSourceSize() const final; | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 114 } | 125 } | 
| 115 bool isOpaque() const final; | 126 bool isOpaque() const final; | 
| 116 bool isAccelerated() const final; | 127 bool isAccelerated() const final; | 
| 117 int sourceWidth() final { return width(); } | 128 int sourceWidth() final { return width(); } | 
| 118 int sourceHeight() final { return height(); } | 129 int sourceHeight() final { return height(); } | 
| 119 | 130 | 
| 120 DECLARE_VIRTUAL_TRACE(); | 131 DECLARE_VIRTUAL_TRACE(); | 
| 121 | 132 | 
| 122 private: | 133 private: | 
| 123 explicit OffscreenCanvas(const IntSize&); | 134 explicit OffscreenCanvas(const IntSize&); | 
| 124 | 135 OffscreenCanvasFrameDispatcher* getOrCreateFrameDispatcher(); | 
| 136 void doCommit(RefPtr<StaticBitmapImage>, bool isWebGLSoftwareRendering); | |
| 125 using ContextFactoryVector = | 137 using ContextFactoryVector = | 
| 126 Vector<std::unique_ptr<CanvasRenderingContextFactory>>; | 138 Vector<std::unique_ptr<CanvasRenderingContextFactory>>; | 
| 127 static ContextFactoryVector& renderingContextFactories(); | 139 static ContextFactoryVector& renderingContextFactories(); | 
| 128 static CanvasRenderingContextFactory* getRenderingContextFactory(int); | 140 static CanvasRenderingContextFactory* getRenderingContextFactory(int); | 
| 129 | 141 | 
| 130 Member<CanvasRenderingContext> m_context; | 142 Member<CanvasRenderingContext> m_context; | 
| 131 WeakMember<ExecutionContext> m_executionContext; | 143 WeakMember<ExecutionContext> m_executionContext; | 
| 132 | 144 | 
| 133 enum { | 145 enum { | 
| 134 kNoPlaceholderCanvas = -1, // DOMNodeIds starts from 0, using -1 to | 146 kNoPlaceholderCanvas = -1, // DOMNodeIds starts from 0, using -1 to | 
| 135 // indicate no associated canvas element. | 147 // indicate no associated canvas element. | 
| 136 }; | 148 }; | 
| 137 int m_placeholderCanvasId = kNoPlaceholderCanvas; | 149 int m_placeholderCanvasId = kNoPlaceholderCanvas; | 
| 138 | 150 | 
| 139 IntSize m_size; | 151 IntSize m_size; | 
| 140 bool m_isNeutered = false; | 152 bool m_isNeutered = false; | 
| 141 | 153 | 
| 142 bool m_originClean; | 154 bool m_originClean = true; | 
| 143 bool m_disableReadingFromCanvas = false; | 155 bool m_disableReadingFromCanvas = false; | 
| 144 | 156 | 
| 145 bool isPaintable() const; | 157 bool isPaintable() const; | 
| 146 | 158 | 
| 147 std::unique_ptr<OffscreenCanvasFrameDispatcher> m_frameDispatcher; | 159 std::unique_ptr<OffscreenCanvasFrameDispatcher> m_frameDispatcher; | 
| 148 // cc::FrameSinkId is broken into two integer components as this can be used | 160 // cc::FrameSinkId is broken into two integer components as this can be used | 
| 
xlai (Olivia)
2016/12/21 19:54:25
This comment for uint32_t m_clientId is broken int
 
Justin Novosad
2016/12/21 21:15:40
Oop. Bad rebase.  Done.
 | |
| 161 Member<ScriptPromiseResolver> m_commitPromiseResolver; | |
| 162 RefPtr<StaticBitmapImage> m_overdrawFrame; | |
| 163 bool m_overdrawFrameIsWebGLSoftwareRendering = false; | |
| 149 // in transfer of OffscreenCanvas across threads | 164 // in transfer of OffscreenCanvas across threads | 
| 150 // If this object is not created via | 165 // If this object is not created via | 
| 151 // HTMLCanvasElement.transferControlToOffscreen(), | 166 // HTMLCanvasElement.transferControlToOffscreen(), | 
| 152 // then the following members would remain as initialized zero values. | 167 // then the following members would remain as initialized zero values. | 
| 153 uint32_t m_clientId = 0; | 168 uint32_t m_clientId = 0; | 
| 154 uint32_t m_sinkId = 0; | 169 uint32_t m_sinkId = 0; | 
| 155 }; | 170 }; | 
| 156 | 171 | 
| 157 } // namespace blink | 172 } // namespace blink | 
| 158 | 173 | 
| 159 #endif // OffscreenCanvas_h | 174 #endif // OffscreenCanvas_h | 
| OLD | NEW |