| 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 19 matching lines...) Expand all Loading... |
| 30 #include "SkImage.h" | 30 #include "SkImage.h" |
| 31 #include "core/platform/graphics/GraphicsContext3D.h" | 31 #include "core/platform/graphics/GraphicsContext3D.h" |
| 32 #include "platform/geometry/IntSize.h" | 32 #include "platform/geometry/IntSize.h" |
| 33 #include "public/platform/WebExternalTextureLayer.h" | 33 #include "public/platform/WebExternalTextureLayer.h" |
| 34 #include "public/platform/WebExternalTextureLayerClient.h" | 34 #include "public/platform/WebExternalTextureLayerClient.h" |
| 35 #include "public/platform/WebExternalTextureMailbox.h" | 35 #include "public/platform/WebExternalTextureMailbox.h" |
| 36 #include "wtf/DoublyLinkedList.h" | 36 #include "wtf/DoublyLinkedList.h" |
| 37 #include "wtf/PassOwnPtr.h" | 37 #include "wtf/PassOwnPtr.h" |
| 38 #include "wtf/RefPtr.h" | 38 #include "wtf/RefPtr.h" |
| 39 | 39 |
| 40 namespace WebKit { | 40 namespace blink { |
| 41 class WebGraphicsContext3D; | 41 class WebGraphicsContext3D; |
| 42 } | 42 } |
| 43 | 43 |
| 44 namespace WebCore { | 44 namespace WebCore { |
| 45 | 45 |
| 46 class Canvas2DLayerBridge; | 46 class Canvas2DLayerBridge; |
| 47 class PassCanvas2DLayerBridgePtr; | 47 class PassCanvas2DLayerBridgePtr; |
| 48 | 48 |
| 49 class Canvas2DLayerBridgePtr { | 49 class Canvas2DLayerBridgePtr { |
| 50 public: | 50 public: |
| 51 Canvas2DLayerBridgePtr() { } | 51 Canvas2DLayerBridgePtr() { } |
| 52 Canvas2DLayerBridgePtr(const PassRefPtr<Canvas2DLayerBridge>& ptr) { m_ptr =
ptr; } | 52 Canvas2DLayerBridgePtr(const PassRefPtr<Canvas2DLayerBridge>& ptr) { m_ptr =
ptr; } |
| 53 ~Canvas2DLayerBridgePtr() { clear(); } | 53 ~Canvas2DLayerBridgePtr() { clear(); } |
| 54 Canvas2DLayerBridge* operator->() const { return m_ptr.get(); } | 54 Canvas2DLayerBridge* operator->() const { return m_ptr.get(); } |
| 55 Canvas2DLayerBridgePtr& operator=(const PassRefPtr<Canvas2DLayerBridge>&); | 55 Canvas2DLayerBridgePtr& operator=(const PassRefPtr<Canvas2DLayerBridge>&); |
| 56 Canvas2DLayerBridge* get() const { return m_ptr.get(); } | 56 Canvas2DLayerBridge* get() const { return m_ptr.get(); } |
| 57 operator bool () const { return m_ptr; } | 57 operator bool () const { return m_ptr; } |
| 58 void clear(); | 58 void clear(); |
| 59 PassRefPtr<Canvas2DLayerBridge> release() WARN_UNUSED_RETURN { return m_ptr.
release(); } | 59 PassRefPtr<Canvas2DLayerBridge> release() WARN_UNUSED_RETURN { return m_ptr.
release(); } |
| 60 private: | 60 private: |
| 61 RefPtr<Canvas2DLayerBridge> m_ptr; | 61 RefPtr<Canvas2DLayerBridge> m_ptr; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class Canvas2DLayerBridge : public WebKit::WebExternalTextureLayerClient, public
SkDeferredCanvas::NotificationClient, public DoublyLinkedListNode<Canvas2DLayer
Bridge>, public RefCounted<Canvas2DLayerBridge> { | 64 class Canvas2DLayerBridge : public blink::WebExternalTextureLayerClient, public
SkDeferredCanvas::NotificationClient, public DoublyLinkedListNode<Canvas2DLayerB
ridge>, public RefCounted<Canvas2DLayerBridge> { |
| 65 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); | 65 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); |
| 66 public: | 66 public: |
| 67 enum OpacityMode { | 67 enum OpacityMode { |
| 68 Opaque, | 68 Opaque, |
| 69 NonOpaque | 69 NonOpaque |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 static PassRefPtr<Canvas2DLayerBridge> create(PassRefPtr<GraphicsContext3D>,
const IntSize&, OpacityMode, int msaaSampleCount); | 72 static PassRefPtr<Canvas2DLayerBridge> create(PassRefPtr<GraphicsContext3D>,
const IntSize&, OpacityMode, int msaaSampleCount); |
| 73 | 73 |
| 74 virtual ~Canvas2DLayerBridge(); | 74 virtual ~Canvas2DLayerBridge(); |
| 75 | 75 |
| 76 // WebKit::WebExternalTextureLayerClient implementation. | 76 // blink::WebExternalTextureLayerClient implementation. |
| 77 virtual WebKit::WebGraphicsContext3D* context() OVERRIDE; | 77 virtual blink::WebGraphicsContext3D* context() OVERRIDE; |
| 78 virtual bool prepareMailbox(WebKit::WebExternalTextureMailbox*, WebKit::WebE
xternalBitmap*) OVERRIDE; | 78 virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExt
ernalBitmap*) OVERRIDE; |
| 79 virtual void mailboxReleased(const WebKit::WebExternalTextureMailbox&) OVERR
IDE; | 79 virtual void mailboxReleased(const blink::WebExternalTextureMailbox&) OVERRI
DE; |
| 80 | 80 |
| 81 // SkDeferredCanvas::NotificationClient implementation | 81 // SkDeferredCanvas::NotificationClient implementation |
| 82 virtual void prepareForDraw() OVERRIDE; | 82 virtual void prepareForDraw() OVERRIDE; |
| 83 virtual void storageAllocatedForRecordingChanged(size_t) OVERRIDE; | 83 virtual void storageAllocatedForRecordingChanged(size_t) OVERRIDE; |
| 84 virtual void flushedDrawCommands() OVERRIDE; | 84 virtual void flushedDrawCommands() OVERRIDE; |
| 85 virtual void skippedPendingDrawCommands() OVERRIDE; | 85 virtual void skippedPendingDrawCommands() OVERRIDE; |
| 86 | 86 |
| 87 // Methods used by Canvas2DLayerManager | 87 // Methods used by Canvas2DLayerManager |
| 88 virtual size_t freeMemoryIfPossible(size_t); // virtual for mocking | 88 virtual size_t freeMemoryIfPossible(size_t); // virtual for mocking |
| 89 virtual void flush(); // virtual for mocking | 89 virtual void flush(); // virtual for mocking |
| 90 virtual size_t storageAllocatedForRecording(); // virtual for faking | 90 virtual size_t storageAllocatedForRecording(); // virtual for faking |
| 91 size_t bytesAllocated() const {return m_bytesAllocated;} | 91 size_t bytesAllocated() const {return m_bytesAllocated;} |
| 92 void limitPendingFrames(); | 92 void limitPendingFrames(); |
| 93 | 93 |
| 94 WebKit::WebLayer* layer(); | 94 blink::WebLayer* layer(); |
| 95 void contextAcquired(); | 95 void contextAcquired(); |
| 96 PassRefPtr<SkCanvas> getCanvas() { return PassRefPtr<SkCanvas>(m_canvas); } | 96 PassRefPtr<SkCanvas> getCanvas() { return PassRefPtr<SkCanvas>(m_canvas); } |
| 97 | 97 |
| 98 unsigned backBufferTexture(); | 98 unsigned backBufferTexture(); |
| 99 | 99 |
| 100 bool isValid(); | 100 bool isValid(); |
| 101 | 101 |
| 102 protected: | 102 protected: |
| 103 void destroy(); | 103 void destroy(); |
| 104 friend class Canvas2DLayerBridgePtr; | 104 friend class Canvas2DLayerBridgePtr; |
| 105 Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D>, PassRefPtr<SkDeferredCanv
as>, int, OpacityMode); | 105 Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D>, PassRefPtr<SkDeferredCanv
as>, int, OpacityMode); |
| 106 void setRateLimitingEnabled(bool); | 106 void setRateLimitingEnabled(bool); |
| 107 | 107 |
| 108 RefPtr<SkDeferredCanvas> m_canvas; | 108 RefPtr<SkDeferredCanvas> m_canvas; |
| 109 OwnPtr<WebKit::WebExternalTextureLayer> m_layer; | 109 OwnPtr<blink::WebExternalTextureLayer> m_layer; |
| 110 RefPtr<GraphicsContext3D> m_context; | 110 RefPtr<GraphicsContext3D> m_context; |
| 111 int m_msaaSampleCount; | 111 int m_msaaSampleCount; |
| 112 size_t m_bytesAllocated; | 112 size_t m_bytesAllocated; |
| 113 bool m_didRecordDrawCommand; | 113 bool m_didRecordDrawCommand; |
| 114 bool m_surfaceIsValid; | 114 bool m_surfaceIsValid; |
| 115 int m_framesPending; | 115 int m_framesPending; |
| 116 bool m_destructionInProgress; | 116 bool m_destructionInProgress; |
| 117 bool m_rateLimitingEnabled; | 117 bool m_rateLimitingEnabled; |
| 118 | 118 |
| 119 friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>; | 119 friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>; |
| 120 Canvas2DLayerBridge* m_next; | 120 Canvas2DLayerBridge* m_next; |
| 121 Canvas2DLayerBridge* m_prev; | 121 Canvas2DLayerBridge* m_prev; |
| 122 | 122 |
| 123 enum MailboxStatus { | 123 enum MailboxStatus { |
| 124 MailboxInUse, | 124 MailboxInUse, |
| 125 MailboxReleased, | 125 MailboxReleased, |
| 126 MailboxAvailable, | 126 MailboxAvailable, |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 struct MailboxInfo { | 129 struct MailboxInfo { |
| 130 WebKit::WebExternalTextureMailbox m_mailbox; | 130 blink::WebExternalTextureMailbox m_mailbox; |
| 131 SkAutoTUnref<SkImage> m_image; | 131 SkAutoTUnref<SkImage> m_image; |
| 132 MailboxStatus m_status; | 132 MailboxStatus m_status; |
| 133 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; | 133 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; |
| 134 | 134 |
| 135 MailboxInfo(const MailboxInfo&); | 135 MailboxInfo(const MailboxInfo&); |
| 136 MailboxInfo() {} | 136 MailboxInfo() {} |
| 137 }; | 137 }; |
| 138 MailboxInfo* createMailboxInfo(); | 138 MailboxInfo* createMailboxInfo(); |
| 139 | 139 |
| 140 uint32_t m_lastImageId; | 140 uint32_t m_lastImageId; |
| 141 Vector<MailboxInfo> m_mailboxes; | 141 Vector<MailboxInfo> m_mailboxes; |
| 142 }; | 142 }; |
| 143 } | 143 } |
| 144 #endif | 144 #endif |
| OLD | NEW |