| OLD | NEW |
| 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 #ifndef ImageBitmapRenderingContext_h | 5 #ifndef ImageBitmapRenderingContext_h |
| 6 #define ImageBitmapRenderingContext_h | 6 #define ImageBitmapRenderingContext_h |
| 7 | 7 |
| 8 #include "core/html/canvas/CanvasRenderingContext.h" | 8 #include "core/html/canvas/CanvasRenderingContext.h" |
| 9 #include "core/html/canvas/CanvasRenderingContextFactory.h" | 9 #include "core/html/canvas/CanvasRenderingContextFactory.h" |
| 10 #include "modules/ModulesExport.h" | 10 #include "modules/ModulesExport.h" |
| 11 #include "wtf/RefPtr.h" | 11 #include "wtf/RefPtr.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 class ImageBitmap; | 15 class ImageBitmap; |
| 16 class ImageLayerBridge; |
| 16 | 17 |
| 17 class MODULES_EXPORT ImageBitmapRenderingContext final | 18 class MODULES_EXPORT ImageBitmapRenderingContext final |
| 18 : public CanvasRenderingContext { | 19 : public CanvasRenderingContext { |
| 19 DEFINE_WRAPPERTYPEINFO(); | 20 DEFINE_WRAPPERTYPEINFO(); |
| 20 | 21 |
| 21 public: | 22 public: |
| 22 class Factory : public CanvasRenderingContextFactory { | 23 class Factory : public CanvasRenderingContextFactory { |
| 23 WTF_MAKE_NONCOPYABLE(Factory); | 24 WTF_MAKE_NONCOPYABLE(Factory); |
| 24 | 25 |
| 25 public: | 26 public: |
| 26 Factory() {} | 27 Factory() {} |
| 27 ~Factory() override {} | 28 ~Factory() override {} |
| 28 | 29 |
| 29 CanvasRenderingContext* create(HTMLCanvasElement*, | 30 CanvasRenderingContext* create(HTMLCanvasElement*, |
| 30 const CanvasContextCreationAttributes&, | 31 const CanvasContextCreationAttributes&, |
| 31 Document&) override; | 32 Document&) override; |
| 32 CanvasRenderingContext::ContextType getContextType() const override { | 33 CanvasRenderingContext::ContextType getContextType() const override { |
| 33 return CanvasRenderingContext::ContextImageBitmap; | 34 return CanvasRenderingContext::ContextImageBitmap; |
| 34 } | 35 } |
| 35 }; | 36 }; |
| 36 | 37 |
| 38 DECLARE_TRACE(); |
| 39 |
| 37 // Script API | 40 // Script API |
| 38 void transferFromImageBitmap(ImageBitmap*, ExceptionState&); | 41 void transferFromImageBitmap(ImageBitmap*, ExceptionState&); |
| 39 | 42 |
| 40 // CanvasRenderingContext implementation | 43 // CanvasRenderingContext implementation |
| 41 ContextType getContextType() const override { | 44 ContextType getContextType() const override { |
| 42 return CanvasRenderingContext::ContextImageBitmap; | 45 return CanvasRenderingContext::ContextImageBitmap; |
| 43 } | 46 } |
| 44 void setIsHidden(bool) override {} | 47 void setIsHidden(bool) override {} |
| 45 bool isContextLost() const override { return false; } | 48 bool isContextLost() const override { return false; } |
| 46 bool paint(GraphicsContext&, const IntRect&) override; | |
| 47 void setCanvasGetContextResult(RenderingContext&) final; | 49 void setCanvasGetContextResult(RenderingContext&) final; |
| 48 PassRefPtr<Image> getImage(AccelerationHint, SnapshotReason) const final { | 50 PassRefPtr<Image> getImage(AccelerationHint, SnapshotReason) const final; |
| 49 return m_image.get(); | 51 bool isComposited() const final { return true; } |
| 50 } | 52 bool isAccelerated() const final; |
| 51 | 53 |
| 52 // TODO(junov): Implement GPU accelerated rendering using a layer bridge | 54 WebLayer* platformLayer() const final; |
| 53 WebLayer* platformLayer() const override { return nullptr; } | |
| 54 // TODO(junov): handle lost contexts when content is GPU-backed | 55 // TODO(junov): handle lost contexts when content is GPU-backed |
| 55 void loseContext(LostContextMode) override {} | 56 void loseContext(LostContextMode) override {} |
| 56 | 57 |
| 57 void stop() override; | 58 void stop() override; |
| 58 | 59 |
| 59 bool isPaintable() const final { return m_image.get(); } | 60 bool isPaintable() const final; |
| 60 | 61 |
| 61 virtual ~ImageBitmapRenderingContext(); | 62 virtual ~ImageBitmapRenderingContext(); |
| 62 | 63 |
| 63 private: | 64 private: |
| 64 ImageBitmapRenderingContext(HTMLCanvasElement*, | 65 ImageBitmapRenderingContext(HTMLCanvasElement*, |
| 65 const CanvasContextCreationAttributes&, | 66 const CanvasContextCreationAttributes&, |
| 66 Document&); | 67 Document&); |
| 67 | 68 |
| 68 RefPtr<Image> m_image; | 69 Member<ImageLayerBridge> m_imageLayerBridge; |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 DEFINE_TYPE_CASTS(ImageBitmapRenderingContext, | 72 DEFINE_TYPE_CASTS(ImageBitmapRenderingContext, |
| 72 CanvasRenderingContext, | 73 CanvasRenderingContext, |
| 73 context, | 74 context, |
| 74 context->getContextType() == | 75 context->getContextType() == |
| 75 CanvasRenderingContext::ContextImageBitmap, | 76 CanvasRenderingContext::ContextImageBitmap, |
| 76 context.getContextType() == | 77 context.getContextType() == |
| 77 CanvasRenderingContext::ContextImageBitmap); | 78 CanvasRenderingContext::ContextImageBitmap); |
| 78 | 79 |
| 79 } // blink | 80 } // blink |
| 80 | 81 |
| 81 #endif | 82 #endif |
| OLD | NEW |