| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // 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 |
| 70 // results to a WebLayer for compositing. | 70 // results to a WebLayer for compositing. |
| 71 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public W
ebExternalTextureLayerClient { | 71 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public W
ebExternalTextureLayerClient { |
| 72 WTF_MAKE_NONCOPYABLE(DrawingBuffer); | 72 WTF_MAKE_NONCOPYABLE(DrawingBuffer); |
| 73 public: | 73 public: |
| 74 enum PreserveDrawingBuffer { | 74 enum PreserveDrawingBuffer { |
| 75 Preserve, | 75 Preserve, |
| 76 Discard | 76 Discard |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 static PassRefPtr<DrawingBuffer> create(PassOwnPtr<WebGraphicsContext3DProvi
der>, const IntSize&, bool premultipliedAlpha, PreserveDrawingBuffer, WebGraphic
sContext3D::Attributes requestedAttributes); | 79 static PassRefPtr<DrawingBuffer> create( |
| 80 PassOwnPtr<WebGraphicsContext3DProvider>, |
| 81 const IntSize&, |
| 82 bool premultipliedAlpha, |
| 83 bool wantAlphaChannel, |
| 84 bool wantDepthBuffer, |
| 85 bool wantStencilBuffer, |
| 86 bool wantAntialiasing, |
| 87 PreserveDrawingBuffer); |
| 80 static void forceNextDrawingBufferCreationToFail(); | 88 static void forceNextDrawingBufferCreationToFail(); |
| 81 | 89 |
| 82 ~DrawingBuffer() override; | 90 ~DrawingBuffer() override; |
| 83 | 91 |
| 84 // Destruction will be completed after all mailboxes are released. | 92 // Destruction will be completed after all mailboxes are released. |
| 85 void beginDestruction(); | 93 void beginDestruction(); |
| 86 | 94 |
| 87 // Issues a glClear() on all framebuffers associated with this DrawingBuffer
. The caller is responsible for | 95 // Issues a glClear() on all framebuffers associated with this DrawingBuffer
. The caller is responsible for |
| 88 // making the context current and setting the clear values and masks. Modifi
es the framebuffer binding. | 96 // making the context current and setting the clear values and masks. Modifi
es the framebuffer binding. |
| 89 void clearFramebuffers(GLbitfield clearMask); | 97 void clearFramebuffers(GLbitfield clearMask); |
| 90 | 98 |
| 91 // Indicates whether the DrawingBuffer internally allocated a packed depth-s
tencil renderbuffer | 99 // Indicates whether the DrawingBuffer internally allocated a packed depth-s
tencil renderbuffer |
| 92 // in the situation where the end user only asked for a depth buffer. In thi
s case, we need to | 100 // in the situation where the end user only asked for a depth buffer. In thi
s case, we need to |
| 93 // upgrade clears of the depth buffer to clears of the depth and stencil buf
fers in order to | 101 // upgrade clears of the depth buffer to clears of the depth and stencil buf
fers in order to |
| 94 // avoid performance problems on some GPUs. | 102 // avoid performance problems on some GPUs. |
| 95 bool hasImplicitStencilBuffer() const; | 103 bool hasImplicitStencilBuffer() const { return m_hasImplicitStencilBuffer; } |
| 96 | 104 |
| 97 // Given the desired buffer size, provides the largest dimensions that will
fit in the pixel budget. | 105 // Given the desired buffer size, provides the largest dimensions that will
fit in the pixel budget. |
| 98 static IntSize adjustSize(const IntSize& desiredSize, const IntSize& curSize
, int maxTextureSize); | 106 static IntSize adjustSize(const IntSize& desiredSize, const IntSize& curSize
, int maxTextureSize); |
| 99 bool reset(const IntSize&); | 107 bool reset(const IntSize&, bool wantAlphaChannel, bool wantDepthOrStencilBuf
fer); |
| 100 void bind(GLenum target); | 108 void bind(GLenum target); |
| 101 IntSize size() const { return m_size; } | 109 IntSize size() const { return m_size; } |
| 102 | 110 |
| 103 // Copies the multisample color buffer to the normal color buffer and leaves
m_fbo bound. | 111 // Copies the multisample color buffer to the normal color buffer and leaves
m_fbo bound. |
| 104 void commit(); | 112 void commit(); |
| 105 | 113 |
| 106 // commit should copy the full multisample buffer, and not respect the | 114 // commit should copy the full multisample buffer, and not respect the |
| 107 // current scissor bounds. Track the state of the scissor test so that it | 115 // current scissor bounds. Track the state of the scissor test so that it |
| 108 // can be disabled during calls to commit. | 116 // can be disabled during calls to commit. |
| 109 void setScissorEnabled(bool scissorEnabled) { m_scissorEnabled = scissorEnab
led; } | 117 void setScissorEnabled(bool scissorEnabled) { m_scissorEnabled = scissorEnab
led; } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 bool bufferClearNeeded() const; | 155 bool bufferClearNeeded() const; |
| 148 void setIsHidden(bool); | 156 void setIsHidden(bool); |
| 149 void setFilterQuality(SkFilterQuality); | 157 void setFilterQuality(SkFilterQuality); |
| 150 | 158 |
| 151 WebLayer* platformLayer(); | 159 WebLayer* platformLayer(); |
| 152 | 160 |
| 153 WebGraphicsContext3D* context(); | 161 WebGraphicsContext3D* context(); |
| 154 gpu::gles2::GLES2Interface* contextGL(); | 162 gpu::gles2::GLES2Interface* contextGL(); |
| 155 WebGraphicsContext3DProvider* contextProvider(); | 163 WebGraphicsContext3DProvider* contextProvider(); |
| 156 | 164 |
| 157 // Returns the actual context attributes for this drawing buffer which may d
iffer from the | 165 bool hasDepthBuffer() const { return m_hasDepthBuffer; } |
| 158 // requested context attributes due to implementation limits. | 166 bool hasStencilBuffer() const { return m_hasStencilBuffer; } |
| 159 WebGraphicsContext3D::Attributes getActualAttributes() const { return m_actu
alAttributes; } | |
| 160 | 167 |
| 161 // WebExternalTextureLayerClient implementation. | 168 // WebExternalTextureLayerClient implementation. |
| 162 bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*) override
; | 169 bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*) override
; |
| 163 void mailboxReleased(const WebExternalTextureMailbox&, bool lostResource = f
alse) override; | 170 void mailboxReleased(const WebExternalTextureMailbox&, bool lostResource = f
alse) override; |
| 164 | 171 |
| 165 // Destroys the TEXTURE_2D binding for the owned context | 172 // Destroys the TEXTURE_2D binding for the owned context |
| 166 bool copyToPlatformTexture(WebGraphicsContext3D*, gpu::gles2::GLES2Interface
*, GLuint texture, GLenum internalFormat, | 173 bool copyToPlatformTexture(WebGraphicsContext3D*, gpu::gles2::GLES2Interface
*, GLuint texture, GLenum internalFormat, |
| 167 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceD
rawingBuffer); | 174 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceD
rawingBuffer); |
| 168 | 175 |
| 169 void setPackAlignment(GLint param); | 176 void setPackAlignment(GLint param); |
| 170 | 177 |
| 171 bool paintRenderingResultsToImageData(int&, int&, SourceDrawingBuffer, WTF::
ArrayBufferContents&); | 178 bool paintRenderingResultsToImageData(int&, int&, SourceDrawingBuffer, WTF::
ArrayBufferContents&); |
| 172 | 179 |
| 173 int sampleCount() const { return m_sampleCount; } | 180 int sampleCount() const { return m_sampleCount; } |
| 174 bool explicitResolveOfMultisampleData() const { return m_antiAliasingMode ==
MSAAExplicitResolve; } | 181 bool explicitResolveOfMultisampleData() const { return m_antiAliasingMode ==
MSAAExplicitResolve; } |
| 175 | 182 |
| 176 // Bind to m_drawFramebufferBinding or m_readFramebufferBinding if it's not
0. | 183 // Bind to m_drawFramebufferBinding or m_readFramebufferBinding if it's not
0. |
| 177 // Otherwise, bind to the default FBO. | 184 // Otherwise, bind to the default FBO. |
| 178 void restoreFramebufferBindings(); | 185 void restoreFramebufferBindings(); |
| 179 | 186 |
| 180 void addNewMailboxCallback(PassOwnPtr<SameThreadClosure> closure) { m_newMai
lboxCallback = std::move(closure); } | 187 void addNewMailboxCallback(PassOwnPtr<SameThreadClosure> closure) { m_newMai
lboxCallback = std::move(closure); } |
| 181 | 188 |
| 182 protected: // For unittests | 189 protected: // For unittests |
| 183 DrawingBuffer( | 190 DrawingBuffer( |
| 184 PassOwnPtr<WebGraphicsContext3DProvider>, | 191 PassOwnPtr<WebGraphicsContext3DProvider>, |
| 185 PassOwnPtr<Extensions3DUtil>, | 192 PassOwnPtr<Extensions3DUtil>, |
| 186 bool multisampleExtensionSupported, | |
| 187 bool discardFramebufferSupported, | 193 bool discardFramebufferSupported, |
| 188 bool premultipliedAlpha, | 194 bool premultipliedAlpha, |
| 189 PreserveDrawingBuffer, | 195 PreserveDrawingBuffer); |
| 190 WebGraphicsContext3D::Attributes requestedAttributes); | |
| 191 | 196 |
| 192 bool initialize(const IntSize&); | 197 bool initialize(const IntSize&, bool wantAlphaChannel, bool wantDepthBuffer,
bool wantStencilBuffer, bool multisampleExtensionSupported); |
| 193 | 198 |
| 194 private: | 199 private: |
| 195 struct TextureParameters { | 200 struct TextureParameters { |
| 196 DISALLOW_NEW(); | 201 DISALLOW_NEW(); |
| 197 GLenum target; | 202 GLenum target; |
| 198 GLenum internalColorFormat; | 203 GLenum internalColorFormat; |
| 199 GLenum colorFormat; | 204 GLenum colorFormat; |
| 200 GLenum internalRenderbufferFormat; | 205 GLenum internalRenderbufferFormat; |
| 201 | 206 |
| 202 TextureParameters() | 207 TextureParameters() |
| (...skipping 30 matching lines...) Expand all Loading... |
| 233 TextureInfo textureInfo; | 238 TextureInfo textureInfo; |
| 234 IntSize size; | 239 IntSize size; |
| 235 // This keeps the parent drawing buffer alive as long as the compositor
is | 240 // This keeps the parent drawing buffer alive as long as the compositor
is |
| 236 // referring to one of the mailboxes DrawingBuffer produced. The parent
drawing buffer is | 241 // referring to one of the mailboxes DrawingBuffer produced. The parent
drawing buffer is |
| 237 // cleared when the compositor returns the mailbox. See mailboxReleased(
). | 242 // cleared when the compositor returns the mailbox. See mailboxReleased(
). |
| 238 RefPtr<DrawingBuffer> m_parentDrawingBuffer; | 243 RefPtr<DrawingBuffer> m_parentDrawingBuffer; |
| 239 }; | 244 }; |
| 240 | 245 |
| 241 // The texture parameters to use for a texture that will be backed by a | 246 // The texture parameters to use for a texture that will be backed by a |
| 242 // CHROMIUM_image. | 247 // CHROMIUM_image. |
| 243 TextureParameters chromiumImageTextureParameters(); | 248 TextureParameters chromiumImageTextureParameters(bool wantAlphaChannel); |
| 244 | 249 |
| 245 // The texture parameters to use for a default texture. | 250 // The texture parameters to use for a default texture. |
| 246 TextureParameters defaultTextureParameters(); | 251 TextureParameters defaultTextureParameters(bool wantAlphaChannel); |
| 247 | 252 |
| 248 void mailboxReleasedWithoutRecycling(const WebExternalTextureMailbox&); | 253 void mailboxReleasedWithoutRecycling(const WebExternalTextureMailbox&); |
| 249 | 254 |
| 250 // Creates and binds a texture with the given parameters. Returns 0 on | 255 // Creates and binds a texture with the given parameters. Returns 0 on |
| 251 // failure, or the newly created texture id on success. The caller takes | 256 // failure, or the newly created texture id on success. The caller takes |
| 252 // ownership of the newly created texture. | 257 // ownership of the newly created texture. |
| 253 GLuint createColorTexture(const TextureParameters&); | 258 GLuint createColorTexture(const TextureParameters&); |
| 254 | 259 |
| 255 // Create the depth/stencil and multisample buffers, if needed. | 260 // Create the depth/stencil and multisample buffers, if needed. |
| 256 void createSecondaryBuffers(); | 261 void createSecondaryBuffers(); |
| 257 bool resizeFramebuffer(const IntSize&); | 262 bool resizeFramebuffer(const IntSize&, bool wantDepthOrStencilBuffer); |
| 258 bool resizeMultisampleFramebuffer(const IntSize&); | 263 bool resizeMultisampleFramebuffer(const IntSize&, bool wantDepthOrStencilBuf
fer); |
| 259 void resizeDepthStencil(const IntSize&); | 264 void resizeDepthStencil(const IntSize&); |
| 260 | 265 |
| 261 void clearPlatformLayer(); | 266 void clearPlatformLayer(); |
| 262 | 267 |
| 263 PassRefPtr<MailboxInfo> recycledMailbox(); | 268 PassRefPtr<MailboxInfo> recycledMailbox(); |
| 264 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&); | 269 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&); |
| 265 void deleteMailbox(const WebExternalTextureMailbox&); | 270 void deleteMailbox(const WebExternalTextureMailbox&); |
| 266 void freeRecycledMailboxes(); | 271 void freeRecycledMailboxes(); |
| 267 | 272 |
| 268 // Updates the current size of the buffer, ensuring that s_currentResourceUs
ePixels is updated. | 273 // Updates the current size of the buffer, ensuring that s_currentResourceUs
ePixels is updated. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 283 | 288 |
| 284 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0. | 289 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0. |
| 285 // By default, alignment is 4, the OpenGL default setting. | 290 // By default, alignment is 4, the OpenGL default setting. |
| 286 void texImage2DResourceSafe(GLenum target, GLint level, GLenum internalforma
t, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLin
t alignment = 4); | 291 void texImage2DResourceSafe(GLenum target, GLint level, GLenum internalforma
t, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLin
t alignment = 4); |
| 287 // Allocate buffer storage to be sent to compositor using either texImage2D
or CHROMIUM_image based on available support. | 292 // Allocate buffer storage to be sent to compositor using either texImage2D
or CHROMIUM_image based on available support. |
| 288 void deleteChromiumImageForTexture(TextureInfo*); | 293 void deleteChromiumImageForTexture(TextureInfo*); |
| 289 | 294 |
| 290 // Tries to create a CHROMIUM_image backed texture if | 295 // Tries to create a CHROMIUM_image backed texture if |
| 291 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() is true. On failure, | 296 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() is true. On failure, |
| 292 // or if the flag is false, creates a default texture. | 297 // or if the flag is false, creates a default texture. |
| 293 TextureInfo createTextureAndAllocateMemory(const IntSize&); | 298 TextureInfo createTextureAndAllocateMemory(const IntSize&, bool wantAlphaCha
nnel); |
| 294 | 299 |
| 295 // Creates and allocates space for a default texture. | 300 // Creates and allocates space for a default texture. |
| 296 TextureInfo createDefaultTextureAndAllocateMemory(const IntSize&); | 301 TextureInfo createDefaultTextureAndAllocateMemory(const IntSize&, bool wantA
lphaChannel); |
| 297 | 302 |
| 298 void resizeTextureMemory(TextureInfo*, const IntSize&); | 303 void resizeTextureMemory(TextureInfo*, const IntSize&); |
| 299 | 304 |
| 300 void attachColorBufferToCurrentFBO(); | 305 void attachColorBufferToCurrentFBO(); |
| 301 | 306 |
| 302 PreserveDrawingBuffer m_preserveDrawingBuffer; | 307 PreserveDrawingBuffer m_preserveDrawingBuffer; |
| 303 bool m_scissorEnabled; | 308 bool m_scissorEnabled; |
| 304 GLuint m_texture2DBinding; | 309 GLuint m_texture2DBinding; |
| 305 GLuint m_drawFramebufferBinding; | 310 GLuint m_drawFramebufferBinding; |
| 306 GLuint m_readFramebufferBinding; | 311 GLuint m_readFramebufferBinding; |
| 307 GLenum m_activeTextureUnit; | 312 GLenum m_activeTextureUnit; |
| 308 | 313 |
| 309 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; | 314 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; |
| 310 WebGraphicsContext3D* m_context; // Lifetime is tied to the m_contextProvide
r. | 315 WebGraphicsContext3D* m_context; // Lifetime is tied to the m_contextProvide
r. |
| 311 gpu::gles2::GLES2Interface* m_gl; // Lifetime is tied to the m_contextProvid
er. | 316 gpu::gles2::GLES2Interface* m_gl; // Lifetime is tied to the m_contextProvid
er. |
| 312 OwnPtr<Extensions3DUtil> m_extensionsUtil; | 317 OwnPtr<Extensions3DUtil> m_extensionsUtil; |
| 313 IntSize m_size; | 318 IntSize m_size; |
| 314 WebGraphicsContext3D::Attributes m_requestedAttributes; | 319 WebGraphicsContext3D::Attributes m_attributes; |
| 315 bool m_multisampleExtensionSupported; | |
| 316 bool m_discardFramebufferSupported; | 320 bool m_discardFramebufferSupported; |
| 317 bool m_premultipliedAlpha; | 321 bool m_premultipliedAlpha; |
| 322 bool m_hasAlphaChannel; |
| 323 bool m_hasDepthBuffer; |
| 324 bool m_hasStencilBuffer; |
| 325 bool m_hasImplicitStencilBuffer; |
| 318 GLuint m_fbo; | 326 GLuint m_fbo; |
| 319 // DrawingBuffer's output is double-buffered. m_colorBuffer is the back buff
er. | 327 // DrawingBuffer's output is double-buffered. m_colorBuffer is the back buff
er. |
| 320 TextureInfo m_colorBuffer; | 328 TextureInfo m_colorBuffer; |
| 321 struct FrontBufferInfo { | 329 struct FrontBufferInfo { |
| 322 TextureInfo texInfo; | 330 TextureInfo texInfo; |
| 323 WebExternalTextureMailbox mailbox; | 331 WebExternalTextureMailbox mailbox; |
| 324 }; | 332 }; |
| 325 FrontBufferInfo m_frontColorBuffer; | 333 FrontBufferInfo m_frontColorBuffer; |
| 326 | 334 |
| 327 OwnPtr<SameThreadClosure> m_newMailboxCallback; | 335 OwnPtr<SameThreadClosure> m_newMailboxCallback; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 342 | 350 |
| 343 enum AntialiasingMode { | 351 enum AntialiasingMode { |
| 344 None, | 352 None, |
| 345 MSAAImplicitResolve, | 353 MSAAImplicitResolve, |
| 346 MSAAExplicitResolve, | 354 MSAAExplicitResolve, |
| 347 ScreenSpaceAntialiasing, | 355 ScreenSpaceAntialiasing, |
| 348 }; | 356 }; |
| 349 | 357 |
| 350 AntialiasingMode m_antiAliasingMode; | 358 AntialiasingMode m_antiAliasingMode; |
| 351 | 359 |
| 352 WebGraphicsContext3D::Attributes m_actualAttributes; | |
| 353 int m_maxTextureSize; | 360 int m_maxTextureSize; |
| 354 int m_sampleCount; | 361 int m_sampleCount; |
| 355 int m_packAlignment; | 362 int m_packAlignment; |
| 356 bool m_destructionInProgress; | 363 bool m_destructionInProgress; |
| 357 bool m_isHidden; | 364 bool m_isHidden; |
| 358 SkFilterQuality m_filterQuality; | 365 SkFilterQuality m_filterQuality; |
| 359 | 366 |
| 360 OwnPtr<WebExternalTextureLayer> m_layer; | 367 OwnPtr<WebExternalTextureLayer> m_layer; |
| 361 | 368 |
| 362 // All of the mailboxes that this DrawingBuffer has ever created. | 369 // All of the mailboxes that this DrawingBuffer has ever created. |
| 363 Vector<RefPtr<MailboxInfo>> m_textureMailboxes; | 370 Vector<RefPtr<MailboxInfo>> m_textureMailboxes; |
| 364 // Mailboxes that were released by the compositor can be used again by this
DrawingBuffer. | 371 // Mailboxes that were released by the compositor can be used again by this
DrawingBuffer. |
| 365 Deque<WebExternalTextureMailbox> m_recycledMailboxQueue; | 372 Deque<WebExternalTextureMailbox> m_recycledMailboxQueue; |
| 366 | 373 |
| 367 // If the width and height of the Canvas's backing store don't | 374 // If the width and height of the Canvas's backing store don't |
| 368 // match those that we were given in the most recent call to | 375 // match those that we were given in the most recent call to |
| 369 // reshape(), then we need an intermediate bitmap to read back the | 376 // reshape(), then we need an intermediate bitmap to read back the |
| 370 // frame buffer into. This seems to happen when CSS styles are | 377 // frame buffer into. This seems to happen when CSS styles are |
| 371 // used to resize the Canvas. | 378 // used to resize the Canvas. |
| 372 SkBitmap m_resizingBitmap; | 379 SkBitmap m_resizingBitmap; |
| 373 | 380 |
| 374 // Used to flip a bitmap vertically. | 381 // Used to flip a bitmap vertically. |
| 375 Vector<uint8_t> m_scanline; | 382 Vector<uint8_t> m_scanline; |
| 376 }; | 383 }; |
| 377 | 384 |
| 378 } // namespace blink | 385 } // namespace blink |
| 379 | 386 |
| 380 #endif // DrawingBuffer_h | 387 #endif // DrawingBuffer_h |
| OLD | NEW |