OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "platform/PlatformExport.h" | 34 #include "platform/PlatformExport.h" |
35 #include "platform/geometry/IntSize.h" | 35 #include "platform/geometry/IntSize.h" |
36 #include "platform/graphics/GraphicsTypes3D.h" | 36 #include "platform/graphics/GraphicsTypes3D.h" |
37 #include "platform/graphics/gpu/WebGLImageConversion.h" | 37 #include "platform/graphics/gpu/WebGLImageConversion.h" |
38 #include "public/platform/WebExternalTextureLayerClient.h" | 38 #include "public/platform/WebExternalTextureLayerClient.h" |
39 #include "public/platform/WebExternalTextureMailbox.h" | 39 #include "public/platform/WebExternalTextureMailbox.h" |
40 #include "public/platform/WebGraphicsContext3D.h" | 40 #include "public/platform/WebGraphicsContext3D.h" |
41 #include "third_party/khronos/GLES2/gl2.h" | 41 #include "third_party/khronos/GLES2/gl2.h" |
42 #include "third_party/khronos/GLES2/gl2ext.h" | 42 #include "third_party/khronos/GLES2/gl2ext.h" |
43 #include "third_party/skia/include/core/SkBitmap.h" | 43 #include "third_party/skia/include/core/SkBitmap.h" |
| 44 #include "wtf/Deque.h" |
44 #include "wtf/Noncopyable.h" | 45 #include "wtf/Noncopyable.h" |
45 #include "wtf/OwnPtr.h" | 46 #include "wtf/OwnPtr.h" |
46 #include "wtf/PassOwnPtr.h" | 47 #include "wtf/PassOwnPtr.h" |
47 | 48 |
48 namespace blink { | 49 namespace blink { |
49 class WebExternalBitmap; | 50 class WebExternalBitmap; |
50 class WebExternalTextureLayer; | 51 class WebExternalTextureLayer; |
51 class WebGraphicsContext3D; | 52 class WebGraphicsContext3D; |
52 class WebLayer; | 53 class WebLayer; |
53 } | 54 } |
(...skipping 11 matching lines...) Expand all Loading... |
65 virtual IntSize oldestContextSize() = 0; | 66 virtual IntSize oldestContextSize() = 0; |
66 }; | 67 }; |
67 | 68 |
68 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ
ish its rendering | 69 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ
ish its rendering |
69 // results to a blink::WebLayer for compositing. | 70 // results to a blink::WebLayer for compositing. |
70 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public b
link::WebExternalTextureLayerClient { | 71 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public b
link::WebExternalTextureLayerClient { |
71 struct MailboxInfo : public RefCounted<MailboxInfo> { | 72 struct MailboxInfo : public RefCounted<MailboxInfo> { |
72 blink::WebExternalTextureMailbox mailbox; | 73 blink::WebExternalTextureMailbox mailbox; |
73 unsigned textureId; | 74 unsigned textureId; |
74 IntSize size; | 75 IntSize size; |
| 76 // This keeps the parent drawing buffer alive as long as the compositor
is |
| 77 // referring to one of the mailboxes DrawingBuffer produced. The parent
drawing buffer is |
| 78 // cleared when the compositor returns the mailbox. See mailboxReleased(
). |
| 79 RefPtr<DrawingBuffer> m_parentDrawingBuffer; |
75 }; | 80 }; |
76 public: | 81 public: |
77 enum PreserveDrawingBuffer { | 82 enum PreserveDrawingBuffer { |
78 Preserve, | 83 Preserve, |
79 Discard | 84 Discard |
80 }; | 85 }; |
81 | 86 |
82 static PassRefPtr<DrawingBuffer> create(PassOwnPtr<blink::WebGraphicsContext
3D>, const IntSize&, PreserveDrawingBuffer, PassRefPtr<ContextEvictionManager>); | 87 static PassRefPtr<DrawingBuffer> create(PassOwnPtr<blink::WebGraphicsContext
3D>, const IntSize&, PreserveDrawingBuffer, PassRefPtr<ContextEvictionManager>); |
83 | 88 |
84 virtual ~DrawingBuffer(); | 89 virtual ~DrawingBuffer(); |
85 | 90 |
| 91 // Destruction will be completed after all mailboxes are released. |
| 92 void beginDestruction(); |
| 93 |
86 // Issues a glClear() on all framebuffers associated with this DrawingBuffer
. The caller is responsible for | 94 // Issues a glClear() on all framebuffers associated with this DrawingBuffer
. The caller is responsible for |
87 // making the context current and setting the clear values and masks. Modifi
es the framebuffer binding. | 95 // making the context current and setting the clear values and masks. Modifi
es the framebuffer binding. |
88 void clearFramebuffers(GLbitfield clearMask); | 96 void clearFramebuffers(GLbitfield clearMask); |
89 | 97 |
90 // Given the desired buffer size, provides the largest dimensions that will
fit in the pixel budget. | 98 // Given the desired buffer size, provides the largest dimensions that will
fit in the pixel budget. |
91 IntSize adjustSize(const IntSize&); | 99 IntSize adjustSize(const IntSize&); |
92 bool reset(const IntSize&); | 100 bool reset(const IntSize&); |
93 void bind(); | 101 void bind(); |
94 IntSize size() const { return m_size; } | 102 IntSize size() const { return m_size; } |
95 | 103 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 139 |
132 // Destroys the TEXTURE_2D binding for the owned context | 140 // Destroys the TEXTURE_2D binding for the owned context |
133 bool copyToPlatformTexture(blink::WebGraphicsContext3D*, Platform3DObject te
xture, GLenum internalFormat, | 141 bool copyToPlatformTexture(blink::WebGraphicsContext3D*, Platform3DObject te
xture, GLenum internalFormat, |
134 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY); | 142 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY); |
135 | 143 |
136 void setPackAlignment(GLint param); | 144 void setPackAlignment(GLint param); |
137 | 145 |
138 void paintRenderingResultsToCanvas(ImageBuffer*); | 146 void paintRenderingResultsToCanvas(ImageBuffer*); |
139 PassRefPtr<Uint8ClampedArray> paintRenderingResultsToImageData(int&, int&); | 147 PassRefPtr<Uint8ClampedArray> paintRenderingResultsToImageData(int&, int&); |
140 | 148 |
141 private: | 149 protected: // For unittests |
142 DrawingBuffer(PassOwnPtr<blink::WebGraphicsContext3D>, bool multisampleExten
sionSupported, | 150 DrawingBuffer(PassOwnPtr<blink::WebGraphicsContext3D>, bool multisampleExten
sionSupported, |
143 bool packedDepthStencilExtensionSupported, PreserveDrawingBuff
er, PassRefPtr<ContextEvictionManager>); | 151 bool packedDepthStencilExtensionSupported, PreserveDrawingBuff
er, PassRefPtr<ContextEvictionManager>); |
144 | 152 |
145 bool initialize(const IntSize&); | 153 bool initialize(const IntSize&); |
146 void releaseResources(); | 154 |
| 155 private: |
| 156 void mailboxReleasedWhileDestructionInProgress(const blink::WebExternalTextu
reMailbox&); |
147 | 157 |
148 unsigned createColorTexture(const IntSize& size = IntSize()); | 158 unsigned createColorTexture(const IntSize& size = IntSize()); |
149 // Create the depth/stencil and multisample buffers, if needed. | 159 // Create the depth/stencil and multisample buffers, if needed. |
150 void createSecondaryBuffers(); | 160 void createSecondaryBuffers(); |
151 bool resizeFramebuffer(const IntSize&); | 161 bool resizeFramebuffer(const IntSize&); |
152 bool resizeMultisampleFramebuffer(const IntSize&); | 162 bool resizeMultisampleFramebuffer(const IntSize&); |
153 void resizeDepthStencil(const IntSize&); | 163 void resizeDepthStencil(const IntSize&); |
154 | 164 |
155 // Bind to the m_framebufferBinding if it's not 0. | 165 // Bind to the m_framebufferBinding if it's not 0. |
156 void restoreFramebufferBinding(); | 166 void restoreFramebufferBinding(); |
157 | 167 |
158 void clearPlatformLayer(); | 168 void clearPlatformLayer(); |
159 | 169 |
160 PassRefPtr<MailboxInfo> recycledMailbox(); | 170 PassRefPtr<MailboxInfo> recycledMailbox(); |
161 PassRefPtr<MailboxInfo> createNewMailbox(unsigned); | 171 PassRefPtr<MailboxInfo> createNewMailbox(unsigned); |
| 172 void deleteMailbox(const blink::WebExternalTextureMailbox&); |
162 | 173 |
163 // Updates the current size of the buffer, ensuring that s_currentResourceUs
ePixels is updated. | 174 // Updates the current size of the buffer, ensuring that s_currentResourceUs
ePixels is updated. |
164 void setSize(const IntSize& size); | 175 void setSize(const IntSize& size); |
165 | 176 |
166 // Calculates the difference in pixels between the current buffer size and t
he proposed size. | 177 // Calculates the difference in pixels between the current buffer size and t
he proposed size. |
167 int pixelDelta(const IntSize& size); | 178 int pixelDelta(const IntSize& size); |
168 | 179 |
169 // Given the desired buffer size, provides the largest dimensions that will
fit in the pixel budget | 180 // Given the desired buffer size, provides the largest dimensions that will
fit in the pixel budget |
170 // Returns true if the buffer will only fit if the oldest WebGL context is f
orcibly lost | 181 // Returns true if the buffer will only fit if the oldest WebGL context is f
orcibly lost |
171 IntSize adjustSizeWithContextEviction(const IntSize&, bool& evictContext); | 182 IntSize adjustSizeWithContextEviction(const IntSize&, bool& evictContext); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 241 |
231 MultisampleMode m_multisampleMode; | 242 MultisampleMode m_multisampleMode; |
232 | 243 |
233 blink::WebGraphicsContext3D::Attributes m_attributes; | 244 blink::WebGraphicsContext3D::Attributes m_attributes; |
234 unsigned m_internalColorFormat; | 245 unsigned m_internalColorFormat; |
235 unsigned m_colorFormat; | 246 unsigned m_colorFormat; |
236 unsigned m_internalRenderbufferFormat; | 247 unsigned m_internalRenderbufferFormat; |
237 int m_maxTextureSize; | 248 int m_maxTextureSize; |
238 int m_sampleCount; | 249 int m_sampleCount; |
239 int m_packAlignment; | 250 int m_packAlignment; |
| 251 bool m_destructionInProgress; |
240 | 252 |
241 OwnPtr<blink::WebExternalTextureLayer> m_layer; | 253 OwnPtr<blink::WebExternalTextureLayer> m_layer; |
242 | 254 |
243 // All of the mailboxes that this DrawingBuffer has ever created. | 255 // All of the mailboxes that this DrawingBuffer has ever created. |
244 Vector<RefPtr<MailboxInfo> > m_textureMailboxes; | 256 Vector<RefPtr<MailboxInfo> > m_textureMailboxes; |
245 // Mailboxes that were released by the compositor and can be used again by t
his DrawingBuffer. | 257 // Mailboxes that were released by the compositor can be used again by this
DrawingBuffer. |
246 Vector<RefPtr<MailboxInfo> > m_recycledMailboxes; | 258 Deque<blink::WebExternalTextureMailbox> m_recycledMailboxQueue; |
247 | 259 |
248 RefPtr<ContextEvictionManager> m_contextEvictionManager; | 260 RefPtr<ContextEvictionManager> m_contextEvictionManager; |
249 | 261 |
250 // If the width and height of the Canvas's backing store don't | 262 // If the width and height of the Canvas's backing store don't |
251 // match those that we were given in the most recent call to | 263 // match those that we were given in the most recent call to |
252 // reshape(), then we need an intermediate bitmap to read back the | 264 // reshape(), then we need an intermediate bitmap to read back the |
253 // frame buffer into. This seems to happen when CSS styles are | 265 // frame buffer into. This seems to happen when CSS styles are |
254 // used to resize the Canvas. | 266 // used to resize the Canvas. |
255 SkBitmap m_resizingBitmap; | 267 SkBitmap m_resizingBitmap; |
256 | 268 |
257 // Used to flip a bitmap vertically. | 269 // Used to flip a bitmap vertically. |
258 Vector<uint8_t> m_scanline; | 270 Vector<uint8_t> m_scanline; |
259 }; | 271 }; |
260 | 272 |
261 } // namespace WebCore | 273 } // namespace WebCore |
262 | 274 |
263 #endif // DrawingBuffer_h | 275 #endif // DrawingBuffer_h |
OLD | NEW |