2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef Canvas2DLayerBridge_h
27 #define Canvas2DLayerBridge_h
29 #include "SkDeferredCanvas.h"
31 #include "platform/PlatformExport.h"
32 #include "platform/geometry/IntSize.h"
33 #include "platform/graphics/GraphicsContext3D.h"
34 #include "platform/graphics/ImageBufferSurface.h"
35 #include "public/platform/WebExternalTextureLayer.h"
36 #include "public/platform/WebExternalTextureLayerClient.h"
37 #include "public/platform/WebExternalTextureMailbox.h"
38 #include "wtf/DoublyLinkedList.h"
39 #include "wtf/PassOwnPtr.h"
40 #include "wtf/RefCounted.h"
41 #include "wtf/RefPtr.h"
44 class WebGraphicsContext3D;
47 class Canvas2DLayerBridgeTest;
51 class PLATFORM_EXPORT Canvas2DLayerBridge : public blink::WebExternalTextureLayerClient, public SkDeferredCanvas::NotificationClient, public DoublyLinkedListNode<Canvas2DLayerBridge>, public RefCounted<Canvas2DLayerBridge> {
52 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge);
54 static PassRefPtr<Canvas2DLayerBridge> create(const IntSize&, OpacityMode, int msaaSampleCount);
55 virtual ~Canvas2DLayerBridge();
57 // blink::WebExternalTextureLayerClient implementation.
58 virtual blink::WebGraphicsContext3D* context() OVERRIDE;
59 virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExternalBitmap*) OVERRIDE;
60 virtual void mailboxReleased(const blink::WebExternalTextureMailbox&) OVERRIDE;
62 // SkDeferredCanvas::NotificationClient implementation
63 virtual void prepareForDraw() OVERRIDE;
64 virtual void storageAllocatedForRecordingChanged(size_t) OVERRIDE;
65 virtual void flushedDrawCommands() OVERRIDE;
66 virtual void skippedPendingDrawCommands() OVERRIDE;
68 // ImageBufferSurface implementation
70 SkCanvas* canvas() const { return m_canvas.get(); }
72 blink::WebLayer* layer() const;
73 Platform3DObject getBackingTexture();
74 bool isAccelerated() const { return true; }
76 // Methods used by Canvas2DLayerManager
77 virtual size_t freeMemoryIfPossible(size_t); // virtual for mocking
78 virtual void flush(); // virtual for mocking
79 virtual size_t storageAllocatedForRecording(); // virtual for faking
80 size_t bytesAllocated() const {return m_bytesAllocated;}
81 void limitPendingFrames();
83 void beginDestruction();
86 Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D>, PassOwnPtr<SkDeferredCanvas>, int, OpacityMode);
87 void setRateLimitingEnabled(bool);
89 OwnPtr<SkDeferredCanvas> m_canvas;
90 OwnPtr<blink::WebExternalTextureLayer> m_layer;
91 RefPtr<GraphicsContext3D> m_context;
92 int m_msaaSampleCount;
93 size_t m_bytesAllocated;
94 bool m_didRecordDrawCommand;
95 bool m_surfaceIsValid;
97 bool m_destructionInProgress;
98 bool m_rateLimitingEnabled;
100 friend class WTF::DoublyLinkedListNode<Canvas2DLayerBridge>;
101 friend class ::Canvas2DLayerBridgeTest;
102 Canvas2DLayerBridge* m_next;
103 Canvas2DLayerBridge* m_prev;
112 blink::WebExternalTextureMailbox m_mailbox;
113 SkAutoTUnref<SkImage> m_image;
114 MailboxStatus m_status;
115 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge;
117 MailboxInfo(const MailboxInfo&);
120 MailboxInfo* createMailboxInfo();
122 uint32_t m_lastImageId;
123 Vector<MailboxInfo> m_mailboxes;