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 29 matching lines...) Expand all Loading... |
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/Deque.h" |
45 #include "wtf/Noncopyable.h" | 45 #include "wtf/Noncopyable.h" |
46 #include "wtf/OwnPtr.h" | 46 #include "wtf/OwnPtr.h" |
47 #include "wtf/PassOwnPtr.h" | 47 #include "wtf/PassOwnPtr.h" |
48 | 48 |
49 namespace blink { | 49 namespace blink { |
| 50 |
| 51 class Extensions3DUtil; |
| 52 class ImageBuffer; |
| 53 class ImageData; |
50 class WebExternalBitmap; | 54 class WebExternalBitmap; |
51 class WebExternalTextureLayer; | 55 class WebExternalTextureLayer; |
52 class WebGraphicsContext3D; | 56 class WebGraphicsContext3D; |
53 class WebLayer; | 57 class WebLayer; |
54 } | |
55 | |
56 namespace blink { | |
57 class Extensions3DUtil; | |
58 class ImageData; | |
59 class ImageBuffer; | |
60 | 58 |
61 // Abstract interface to allow basic context eviction management | 59 // Abstract interface to allow basic context eviction management |
62 class PLATFORM_EXPORT ContextEvictionManager : public RefCounted<ContextEviction
Manager> { | 60 class PLATFORM_EXPORT ContextEvictionManager : public RefCounted<ContextEviction
Manager> { |
63 public: | 61 public: |
64 virtual ~ContextEvictionManager() {}; | 62 virtual ~ContextEvictionManager() {}; |
65 | 63 |
66 virtual void forciblyLoseOldestContext(const String& reason) = 0; | 64 virtual void forciblyLoseOldestContext(const String& reason) = 0; |
67 virtual IntSize oldestContextSize() = 0; | 65 virtual IntSize oldestContextSize() = 0; |
68 }; | 66 }; |
69 | 67 |
70 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ
ish its rendering | 68 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ
ish its rendering |
71 // results to a blink::WebLayer for compositing. | 69 // results to a WebLayer for compositing. |
72 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public b
link::WebExternalTextureLayerClient { | 70 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public W
ebExternalTextureLayerClient { |
73 // If we used CHROMIUM_image as the backing storage for our buffers, | 71 // If we used CHROMIUM_image as the backing storage for our buffers, |
74 // we need to know the mapping from texture id to image. | 72 // we need to know the mapping from texture id to image. |
75 struct TextureInfo { | 73 struct TextureInfo { |
76 Platform3DObject textureId; | 74 Platform3DObject textureId; |
77 blink::WGC3Duint imageId; | 75 WGC3Duint imageId; |
78 | 76 |
79 TextureInfo() | 77 TextureInfo() |
80 : textureId(0) | 78 : textureId(0) |
81 , imageId(0) | 79 , imageId(0) |
82 { | 80 { |
83 } | 81 } |
84 }; | 82 }; |
85 | 83 |
86 struct MailboxInfo : public RefCounted<MailboxInfo> { | 84 struct MailboxInfo : public RefCounted<MailboxInfo> { |
87 blink::WebExternalTextureMailbox mailbox; | 85 WebExternalTextureMailbox mailbox; |
88 TextureInfo textureInfo; | 86 TextureInfo textureInfo; |
89 IntSize size; | 87 IntSize size; |
90 // This keeps the parent drawing buffer alive as long as the compositor
is | 88 // This keeps the parent drawing buffer alive as long as the compositor
is |
91 // referring to one of the mailboxes DrawingBuffer produced. The parent
drawing buffer is | 89 // referring to one of the mailboxes DrawingBuffer produced. The parent
drawing buffer is |
92 // cleared when the compositor returns the mailbox. See mailboxReleased(
). | 90 // cleared when the compositor returns the mailbox. See mailboxReleased(
). |
93 RefPtr<DrawingBuffer> m_parentDrawingBuffer; | 91 RefPtr<DrawingBuffer> m_parentDrawingBuffer; |
94 }; | 92 }; |
95 public: | 93 public: |
96 enum PreserveDrawingBuffer { | 94 enum PreserveDrawingBuffer { |
97 Preserve, | 95 Preserve, |
98 Discard | 96 Discard |
99 }; | 97 }; |
100 | 98 |
101 static PassRefPtr<DrawingBuffer> create(PassOwnPtr<blink::WebGraphicsContext
3D>, const IntSize&, PreserveDrawingBuffer, blink::WebGraphicsContext3D::Attribu
tes requestedAttributes, PassRefPtr<ContextEvictionManager>); | 99 static PassRefPtr<DrawingBuffer> create(PassOwnPtr<WebGraphicsContext3D>, co
nst IntSize&, PreserveDrawingBuffer, WebGraphicsContext3D::Attributes requestedA
ttributes, PassRefPtr<ContextEvictionManager>); |
102 | 100 |
103 virtual ~DrawingBuffer(); | 101 virtual ~DrawingBuffer(); |
104 | 102 |
105 // Destruction will be completed after all mailboxes are released. | 103 // Destruction will be completed after all mailboxes are released. |
106 void beginDestruction(); | 104 void beginDestruction(); |
107 | 105 |
108 // Issues a glClear() on all framebuffers associated with this DrawingBuffer
. The caller is responsible for | 106 // Issues a glClear() on all framebuffers associated with this DrawingBuffer
. The caller is responsible for |
109 // making the context current and setting the clear values and masks. Modifi
es the framebuffer binding. | 107 // making the context current and setting the clear values and masks. Modifi
es the framebuffer binding. |
110 void clearFramebuffers(GLbitfield clearMask); | 108 void clearFramebuffers(GLbitfield clearMask); |
111 | 109 |
(...skipping 24 matching lines...) Expand all Loading... |
136 void setActiveTextureUnit(GLint textureUnit) { m_activeTextureUnit = texture
Unit; } | 134 void setActiveTextureUnit(GLint textureUnit) { m_activeTextureUnit = texture
Unit; } |
137 | 135 |
138 bool multisample() const; | 136 bool multisample() const; |
139 | 137 |
140 Platform3DObject framebuffer() const; | 138 Platform3DObject framebuffer() const; |
141 | 139 |
142 void markContentsChanged(); | 140 void markContentsChanged(); |
143 void markLayerComposited(); | 141 void markLayerComposited(); |
144 bool layerComposited() const; | 142 bool layerComposited() const; |
145 | 143 |
146 blink::WebLayer* platformLayer(); | 144 WebLayer* platformLayer(); |
147 void paintCompositedResultsToCanvas(ImageBuffer*); | 145 void paintCompositedResultsToCanvas(ImageBuffer*); |
148 | 146 |
149 blink::WebGraphicsContext3D* context(); | 147 WebGraphicsContext3D* context(); |
150 | 148 |
151 // Returns the actual context attributes for this drawing buffer which may d
iffer from the | 149 // Returns the actual context attributes for this drawing buffer which may d
iffer from the |
152 // requested context attributes due to implementation limits. | 150 // requested context attributes due to implementation limits. |
153 blink::WebGraphicsContext3D::Attributes getActualAttributes() const { return
m_actualAttributes; } | 151 WebGraphicsContext3D::Attributes getActualAttributes() const { return m_actu
alAttributes; } |
154 | 152 |
155 // WebExternalTextureLayerClient implementation. | 153 // WebExternalTextureLayerClient implementation. |
156 virtual bool prepareMailbox(blink::WebExternalTextureMailbox*, blink::WebExt
ernalBitmap*) OVERRIDE; | 154 virtual bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*)
OVERRIDE; |
157 virtual void mailboxReleased(const blink::WebExternalTextureMailbox&, bool l
ostResource = false) OVERRIDE; | 155 virtual void mailboxReleased(const WebExternalTextureMailbox&, bool lostReso
urce = false) OVERRIDE; |
158 | 156 |
159 // Destroys the TEXTURE_2D binding for the owned context | 157 // Destroys the TEXTURE_2D binding for the owned context |
160 bool copyToPlatformTexture(blink::WebGraphicsContext3D*, Platform3DObject te
xture, GLenum internalFormat, | 158 bool copyToPlatformTexture(WebGraphicsContext3D*, Platform3DObject texture,
GLenum internalFormat, |
161 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, bool fr
omFrontBuffer = false); | 159 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, bool fr
omFrontBuffer = false); |
162 | 160 |
163 void setPackAlignment(GLint param); | 161 void setPackAlignment(GLint param); |
164 | 162 |
165 void paintRenderingResultsToCanvas(ImageBuffer*); | 163 void paintRenderingResultsToCanvas(ImageBuffer*); |
166 PassRefPtr<Uint8ClampedArray> paintRenderingResultsToImageData(int&, int&); | 164 PassRefPtr<Uint8ClampedArray> paintRenderingResultsToImageData(int&, int&); |
167 | 165 |
168 protected: // For unittests | 166 protected: // For unittests |
169 DrawingBuffer( | 167 DrawingBuffer( |
170 PassOwnPtr<blink::WebGraphicsContext3D>, | 168 PassOwnPtr<WebGraphicsContext3D>, |
171 PassOwnPtr<Extensions3DUtil>, | 169 PassOwnPtr<Extensions3DUtil>, |
172 bool multisampleExtensionSupported, | 170 bool multisampleExtensionSupported, |
173 bool packedDepthStencilExtensionSupported, | 171 bool packedDepthStencilExtensionSupported, |
174 PreserveDrawingBuffer, | 172 PreserveDrawingBuffer, |
175 blink::WebGraphicsContext3D::Attributes requestedAttributes, | 173 WebGraphicsContext3D::Attributes requestedAttributes, |
176 PassRefPtr<ContextEvictionManager>); | 174 PassRefPtr<ContextEvictionManager>); |
177 | 175 |
178 bool initialize(const IntSize&); | 176 bool initialize(const IntSize&); |
179 | 177 |
180 private: | 178 private: |
181 void mailboxReleasedWhileDestructionInProgress(const blink::WebExternalTextu
reMailbox&); | 179 void mailboxReleasedWhileDestructionInProgress(const WebExternalTextureMailb
ox&); |
182 | 180 |
183 unsigned createColorTexture(); | 181 unsigned createColorTexture(); |
184 // Create the depth/stencil and multisample buffers, if needed. | 182 // Create the depth/stencil and multisample buffers, if needed. |
185 void createSecondaryBuffers(); | 183 void createSecondaryBuffers(); |
186 bool resizeFramebuffer(const IntSize&); | 184 bool resizeFramebuffer(const IntSize&); |
187 bool resizeMultisampleFramebuffer(const IntSize&); | 185 bool resizeMultisampleFramebuffer(const IntSize&); |
188 void resizeDepthStencil(const IntSize&); | 186 void resizeDepthStencil(const IntSize&); |
189 | 187 |
190 // Bind to the m_framebufferBinding if it's not 0. | 188 // Bind to the m_framebufferBinding if it's not 0. |
191 void restoreFramebufferBinding(); | 189 void restoreFramebufferBinding(); |
192 | 190 |
193 void clearPlatformLayer(); | 191 void clearPlatformLayer(); |
194 | 192 |
195 PassRefPtr<MailboxInfo> recycledMailbox(); | 193 PassRefPtr<MailboxInfo> recycledMailbox(); |
196 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&); | 194 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&); |
197 void deleteMailbox(const blink::WebExternalTextureMailbox&); | 195 void deleteMailbox(const WebExternalTextureMailbox&); |
198 | 196 |
199 // Updates the current size of the buffer, ensuring that s_currentResourceUs
ePixels is updated. | 197 // Updates the current size of the buffer, ensuring that s_currentResourceUs
ePixels is updated. |
200 void setSize(const IntSize& size); | 198 void setSize(const IntSize& size); |
201 | 199 |
202 // Calculates the difference in pixels between the current buffer size and t
he proposed size. | 200 // Calculates the difference in pixels between the current buffer size and t
he proposed size. |
203 static int pixelDelta(const IntSize& newSize, const IntSize& curSize); | 201 static int pixelDelta(const IntSize& newSize, const IntSize& curSize); |
204 | 202 |
205 // Given the desired buffer size, provides the largest dimensions that will
fit in the pixel budget | 203 // Given the desired buffer size, provides the largest dimensions that will
fit in the pixel budget |
206 // Returns true if the buffer will only fit if the oldest WebGL context is f
orcibly lost | 204 // Returns true if the buffer will only fit if the oldest WebGL context is f
orcibly lost |
207 IntSize adjustSizeWithContextEviction(const IntSize&, bool& evictContext); | 205 IntSize adjustSizeWithContextEviction(const IntSize&, bool& evictContext); |
(...skipping 19 matching lines...) Expand all Loading... |
227 // Allocate buffer storage to be sent to compositor using either texImage2D
or CHROMIUM_image based on available support. | 225 // Allocate buffer storage to be sent to compositor using either texImage2D
or CHROMIUM_image based on available support. |
228 void allocateTextureMemory(TextureInfo*, const IntSize&); | 226 void allocateTextureMemory(TextureInfo*, const IntSize&); |
229 void deleteChromiumImageForTexture(TextureInfo*); | 227 void deleteChromiumImageForTexture(TextureInfo*); |
230 | 228 |
231 PreserveDrawingBuffer m_preserveDrawingBuffer; | 229 PreserveDrawingBuffer m_preserveDrawingBuffer; |
232 bool m_scissorEnabled; | 230 bool m_scissorEnabled; |
233 Platform3DObject m_texture2DBinding; | 231 Platform3DObject m_texture2DBinding; |
234 Platform3DObject m_framebufferBinding; | 232 Platform3DObject m_framebufferBinding; |
235 GLenum m_activeTextureUnit; | 233 GLenum m_activeTextureUnit; |
236 | 234 |
237 OwnPtr<blink::WebGraphicsContext3D> m_context; | 235 OwnPtr<WebGraphicsContext3D> m_context; |
238 OwnPtr<Extensions3DUtil> m_extensionsUtil; | 236 OwnPtr<Extensions3DUtil> m_extensionsUtil; |
239 IntSize m_size; | 237 IntSize m_size; |
240 blink::WebGraphicsContext3D::Attributes m_requestedAttributes; | 238 WebGraphicsContext3D::Attributes m_requestedAttributes; |
241 bool m_multisampleExtensionSupported; | 239 bool m_multisampleExtensionSupported; |
242 bool m_packedDepthStencilExtensionSupported; | 240 bool m_packedDepthStencilExtensionSupported; |
243 Platform3DObject m_fbo; | 241 Platform3DObject m_fbo; |
244 // DrawingBuffer's output is double-buffered. m_colorBuffer is the back buff
er. | 242 // DrawingBuffer's output is double-buffered. m_colorBuffer is the back buff
er. |
245 TextureInfo m_colorBuffer; | 243 TextureInfo m_colorBuffer; |
246 TextureInfo m_frontColorBuffer; | 244 TextureInfo m_frontColorBuffer; |
247 | 245 |
248 // This is used when we have OES_packed_depth_stencil. | 246 // This is used when we have OES_packed_depth_stencil. |
249 Platform3DObject m_depthStencilBuffer; | 247 Platform3DObject m_depthStencilBuffer; |
250 | 248 |
(...skipping 13 matching lines...) Expand all Loading... |
264 bool m_layerComposited; | 262 bool m_layerComposited; |
265 | 263 |
266 enum MultisampleMode { | 264 enum MultisampleMode { |
267 None, | 265 None, |
268 ImplicitResolve, | 266 ImplicitResolve, |
269 ExplicitResolve, | 267 ExplicitResolve, |
270 }; | 268 }; |
271 | 269 |
272 MultisampleMode m_multisampleMode; | 270 MultisampleMode m_multisampleMode; |
273 | 271 |
274 blink::WebGraphicsContext3D::Attributes m_actualAttributes; | 272 WebGraphicsContext3D::Attributes m_actualAttributes; |
275 unsigned m_internalColorFormat; | 273 unsigned m_internalColorFormat; |
276 unsigned m_colorFormat; | 274 unsigned m_colorFormat; |
277 unsigned m_internalRenderbufferFormat; | 275 unsigned m_internalRenderbufferFormat; |
278 int m_maxTextureSize; | 276 int m_maxTextureSize; |
279 int m_sampleCount; | 277 int m_sampleCount; |
280 int m_packAlignment; | 278 int m_packAlignment; |
281 bool m_destructionInProgress; | 279 bool m_destructionInProgress; |
282 | 280 |
283 OwnPtr<blink::WebExternalTextureLayer> m_layer; | 281 OwnPtr<WebExternalTextureLayer> m_layer; |
284 | 282 |
285 // All of the mailboxes that this DrawingBuffer has ever created. | 283 // All of the mailboxes that this DrawingBuffer has ever created. |
286 Vector<RefPtr<MailboxInfo> > m_textureMailboxes; | 284 Vector<RefPtr<MailboxInfo> > m_textureMailboxes; |
287 // Mailboxes that were released by the compositor can be used again by this
DrawingBuffer. | 285 // Mailboxes that were released by the compositor can be used again by this
DrawingBuffer. |
288 Deque<blink::WebExternalTextureMailbox> m_recycledMailboxQueue; | 286 Deque<WebExternalTextureMailbox> m_recycledMailboxQueue; |
289 | 287 |
290 RefPtr<ContextEvictionManager> m_contextEvictionManager; | 288 RefPtr<ContextEvictionManager> m_contextEvictionManager; |
291 | 289 |
292 // If the width and height of the Canvas's backing store don't | 290 // If the width and height of the Canvas's backing store don't |
293 // match those that we were given in the most recent call to | 291 // match those that we were given in the most recent call to |
294 // reshape(), then we need an intermediate bitmap to read back the | 292 // reshape(), then we need an intermediate bitmap to read back the |
295 // frame buffer into. This seems to happen when CSS styles are | 293 // frame buffer into. This seems to happen when CSS styles are |
296 // used to resize the Canvas. | 294 // used to resize the Canvas. |
297 SkBitmap m_resizingBitmap; | 295 SkBitmap m_resizingBitmap; |
298 | 296 |
299 // Used to flip a bitmap vertically. | 297 // Used to flip a bitmap vertically. |
300 Vector<uint8_t> m_scanline; | 298 Vector<uint8_t> m_scanline; |
301 }; | 299 }; |
302 | 300 |
303 } // namespace blink | 301 } // namespace blink |
304 | 302 |
305 #endif // DrawingBuffer_h | 303 #endif // DrawingBuffer_h |
OLD | NEW |