| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef Canvas2DLayerBridge_h | 26 #ifndef Canvas2DLayerBridge_h |
| 27 #define Canvas2DLayerBridge_h | 27 #define Canvas2DLayerBridge_h |
| 28 | 28 |
| 29 #include "SkDeferredCanvas.h" | 29 #include "SkDeferredCanvas.h" |
| 30 #include "SkImage.h" | 30 #include "SkImage.h" |
| 31 #include "platform/PlatformExport.h" | 31 #include "platform/PlatformExport.h" |
| 32 #include "platform/geometry/IntSize.h" | 32 #include "platform/geometry/IntSize.h" |
| 33 #include "platform/graphics/GraphicsContext3D.h" | 33 #include "platform/graphics/GraphicsContext3D.h" |
| 34 #include "platform/graphics/ImageBufferSurface.h" |
| 34 #include "public/platform/WebExternalTextureLayer.h" | 35 #include "public/platform/WebExternalTextureLayer.h" |
| 35 #include "public/platform/WebExternalTextureLayerClient.h" | 36 #include "public/platform/WebExternalTextureLayerClient.h" |
| 36 #include "public/platform/WebExternalTextureMailbox.h" | 37 #include "public/platform/WebExternalTextureMailbox.h" |
| 37 #include "wtf/DoublyLinkedList.h" | 38 #include "wtf/DoublyLinkedList.h" |
| 38 #include "wtf/PassOwnPtr.h" | 39 #include "wtf/PassOwnPtr.h" |
| 40 #include "wtf/RefCounted.h" |
| 39 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
| 40 | 42 |
| 41 namespace blink { | 43 namespace blink { |
| 42 class WebGraphicsContext3D; | 44 class WebGraphicsContext3D; |
| 43 } | 45 } |
| 44 | 46 |
| 47 class Canvas2DLayerBridgeTest; |
| 48 |
| 45 namespace WebCore { | 49 namespace WebCore { |
| 46 | 50 |
| 47 class Canvas2DLayerBridge; | |
| 48 class PassCanvas2DLayerBridgePtr; | |
| 49 | |
| 50 class PLATFORM_EXPORT Canvas2DLayerBridgePtr { | |
| 51 public: | |
| 52 Canvas2DLayerBridgePtr() { } | |
| 53 Canvas2DLayerBridgePtr(const PassRefPtr<Canvas2DLayerBridge>& ptr) { m_ptr =
ptr; } | |
| 54 ~Canvas2DLayerBridgePtr() { clear(); } | |
| 55 Canvas2DLayerBridge* operator->() const { return m_ptr.get(); } | |
| 56 Canvas2DLayerBridgePtr& operator=(const PassRefPtr<Canvas2DLayerBridge>&); | |
| 57 Canvas2DLayerBridge* get() const { return m_ptr.get(); } | |
| 58 operator bool () const { return m_ptr; } | |
| 59 void clear(); | |
| 60 PassRefPtr<Canvas2DLayerBridge> release() WARN_UNUSED_RETURN { return m_ptr.
release(); } | |
| 61 private: | |
| 62 RefPtr<Canvas2DLayerBridge> m_ptr; | |
| 63 }; | |
| 64 | |
| 65 class PLATFORM_EXPORT Canvas2DLayerBridge : public blink::WebExternalTextureLaye
rClient, public SkDeferredCanvas::NotificationClient, public DoublyLinkedListNod
e<Canvas2DLayerBridge>, public RefCounted<Canvas2DLayerBridge> { | 51 class PLATFORM_EXPORT Canvas2DLayerBridge : public blink::WebExternalTextureLaye
rClient, public SkDeferredCanvas::NotificationClient, public DoublyLinkedListNod
e<Canvas2DLayerBridge>, public RefCounted<Canvas2DLayerBridge> { |
| 66 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); | 52 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); |
| 67 public: | 53 public: |
| 68 enum OpacityMode { | 54 static PassRefPtr<Canvas2DLayerBridge> create(const IntSize&, OpacityMode, i
nt msaaSampleCount); |
| 69 Opaque, | |
| 70 NonOpaque | |
| 71 }; | |
| 72 | |
| 73 static PassRefPtr<Canvas2DLayerBridge> create(PassRefPtr<GraphicsContext3D>,
const IntSize&, OpacityMode, int msaaSampleCount); | |
| 74 | |
| 75 virtual ~Canvas2DLayerBridge(); | 55 virtual ~Canvas2DLayerBridge(); |
| 76 | 56 |
| 77 // blink::WebExternalTextureLayerClient implementation. | 57 // blink::WebExternalTextureLayerClient implementation. |
| 78 virtual blink::WebGraphicsContext3D* context() OVERRIDE; | 58 virtual blink::WebGraphicsContext3D* context() OVERRIDE; |
| 79 virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExt
ernalBitmap*) OVERRIDE; | 59 virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExt
ernalBitmap*) OVERRIDE; |
| 80 virtual void mailboxReleased(const blink::WebExternalTextureMailbox&) OVERRI
DE; | 60 virtual void mailboxReleased(const blink::WebExternalTextureMailbox&) OVERRI
DE; |
| 81 | 61 |
| 82 // SkDeferredCanvas::NotificationClient implementation | 62 // SkDeferredCanvas::NotificationClient implementation |
| 83 virtual void prepareForDraw() OVERRIDE; | 63 virtual void prepareForDraw() OVERRIDE; |
| 84 virtual void storageAllocatedForRecordingChanged(size_t) OVERRIDE; | 64 virtual void storageAllocatedForRecordingChanged(size_t) OVERRIDE; |
| 85 virtual void flushedDrawCommands() OVERRIDE; | 65 virtual void flushedDrawCommands() OVERRIDE; |
| 86 virtual void skippedPendingDrawCommands() OVERRIDE; | 66 virtual void skippedPendingDrawCommands() OVERRIDE; |
| 87 | 67 |
| 68 // ImageBufferSurface implementation |
| 69 void willUse(); |
| 70 SkCanvas* canvas() const { return m_canvas.get(); } |
| 71 bool isValid(); |
| 72 blink::WebLayer* layer() const; |
| 73 Platform3DObject getBackingTexture(); |
| 74 bool isAccelerated() const { return true; } |
| 75 |
| 88 // Methods used by Canvas2DLayerManager | 76 // Methods used by Canvas2DLayerManager |
| 89 virtual size_t freeMemoryIfPossible(size_t); // virtual for mocking | 77 virtual size_t freeMemoryIfPossible(size_t); // virtual for mocking |
| 90 virtual void flush(); // virtual for mocking | 78 virtual void flush(); // virtual for mocking |
| 91 virtual size_t storageAllocatedForRecording(); // virtual for faking | 79 virtual size_t storageAllocatedForRecording(); // virtual for faking |
| 92 size_t bytesAllocated() const {return m_bytesAllocated;} | 80 size_t bytesAllocated() const {return m_bytesAllocated;} |
| 93 void limitPendingFrames(); | 81 void limitPendingFrames(); |
| 94 | 82 |
| 95 blink::WebLayer* layer(); | 83 void beginDestruction(); |
| 96 void contextAcquired(); | |
| 97 PassRefPtr<SkCanvas> getCanvas() { return PassRefPtr<SkCanvas>(m_canvas); } | |
| 98 | |
| 99 unsigned backBufferTexture(); | |
| 100 | |
| 101 bool isValid(); | |
| 102 | 84 |
| 103 protected: | 85 protected: |
| 104 void destroy(); | 86 Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D>, PassOwnPtr<SkDeferredCanv
as>, int, OpacityMode); |
| 105 friend class Canvas2DLayerBridgePtr; | |
| 106 Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D>, PassRefPtr<SkDeferredCanv
as>, int, OpacityMode); | |
| 107 void setRateLimitingEnabled(bool); | 87 void setRateLimitingEnabled(bool); |
| 108 | 88 |
| 109 RefPtr<SkDeferredCanvas> m_canvas; | 89 OwnPtr<SkDeferredCanvas> m_canvas; |
| 110 OwnPtr<blink::WebExternalTextureLayer> m_layer; | 90 OwnPtr<blink::WebExternalTextureLayer> m_layer; |
| 111 RefPtr<GraphicsContext3D> m_context; | 91 RefPtr<GraphicsContext3D> m_context; |
| 112 int m_msaaSampleCount; | 92 int m_msaaSampleCount; |
| 113 size_t m_bytesAllocated; | 93 size_t m_bytesAllocated; |
| 114 bool m_didRecordDrawCommand; | 94 bool m_didRecordDrawCommand; |
| 115 bool m_surfaceIsValid; | 95 bool m_surfaceIsValid; |
| 116 int m_framesPending; | 96 int m_framesPending; |
| 117 bool m_destructionInProgress; | 97 bool m_destructionInProgress; |
| 118 bool m_rateLimitingEnabled; | 98 bool m_rateLimitingEnabled; |
| 119 | 99 |
| 120 friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>; | 100 friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>; |
| 101 friend class ::Canvas2DLayerBridgeTest; |
| 121 Canvas2DLayerBridge* m_next; | 102 Canvas2DLayerBridge* m_next; |
| 122 Canvas2DLayerBridge* m_prev; | 103 Canvas2DLayerBridge* m_prev; |
| 123 | 104 |
| 124 enum MailboxStatus { | 105 enum MailboxStatus { |
| 125 MailboxInUse, | 106 MailboxInUse, |
| 126 MailboxReleased, | 107 MailboxReleased, |
| 127 MailboxAvailable, | 108 MailboxAvailable, |
| 128 }; | 109 }; |
| 129 | 110 |
| 130 struct MailboxInfo { | 111 struct MailboxInfo { |
| 131 blink::WebExternalTextureMailbox m_mailbox; | 112 blink::WebExternalTextureMailbox m_mailbox; |
| 132 SkAutoTUnref<SkImage> m_image; | 113 SkAutoTUnref<SkImage> m_image; |
| 133 MailboxStatus m_status; | 114 MailboxStatus m_status; |
| 134 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; | 115 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; |
| 135 | 116 |
| 136 MailboxInfo(const MailboxInfo&); | 117 MailboxInfo(const MailboxInfo&); |
| 137 MailboxInfo() {} | 118 MailboxInfo() {} |
| 138 }; | 119 }; |
| 139 MailboxInfo* createMailboxInfo(); | 120 MailboxInfo* createMailboxInfo(); |
| 140 | 121 |
| 141 uint32_t m_lastImageId; | 122 uint32_t m_lastImageId; |
| 142 Vector<MailboxInfo> m_mailboxes; | 123 Vector<MailboxInfo> m_mailboxes; |
| 143 }; | 124 }; |
| 144 } | 125 } |
| 145 #endif | 126 #endif |
| OLD | NEW |