| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 namespace blink { | 63 namespace blink { |
| 64 class Extensions3DUtil; | 64 class Extensions3DUtil; |
| 65 class ImageBuffer; | 65 class ImageBuffer; |
| 66 class StaticBitmapImage; | 66 class StaticBitmapImage; |
| 67 class WebExternalBitmap; | 67 class WebExternalBitmap; |
| 68 class WebExternalTextureLayer; | 68 class WebExternalTextureLayer; |
| 69 class WebGraphicsContext3DProvider; | 69 class WebGraphicsContext3DProvider; |
| 70 class WebLayer; | 70 class WebLayer; |
| 71 | 71 |
| 72 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ
ish its rendering | 72 // Manages a rendering target (framebuffer + attachment) for a canvas. Can |
| 73 // results to a WebLayer for compositing. | 73 // publish its rendering results to a WebLayer for compositing. |
| 74 class PLATFORM_EXPORT DrawingBuffer | 74 class PLATFORM_EXPORT DrawingBuffer |
| 75 : public NON_EXPORTED_BASE(cc::TextureLayerClient), | 75 : public NON_EXPORTED_BASE(cc::TextureLayerClient), |
| 76 public RefCounted<DrawingBuffer> { | 76 public RefCounted<DrawingBuffer> { |
| 77 WTF_MAKE_NONCOPYABLE(DrawingBuffer); | 77 WTF_MAKE_NONCOPYABLE(DrawingBuffer); |
| 78 | 78 |
| 79 public: | 79 public: |
| 80 enum PreserveDrawingBuffer { | 80 enum PreserveDrawingBuffer { |
| 81 Preserve, | 81 Preserve, |
| 82 Discard, | 82 Discard, |
| 83 }; | 83 }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 102 PreserveDrawingBuffer, | 102 PreserveDrawingBuffer, |
| 103 WebGLVersion, | 103 WebGLVersion, |
| 104 ChromiumImageUsage); | 104 ChromiumImageUsage); |
| 105 static void forceNextDrawingBufferCreationToFail(); | 105 static void forceNextDrawingBufferCreationToFail(); |
| 106 | 106 |
| 107 ~DrawingBuffer() override; | 107 ~DrawingBuffer() override; |
| 108 | 108 |
| 109 // Destruction will be completed after all mailboxes are released. | 109 // Destruction will be completed after all mailboxes are released. |
| 110 void beginDestruction(); | 110 void beginDestruction(); |
| 111 | 111 |
| 112 // Issues a glClear() on all framebuffers associated with this DrawingBuffer.
The caller is responsible for | 112 // Issues a glClear() on all framebuffers associated with this DrawingBuffer. |
| 113 // making the context current and setting the clear values and masks. Modifies
the framebuffer binding. | 113 // The caller is responsible for making the context current and setting the |
| 114 // clear values and masks. Modifies the framebuffer binding. |
| 114 void clearFramebuffers(GLbitfield clearMask); | 115 void clearFramebuffers(GLbitfield clearMask); |
| 115 | 116 |
| 116 // Indicates whether the DrawingBuffer internally allocated a packed depth-ste
ncil renderbuffer | 117 // Indicates whether the DrawingBuffer internally allocated a packed |
| 117 // in the situation where the end user only asked for a depth buffer. In this
case, we need to | 118 // depth-stencil renderbuffer in the situation where the end user only asked |
| 118 // upgrade clears of the depth buffer to clears of the depth and stencil buffe
rs in order to | 119 // for a depth buffer. In this case, we need to upgrade clears of the depth |
| 119 // avoid performance problems on some GPUs. | 120 // buffer to clears of the depth and stencil buffers in order to avoid |
| 121 // performance problems on some GPUs. |
| 120 bool hasImplicitStencilBuffer() const { return m_hasImplicitStencilBuffer; } | 122 bool hasImplicitStencilBuffer() const { return m_hasImplicitStencilBuffer; } |
| 121 bool hasDepthBuffer() const { return !!m_depthStencilBuffer; } | 123 bool hasDepthBuffer() const { return !!m_depthStencilBuffer; } |
| 122 bool hasStencilBuffer() const { return !!m_depthStencilBuffer; } | 124 bool hasStencilBuffer() const { return !!m_depthStencilBuffer; } |
| 123 | 125 |
| 124 // Given the desired buffer size, provides the largest dimensions that will fi
t in the pixel budget. | 126 // Given the desired buffer size, provides the largest dimensions that will |
| 127 // fit in the pixel budget. |
| 125 static IntSize adjustSize(const IntSize& desiredSize, | 128 static IntSize adjustSize(const IntSize& desiredSize, |
| 126 const IntSize& curSize, | 129 const IntSize& curSize, |
| 127 int maxTextureSize); | 130 int maxTextureSize); |
| 128 | 131 |
| 129 // Resizes (or allocates if necessary) all buffers attached to the default | 132 // Resizes (or allocates if necessary) all buffers attached to the default |
| 130 // framebuffer. Returns whether the operation was successful. Leaves GL | 133 // framebuffer. Returns whether the operation was successful. Leaves GL |
| 131 // bindings dirtied. | 134 // bindings dirtied. |
| 132 bool reset(const IntSize&); | 135 bool reset(const IntSize&); |
| 133 | 136 |
| 134 // Bind the default framebuffer to |target|. |target| must be | 137 // Bind the default framebuffer to |target|. |target| must be |
| 135 // GL_FRAMEBUFFER, GL_READ_FRAMEBUFFER, or GL_DRAW_FRAMEBUFFER. | 138 // GL_FRAMEBUFFER, GL_READ_FRAMEBUFFER, or GL_DRAW_FRAMEBUFFER. |
| 136 void bind(GLenum target); | 139 void bind(GLenum target); |
| 137 IntSize size() const { return m_size; } | 140 IntSize size() const { return m_size; } |
| 138 | 141 |
| 139 // Copies the multisample color buffer to the normal color buffer and leaves m
_fbo bound. | 142 // Copies the multisample color buffer to the normal color buffer and leaves |
| 143 // m_fbo bound. |
| 140 void commit(); | 144 void commit(); |
| 141 | 145 |
| 142 // commit should copy the full multisample buffer, and not respect the | 146 // commit should copy the full multisample buffer, and not respect the |
| 143 // current scissor bounds. Track the state of the scissor test so that it | 147 // current scissor bounds. Track the state of the scissor test so that it |
| 144 // can be disabled during calls to commit. | 148 // can be disabled during calls to commit. |
| 145 void setScissorEnabled(bool scissorEnabled) { | 149 void setScissorEnabled(bool scissorEnabled) { |
| 146 m_scissorEnabled = scissorEnabled; | 150 m_scissorEnabled = scissorEnabled; |
| 147 } | 151 } |
| 148 | 152 |
| 149 // The DrawingBuffer needs to track the texture bound to texture unit 0. | 153 // The DrawingBuffer needs to track the texture bound to texture unit 0. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 void setColorMask(GLboolean* colorMask) { | 193 void setColorMask(GLboolean* colorMask) { |
| 190 memcpy(m_colorMask, colorMask, 4 * sizeof(GLboolean)); | 194 memcpy(m_colorMask, colorMask, 4 * sizeof(GLboolean)); |
| 191 } | 195 } |
| 192 | 196 |
| 193 // The DrawingBuffer needs to track the currently bound renderbuffer so it | 197 // The DrawingBuffer needs to track the currently bound renderbuffer so it |
| 194 // restore the binding when needed. | 198 // restore the binding when needed. |
| 195 void setRenderbufferBinding(GLuint renderbuffer) { | 199 void setRenderbufferBinding(GLuint renderbuffer) { |
| 196 m_renderbufferBinding = renderbuffer; | 200 m_renderbufferBinding = renderbuffer; |
| 197 } | 201 } |
| 198 | 202 |
| 199 // Track the currently active texture unit. Texture unit 0 is used as host for
a scratch | 203 // Track the currently active texture unit. Texture unit 0 is used as host for |
| 200 // texture. | 204 // a scratch texture. |
| 201 void setActiveTextureUnit(GLint textureUnit) { | 205 void setActiveTextureUnit(GLint textureUnit) { |
| 202 m_activeTextureUnit = textureUnit; | 206 m_activeTextureUnit = textureUnit; |
| 203 } | 207 } |
| 204 | 208 |
| 205 bool multisample() const; | 209 bool multisample() const; |
| 206 | 210 |
| 207 GLuint framebuffer() const; | 211 GLuint framebuffer() const; |
| 208 | 212 |
| 209 bool discardFramebufferSupported() const { | 213 bool discardFramebufferSupported() const { |
| 210 return m_discardFramebufferSupported; | 214 return m_discardFramebufferSupported; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 229 WebLayer* platformLayer(); | 233 WebLayer* platformLayer(); |
| 230 | 234 |
| 231 gpu::gles2::GLES2Interface* contextGL(); | 235 gpu::gles2::GLES2Interface* contextGL(); |
| 232 WebGraphicsContext3DProvider* contextProvider(); | 236 WebGraphicsContext3DProvider* contextProvider(); |
| 233 | 237 |
| 234 // cc::TextureLayerClient implementation. | 238 // cc::TextureLayerClient implementation. |
| 235 bool PrepareTextureMailbox( | 239 bool PrepareTextureMailbox( |
| 236 cc::TextureMailbox* outMailbox, | 240 cc::TextureMailbox* outMailbox, |
| 237 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback) override; | 241 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback) override; |
| 238 | 242 |
| 239 // Returns a StaticBitmapImage backed by a texture containing the/ current con
tents of | 243 // Returns a StaticBitmapImage backed by a texture containing the current |
| 240 // the front buffer. This is done without any pixel copies. The texture in the
ImageBitmap | 244 // contents of the front buffer. This is done without any pixel copies. The |
| 241 // is from the active ContextProvider on the DrawingBuffer. | 245 // texture in the ImageBitmap is from the active ContextProvider on the |
| 246 // DrawingBuffer. |
| 242 PassRefPtr<StaticBitmapImage> transferToStaticBitmapImage(); | 247 PassRefPtr<StaticBitmapImage> transferToStaticBitmapImage(); |
| 243 | 248 |
| 244 // Destroys the TEXTURE_2D binding for the owned context | 249 // Destroys the TEXTURE_2D binding for the owned context |
| 245 bool copyToPlatformTexture(gpu::gles2::GLES2Interface*, | 250 bool copyToPlatformTexture(gpu::gles2::GLES2Interface*, |
| 246 GLuint texture, | 251 GLuint texture, |
| 247 GLenum internalFormat, | 252 GLenum internalFormat, |
| 248 GLenum destType, | 253 GLenum destType, |
| 249 GLint level, | 254 GLint level, |
| 250 bool premultiplyAlpha, | 255 bool premultiplyAlpha, |
| 251 bool flipY, | 256 bool flipY, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 282 bool wantAlphaChannel, | 287 bool wantAlphaChannel, |
| 283 bool premultipliedAlpha, | 288 bool premultipliedAlpha, |
| 284 PreserveDrawingBuffer, | 289 PreserveDrawingBuffer, |
| 285 WebGLVersion, | 290 WebGLVersion, |
| 286 bool wantsDepth, | 291 bool wantsDepth, |
| 287 bool wantsStencil, | 292 bool wantsStencil, |
| 288 ChromiumImageUsage); | 293 ChromiumImageUsage); |
| 289 | 294 |
| 290 bool initialize(const IntSize&, bool useMultisampling); | 295 bool initialize(const IntSize&, bool useMultisampling); |
| 291 | 296 |
| 292 // Shared memory bitmaps that were released by the compositor and can be used
again by this DrawingBuffer. | 297 // Shared memory bitmaps that were released by the compositor and can be used |
| 298 // again by this DrawingBuffer. |
| 293 struct RecycledBitmap { | 299 struct RecycledBitmap { |
| 294 std::unique_ptr<cc::SharedBitmap> bitmap; | 300 std::unique_ptr<cc::SharedBitmap> bitmap; |
| 295 IntSize size; | 301 IntSize size; |
| 296 }; | 302 }; |
| 297 Vector<RecycledBitmap> m_recycledBitmaps; | 303 Vector<RecycledBitmap> m_recycledBitmaps; |
| 298 | 304 |
| 299 private: | 305 private: |
| 300 // All parameters necessary to generate the texture that will be passed to | 306 // All parameters necessary to generate the texture that will be passed to |
| 301 // prepareMailbox. | 307 // prepareMailbox. |
| 302 struct TextureParameters { | 308 struct TextureParameters { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 373 |
| 368 void clearPlatformLayer(); | 374 void clearPlatformLayer(); |
| 369 | 375 |
| 370 PassRefPtr<MailboxInfo> takeRecycledMailbox(); | 376 PassRefPtr<MailboxInfo> takeRecycledMailbox(); |
| 371 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&); | 377 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&); |
| 372 void deleteMailbox(const gpu::Mailbox&, const gpu::SyncToken&); | 378 void deleteMailbox(const gpu::Mailbox&, const gpu::SyncToken&); |
| 373 void freeRecycledMailboxes(); | 379 void freeRecycledMailboxes(); |
| 374 | 380 |
| 375 std::unique_ptr<cc::SharedBitmap> createOrRecycleBitmap(); | 381 std::unique_ptr<cc::SharedBitmap> createOrRecycleBitmap(); |
| 376 | 382 |
| 377 // Updates the current size of the buffer, ensuring that s_currentResourceUseP
ixels is updated. | 383 // Updates the current size of the buffer, ensuring that |
| 384 // s_currentResourceUsePixels is updated. |
| 378 void setSize(const IntSize& size); | 385 void setSize(const IntSize& size); |
| 379 | 386 |
| 380 // This is the order of bytes to use when doing a readback. | 387 // This is the order of bytes to use when doing a readback. |
| 381 enum ReadbackOrder { ReadbackRGBA, ReadbackSkia }; | 388 enum ReadbackOrder { ReadbackRGBA, ReadbackSkia }; |
| 382 | 389 |
| 383 // Helper function which does a readback from the currently-bound | 390 // Helper function which does a readback from the currently-bound |
| 384 // framebuffer into a buffer of a certain size with 4-byte pixels. | 391 // framebuffer into a buffer of a certain size with 4-byte pixels. |
| 385 void readBackFramebuffer(unsigned char* pixels, | 392 void readBackFramebuffer(unsigned char* pixels, |
| 386 int width, | 393 int width, |
| 387 int height, | 394 int height, |
| 388 ReadbackOrder, | 395 ReadbackOrder, |
| 389 WebGLImageConversion::AlphaOp); | 396 WebGLImageConversion::AlphaOp); |
| 390 | 397 |
| 391 // Helper function to flip a bitmap vertically. | 398 // Helper function to flip a bitmap vertically. |
| 392 void flipVertically(uint8_t* data, int width, int height); | 399 void flipVertically(uint8_t* data, int width, int height); |
| 393 | 400 |
| 394 // Allocate a storage texture if possible. Otherwise, allocate a regular textu
re. | 401 // Allocate a storage texture if possible. Otherwise, allocate a regular |
| 402 // texture. |
| 395 void allocateConditionallyImmutableTexture(GLenum target, | 403 void allocateConditionallyImmutableTexture(GLenum target, |
| 396 GLenum internalformat, | 404 GLenum internalformat, |
| 397 GLsizei width, | 405 GLsizei width, |
| 398 GLsizei height, | 406 GLsizei height, |
| 399 GLint border, | 407 GLint border, |
| 400 GLenum format, | 408 GLenum format, |
| 401 GLenum type); | 409 GLenum type); |
| 402 // Allocate buffer storage to be sent to compositor using either texImage2D or
CHROMIUM_image based on available support. | 410 // Allocate buffer storage to be sent to compositor using either texImage2D or |
| 411 // CHROMIUM_image based on available support. |
| 403 void deleteChromiumImageForTexture(TextureInfo*); | 412 void deleteChromiumImageForTexture(TextureInfo*); |
| 404 | 413 |
| 405 // If RGB emulation is required, then the CHROMIUM image's alpha channel | 414 // If RGB emulation is required, then the CHROMIUM image's alpha channel |
| 406 // must be immediately cleared after it is bound to a texture. Nothing | 415 // must be immediately cleared after it is bound to a texture. Nothing |
| 407 // should be allowed to change the alpha channel after this. | 416 // should be allowed to change the alpha channel after this. |
| 408 void clearChromiumImageAlpha(const TextureInfo&); | 417 void clearChromiumImageAlpha(const TextureInfo&); |
| 409 | 418 |
| 410 // Tries to create a CHROMIUM_image backed texture if | 419 // Tries to create a CHROMIUM_image backed texture if |
| 411 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() is true. On failure, | 420 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() is true. On failure, |
| 412 // or if the flag is false, creates a default texture. | 421 // or if the flag is false, creates a default texture. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 485 |
| 477 // When wantExplicitResolve() returns false, the target of all draw and | 486 // When wantExplicitResolve() returns false, the target of all draw and |
| 478 // read operations. When wantExplicitResolve() returns true, the target of | 487 // read operations. When wantExplicitResolve() returns true, the target of |
| 479 // all read operations. A swap is performed by exchanging |m_colorBuffer| | 488 // all read operations. A swap is performed by exchanging |m_colorBuffer| |
| 480 // with |m_frontColorBuffer|. | 489 // with |m_frontColorBuffer|. |
| 481 GLuint m_fbo = 0; | 490 GLuint m_fbo = 0; |
| 482 | 491 |
| 483 // All information about the texture storage for |m_fbo|. | 492 // All information about the texture storage for |m_fbo|. |
| 484 TextureInfo m_colorBuffer; | 493 TextureInfo m_colorBuffer; |
| 485 | 494 |
| 486 // True if our contents have been modified since the last presentation of this
buffer. | 495 // True if our contents have been modified since the last presentation of this |
| 496 // buffer. |
| 487 bool m_contentsChanged = true; | 497 bool m_contentsChanged = true; |
| 488 | 498 |
| 489 // True if commit() has been called since the last time markContentsChanged()
had been called. | 499 // True if commit() has been called since the last time markContentsChanged() |
| 500 // had been called. |
| 490 bool m_contentsChangeCommitted = false; | 501 bool m_contentsChangeCommitted = false; |
| 491 bool m_bufferClearNeeded = false; | 502 bool m_bufferClearNeeded = false; |
| 492 | 503 |
| 493 // Whether the client wants a depth or stencil buffer. | 504 // Whether the client wants a depth or stencil buffer. |
| 494 const bool m_wantDepth; | 505 const bool m_wantDepth; |
| 495 const bool m_wantStencil; | 506 const bool m_wantStencil; |
| 496 | 507 |
| 497 enum AntialiasingMode { | 508 enum AntialiasingMode { |
| 498 None, | 509 None, |
| 499 MSAAImplicitResolve, | 510 MSAAImplicitResolve, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 518 RecycledMailbox(const gpu::Mailbox& mailbox, | 529 RecycledMailbox(const gpu::Mailbox& mailbox, |
| 519 const gpu::SyncToken& syncToken) | 530 const gpu::SyncToken& syncToken) |
| 520 : mailbox(mailbox), syncToken(syncToken) {} | 531 : mailbox(mailbox), syncToken(syncToken) {} |
| 521 | 532 |
| 522 gpu::Mailbox mailbox; | 533 gpu::Mailbox mailbox; |
| 523 gpu::SyncToken syncToken; | 534 gpu::SyncToken syncToken; |
| 524 | 535 |
| 525 private: | 536 private: |
| 526 WTF_MAKE_NONCOPYABLE(RecycledMailbox); | 537 WTF_MAKE_NONCOPYABLE(RecycledMailbox); |
| 527 }; | 538 }; |
| 528 // Mailboxes that were released by the compositor can be used again by this Dr
awingBuffer. | 539 // Mailboxes that were released by the compositor can be used again by this |
| 540 // DrawingBuffer. |
| 529 Deque<RefPtr<RecycledMailbox>> m_recycledMailboxQueue; | 541 Deque<RefPtr<RecycledMailbox>> m_recycledMailboxQueue; |
| 530 | 542 |
| 531 // If the width and height of the Canvas's backing store don't | 543 // If the width and height of the Canvas's backing store don't |
| 532 // match those that we were given in the most recent call to | 544 // match those that we were given in the most recent call to |
| 533 // reshape(), then we need an intermediate bitmap to read back the | 545 // reshape(), then we need an intermediate bitmap to read back the |
| 534 // frame buffer into. This seems to happen when CSS styles are | 546 // frame buffer into. This seems to happen when CSS styles are |
| 535 // used to resize the Canvas. | 547 // used to resize the Canvas. |
| 536 SkBitmap m_resizingBitmap; | 548 SkBitmap m_resizingBitmap; |
| 537 | 549 |
| 538 // Used to flip a bitmap vertically. | 550 // Used to flip a bitmap vertically. |
| 539 Vector<uint8_t> m_scanline; | 551 Vector<uint8_t> m_scanline; |
| 540 | 552 |
| 541 // In the case of OffscreenCanvas, we do not want to enable the WebGLImageChro
mium flag, | 553 // In the case of OffscreenCanvas, we do not want to enable the |
| 542 // so we replace all the RuntimeEnabledFeatures::webGLImageChromiumEnabled() c
all with | 554 // WebGLImageChromium flag, so we replace all the |
| 543 // shouldUseChromiumImage() call, and set m_chromiumImageUsage to DisallowChro
miumImage | 555 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() call with |
| 544 // in the case of OffscreenCanvas. | 556 // shouldUseChromiumImage() calls, and set m_chromiumImageUsage to |
| 557 // DisallowChromiumImage in the case of OffscreenCanvas. |
| 545 ChromiumImageUsage m_chromiumImageUsage; | 558 ChromiumImageUsage m_chromiumImageUsage; |
| 546 bool shouldUseChromiumImage(); | 559 bool shouldUseChromiumImage(); |
| 547 }; | 560 }; |
| 548 | 561 |
| 549 } // namespace blink | 562 } // namespace blink |
| 550 | 563 |
| 551 #endif // DrawingBuffer_h | 564 #endif // DrawingBuffer_h |
| OLD | NEW |