| 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 22 matching lines...) Expand all Loading... |
| 33 #include "platform/graphics/ImageBufferSurface.h" | 33 #include "platform/graphics/ImageBufferSurface.h" |
| 34 #include "public/platform/WebExternalTextureLayer.h" | 34 #include "public/platform/WebExternalTextureLayer.h" |
| 35 #include "public/platform/WebExternalTextureLayerClient.h" | 35 #include "public/platform/WebExternalTextureLayerClient.h" |
| 36 #include "public/platform/WebExternalTextureMailbox.h" | 36 #include "public/platform/WebExternalTextureMailbox.h" |
| 37 #include "third_party/khronos/GLES2/gl2.h" | 37 #include "third_party/khronos/GLES2/gl2.h" |
| 38 #include "wtf/DoublyLinkedList.h" | 38 #include "wtf/DoublyLinkedList.h" |
| 39 #include "wtf/PassOwnPtr.h" | 39 #include "wtf/PassOwnPtr.h" |
| 40 #include "wtf/RefCounted.h" | 40 #include "wtf/RefCounted.h" |
| 41 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
| 42 | 42 |
| 43 namespace blink { | |
| 44 class WebGraphicsContext3D; | |
| 45 class WebGraphicsContext3DProvider; | |
| 46 } | |
| 47 | |
| 48 class Canvas2DLayerBridgeTest; | 43 class Canvas2DLayerBridgeTest; |
| 49 | 44 |
| 50 namespace blink { | 45 namespace blink { |
| 51 | 46 |
| 52 class ImageBuffer; | 47 class ImageBuffer; |
| 48 class WebGraphicsContext3D; |
| 49 class WebGraphicsContext3DProvider; |
| 53 | 50 |
| 54 class PLATFORM_EXPORT Canvas2DLayerBridge : public blink::WebExternalTextureLaye
rClient, public SkDeferredCanvas::NotificationClient, public DoublyLinkedListNod
e<Canvas2DLayerBridge>, public RefCounted<Canvas2DLayerBridge> { | 51 class PLATFORM_EXPORT Canvas2DLayerBridge : public WebExternalTextureLayerClient
, public SkDeferredCanvas::NotificationClient, public DoublyLinkedListNode<Canva
s2DLayerBridge>, public RefCounted<Canvas2DLayerBridge> { |
| 55 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); | 52 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); |
| 56 public: | 53 public: |
| 57 static PassRefPtr<Canvas2DLayerBridge> create(const IntSize&, OpacityMode, i
nt msaaSampleCount); | 54 static PassRefPtr<Canvas2DLayerBridge> create(const IntSize&, OpacityMode, i
nt msaaSampleCount); |
| 58 | 55 |
| 59 virtual ~Canvas2DLayerBridge(); | 56 virtual ~Canvas2DLayerBridge(); |
| 60 | 57 |
| 61 // blink::WebExternalTextureLayerClient implementation. | 58 // WebExternalTextureLayerClient implementation. |
| 62 virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExt
ernalBitmap*) OVERRIDE; | 59 virtual bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*)
OVERRIDE; |
| 63 virtual void mailboxReleased(const blink::WebExternalTextureMailbox&, bool l
ostResource) OVERRIDE; | 60 virtual void mailboxReleased(const WebExternalTextureMailbox&, bool lostReso
urce) OVERRIDE; |
| 64 | 61 |
| 65 // SkDeferredCanvas::NotificationClient implementation | 62 // SkDeferredCanvas::NotificationClient implementation |
| 66 virtual void prepareForDraw() OVERRIDE; | 63 virtual void prepareForDraw() OVERRIDE; |
| 67 virtual void storageAllocatedForRecordingChanged(size_t) OVERRIDE; | 64 virtual void storageAllocatedForRecordingChanged(size_t) OVERRIDE; |
| 68 virtual void flushedDrawCommands() OVERRIDE; | 65 virtual void flushedDrawCommands() OVERRIDE; |
| 69 virtual void skippedPendingDrawCommands() OVERRIDE; | 66 virtual void skippedPendingDrawCommands() OVERRIDE; |
| 70 | 67 |
| 71 // ImageBufferSurface implementation | 68 // ImageBufferSurface implementation |
| 72 void finalizeFrame(); | 69 void finalizeFrame(); |
| 73 void willAccessPixels(); | 70 void willAccessPixels(); |
| 74 SkCanvas* canvas() const { return m_canvas.get(); } | 71 SkCanvas* canvas() const { return m_canvas.get(); } |
| 75 bool checkSurfaceValid(); | 72 bool checkSurfaceValid(); |
| 76 bool restoreSurface(); | 73 bool restoreSurface(); |
| 77 blink::WebLayer* layer() const; | 74 WebLayer* layer() const; |
| 78 Platform3DObject getBackingTexture(); | 75 Platform3DObject getBackingTexture(); |
| 79 bool isAccelerated() const { return true; } | 76 bool isAccelerated() const { return true; } |
| 80 void setIsHidden(bool); | 77 void setIsHidden(bool); |
| 81 void setImageBuffer(ImageBuffer* imageBuffer) { m_imageBuffer = imageBuffer;
} | 78 void setImageBuffer(ImageBuffer* imageBuffer) { m_imageBuffer = imageBuffer;
} |
| 82 | 79 |
| 83 // Methods used by Canvas2DLayerManager | 80 // Methods used by Canvas2DLayerManager |
| 84 virtual size_t freeMemoryIfPossible(size_t); // virtual for mocking | 81 virtual size_t freeMemoryIfPossible(size_t); // virtual for mocking |
| 85 virtual void flush(); // virtual for mocking | 82 virtual void flush(); // virtual for mocking |
| 86 virtual size_t storageAllocatedForRecording(); // virtual for faking | 83 virtual size_t storageAllocatedForRecording(); // virtual for faking |
| 87 size_t bytesAllocated() const { return m_bytesAllocated; } | 84 size_t bytesAllocated() const { return m_bytesAllocated; } |
| 88 void limitPendingFrames(); | 85 void limitPendingFrames(); |
| 89 void freeReleasedMailbox(); | 86 void freeReleasedMailbox(); |
| 90 bool hasReleasedMailbox() const; | 87 bool hasReleasedMailbox() const; |
| 91 void freeTransientResources(); | 88 void freeTransientResources(); |
| 92 bool hasTransientResources() const; | 89 bool hasTransientResources() const; |
| 93 bool isHidden() { return m_isHidden; } | 90 bool isHidden() { return m_isHidden; } |
| 94 | 91 |
| 95 void beginDestruction(); | 92 void beginDestruction(); |
| 96 | 93 |
| 97 protected: | 94 protected: |
| 98 Canvas2DLayerBridge(PassOwnPtr<blink::WebGraphicsContext3DProvider>, PassOwn
Ptr<SkDeferredCanvas>, PassRefPtr<SkSurface>, int, OpacityMode); | 95 Canvas2DLayerBridge(PassOwnPtr<WebGraphicsContext3DProvider>, PassOwnPtr<SkD
eferredCanvas>, PassRefPtr<SkSurface>, int, OpacityMode); |
| 99 void setRateLimitingEnabled(bool); | 96 void setRateLimitingEnabled(bool); |
| 100 bool releasedMailboxHasExpired(); | 97 bool releasedMailboxHasExpired(); |
| 101 blink::WebGraphicsContext3D* context(); | 98 WebGraphicsContext3D* context(); |
| 102 | 99 |
| 103 OwnPtr<SkDeferredCanvas> m_canvas; | 100 OwnPtr<SkDeferredCanvas> m_canvas; |
| 104 RefPtr<SkSurface> m_surface; | 101 RefPtr<SkSurface> m_surface; |
| 105 OwnPtr<blink::WebExternalTextureLayer> m_layer; | 102 OwnPtr<WebExternalTextureLayer> m_layer; |
| 106 OwnPtr<blink::WebGraphicsContext3DProvider> m_contextProvider; | 103 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; |
| 107 ImageBuffer* m_imageBuffer; | 104 ImageBuffer* m_imageBuffer; |
| 108 int m_msaaSampleCount; | 105 int m_msaaSampleCount; |
| 109 size_t m_bytesAllocated; | 106 size_t m_bytesAllocated; |
| 110 bool m_didRecordDrawCommand; | 107 bool m_didRecordDrawCommand; |
| 111 bool m_isSurfaceValid; | 108 bool m_isSurfaceValid; |
| 112 int m_framesPending; | 109 int m_framesPending; |
| 113 int m_framesSinceMailboxRelease; | 110 int m_framesSinceMailboxRelease; |
| 114 bool m_destructionInProgress; | 111 bool m_destructionInProgress; |
| 115 bool m_rateLimitingEnabled; | 112 bool m_rateLimitingEnabled; |
| 116 bool m_isHidden; | 113 bool m_isHidden; |
| 117 | 114 |
| 118 friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>; | 115 friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>; |
| 119 friend class ::Canvas2DLayerBridgeTest; | 116 friend class ::Canvas2DLayerBridgeTest; |
| 120 Canvas2DLayerBridge* m_next; | 117 Canvas2DLayerBridge* m_next; |
| 121 Canvas2DLayerBridge* m_prev; | 118 Canvas2DLayerBridge* m_prev; |
| 122 | 119 |
| 123 enum MailboxStatus { | 120 enum MailboxStatus { |
| 124 MailboxInUse, | 121 MailboxInUse, |
| 125 MailboxReleased, | 122 MailboxReleased, |
| 126 MailboxAvailable, | 123 MailboxAvailable, |
| 127 }; | 124 }; |
| 128 | 125 |
| 129 struct MailboxInfo { | 126 struct MailboxInfo { |
| 130 blink::WebExternalTextureMailbox m_mailbox; | 127 WebExternalTextureMailbox m_mailbox; |
| 131 RefPtr<SkImage> m_image; | 128 RefPtr<SkImage> m_image; |
| 132 MailboxStatus m_status; | 129 MailboxStatus m_status; |
| 133 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; | 130 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; |
| 134 | 131 |
| 135 MailboxInfo(const MailboxInfo&); | 132 MailboxInfo(const MailboxInfo&); |
| 136 MailboxInfo() {} | 133 MailboxInfo() {} |
| 137 }; | 134 }; |
| 138 MailboxInfo* createMailboxInfo(); | 135 MailboxInfo* createMailboxInfo(); |
| 139 MailboxInfo* releasedMailboxInfo(); | 136 MailboxInfo* releasedMailboxInfo(); |
| 140 | 137 |
| 141 uint32_t m_lastImageId; | 138 uint32_t m_lastImageId; |
| 142 Vector<MailboxInfo> m_mailboxes; | 139 Vector<MailboxInfo> m_mailboxes; |
| 143 int m_releasedMailboxInfoIndex; | 140 int m_releasedMailboxInfoIndex; |
| 144 }; | 141 }; |
| 145 } | 142 |
| 143 } // namespace blink |
| 144 |
| 146 #endif | 145 #endif |
| OLD | NEW |