| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef DrawingBuffer_h | 31 #ifndef DrawingBuffer_h |
| 32 #define DrawingBuffer_h | 32 #define DrawingBuffer_h |
| 33 | 33 |
| 34 #include "cc/layers/texture_layer_client.h" |
| 35 #include "gpu/command_buffer/common/mailbox.h" |
| 36 #include "gpu/command_buffer/common/sync_token.h" |
| 34 #include "platform/PlatformExport.h" | 37 #include "platform/PlatformExport.h" |
| 35 #include "platform/geometry/IntSize.h" | 38 #include "platform/geometry/IntSize.h" |
| 36 #include "platform/graphics/GraphicsTypes3D.h" | 39 #include "platform/graphics/GraphicsTypes3D.h" |
| 37 #include "platform/graphics/gpu/WebGLImageConversion.h" | 40 #include "platform/graphics/gpu/WebGLImageConversion.h" |
| 38 #include "public/platform/WebExternalTextureLayerClient.h" | |
| 39 #include "public/platform/WebExternalTextureMailbox.h" | |
| 40 #include "third_party/khronos/GLES2/gl2.h" | 41 #include "third_party/khronos/GLES2/gl2.h" |
| 41 #include "third_party/skia/include/core/SkBitmap.h" | 42 #include "third_party/skia/include/core/SkBitmap.h" |
| 42 #include "wtf/Deque.h" | 43 #include "wtf/Deque.h" |
| 43 #include "wtf/Noncopyable.h" | 44 #include "wtf/Noncopyable.h" |
| 44 #include "wtf/RefCounted.h" | 45 #include "wtf/RefCounted.h" |
| 45 #include <memory> | 46 #include <memory> |
| 46 | 47 |
| 48 namespace cc { |
| 49 class SharedBitmap; |
| 50 } |
| 51 |
| 47 namespace gpu { | 52 namespace gpu { |
| 48 namespace gles2 { | 53 namespace gles2 { |
| 49 class GLES2Interface; | 54 class GLES2Interface; |
| 50 } | 55 } |
| 51 } | 56 } |
| 52 | 57 |
| 53 namespace WTF { | 58 namespace WTF { |
| 54 class ArrayBufferContents; | 59 class ArrayBufferContents; |
| 55 } | 60 } |
| 56 | 61 |
| 57 namespace blink { | 62 namespace blink { |
| 58 | |
| 59 class Extensions3DUtil; | 63 class Extensions3DUtil; |
| 60 class ImageBuffer; | 64 class ImageBuffer; |
| 65 class StaticBitmapImage; |
| 61 class WebExternalBitmap; | 66 class WebExternalBitmap; |
| 62 class WebExternalTextureLayer; | 67 class WebExternalTextureLayer; |
| 63 class WebGraphicsContext3DProvider; | 68 class WebGraphicsContext3DProvider; |
| 64 class WebLayer; | 69 class WebLayer; |
| 65 | 70 |
| 66 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ
ish its rendering | 71 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ
ish its rendering |
| 67 // results to a WebLayer for compositing. | 72 // results to a WebLayer for compositing. |
| 68 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public W
ebExternalTextureLayerClient { | 73 class PLATFORM_EXPORT DrawingBuffer : public NON_EXPORTED_BASE(cc::TextureLayerC
lient), public RefCounted<DrawingBuffer> { |
| 69 WTF_MAKE_NONCOPYABLE(DrawingBuffer); | 74 WTF_MAKE_NONCOPYABLE(DrawingBuffer); |
| 70 public: | 75 public: |
| 71 enum PreserveDrawingBuffer { | 76 enum PreserveDrawingBuffer { |
| 72 Preserve, | 77 Preserve, |
| 73 Discard | 78 Discard |
| 74 }; | 79 }; |
| 75 enum WebGLVersion { | 80 enum WebGLVersion { |
| 76 WebGL1, | 81 WebGL1, |
| 77 WebGL2, | 82 WebGL2, |
| 78 }; | 83 }; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 199 |
| 195 // Similar to requiresAlphaChannelToBePreserved(), but always targets the | 200 // Similar to requiresAlphaChannelToBePreserved(), but always targets the |
| 196 // default framebuffer. | 201 // default framebuffer. |
| 197 bool defaultBufferRequiresAlphaChannelToBePreserved(); | 202 bool defaultBufferRequiresAlphaChannelToBePreserved(); |
| 198 | 203 |
| 199 WebLayer* platformLayer(); | 204 WebLayer* platformLayer(); |
| 200 | 205 |
| 201 gpu::gles2::GLES2Interface* contextGL(); | 206 gpu::gles2::GLES2Interface* contextGL(); |
| 202 WebGraphicsContext3DProvider* contextProvider(); | 207 WebGraphicsContext3DProvider* contextProvider(); |
| 203 | 208 |
| 204 // WebExternalTextureLayerClient implementation. | 209 // cc::TextureLayerClient implementation. |
| 205 bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*) override
; | 210 bool PrepareTextureMailbox( |
| 206 void mailboxReleased(const WebExternalTextureMailbox&, bool lostResource = f
alse) override; | 211 cc::TextureMailbox* outMailbox, |
| 212 std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback, |
| 213 bool useSharedMemory) override; |
| 214 |
| 215 // Callbacks for mailboxes given to the compositor from PrepareTextureMailbo
x. |
| 216 void gpuMailboxReleased(const gpu::Mailbox&, const gpu::SyncToken&, bool los
tResource); |
| 217 void softwareMailboxReleased(std::unique_ptr<cc::SharedBitmap>, const IntSiz
e&, const gpu::SyncToken&, bool lostResource); |
| 218 |
| 219 // Returns a StaticBitmapImage backed by a texture containing the/ current c
ontents of |
| 220 // the front buffer. This is done without any pixel copies. The texture in t
he ImageBitmap |
| 221 // is from the active ContextProvider on the DrawingBuffer. |
| 222 PassRefPtr<StaticBitmapImage> transferToStaticBitmapImage(); |
| 207 | 223 |
| 208 // Destroys the TEXTURE_2D binding for the owned context | 224 // Destroys the TEXTURE_2D binding for the owned context |
| 209 bool copyToPlatformTexture(gpu::gles2::GLES2Interface*, GLuint texture, GLen
um internalFormat, | 225 bool copyToPlatformTexture(gpu::gles2::GLES2Interface*, GLuint texture, GLen
um internalFormat, |
| 210 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceD
rawingBuffer); | 226 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceD
rawingBuffer); |
| 211 | 227 |
| 212 void setPackAlignment(GLint param); | 228 void setPackAlignment(GLint param); |
| 213 | 229 |
| 214 bool paintRenderingResultsToImageData(int&, int&, SourceDrawingBuffer, WTF::
ArrayBufferContents&); | 230 bool paintRenderingResultsToImageData(int&, int&, SourceDrawingBuffer, WTF::
ArrayBufferContents&); |
| 215 | 231 |
| 216 int sampleCount() const { return m_sampleCount; } | 232 int sampleCount() const { return m_sampleCount; } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 // we need to know the mapping from texture id to image. | 273 // we need to know the mapping from texture id to image. |
| 258 struct TextureInfo { | 274 struct TextureInfo { |
| 259 DISALLOW_NEW(); | 275 DISALLOW_NEW(); |
| 260 GLuint textureId = 0; | 276 GLuint textureId = 0; |
| 261 GLuint imageId = 0; | 277 GLuint imageId = 0; |
| 262 bool immutable = false; | 278 bool immutable = false; |
| 263 TextureParameters parameters; | 279 TextureParameters parameters; |
| 264 }; | 280 }; |
| 265 | 281 |
| 266 struct MailboxInfo : public RefCounted<MailboxInfo> { | 282 struct MailboxInfo : public RefCounted<MailboxInfo> { |
| 267 WTF_MAKE_NONCOPYABLE(MailboxInfo); | 283 MailboxInfo() = default; |
| 268 | 284 gpu::Mailbox mailbox; |
| 269 public: | |
| 270 MailboxInfo() {} | |
| 271 | |
| 272 WebExternalTextureMailbox mailbox; | |
| 273 TextureInfo textureInfo; | 285 TextureInfo textureInfo; |
| 274 IntSize size; | 286 IntSize size; |
| 275 // This keeps the parent drawing buffer alive as long as the compositor
is | 287 |
| 276 // referring to one of the mailboxes DrawingBuffer produced. The parent
drawing buffer is | 288 private: |
| 277 // cleared when the compositor returns the mailbox. See mailboxReleased(
). | 289 WTF_MAKE_NONCOPYABLE(MailboxInfo); |
| 278 RefPtr<DrawingBuffer> m_parentDrawingBuffer; | |
| 279 }; | 290 }; |
| 280 | 291 |
| 281 // The texture parameters to use for a texture that will be backed by a | 292 // The texture parameters to use for a texture that will be backed by a |
| 282 // CHROMIUM_image. | 293 // CHROMIUM_image. |
| 283 TextureParameters chromiumImageTextureParameters(); | 294 TextureParameters chromiumImageTextureParameters(); |
| 284 | 295 |
| 285 // The texture parameters to use for a default texture. | 296 // The texture parameters to use for a default texture. |
| 286 TextureParameters defaultTextureParameters(); | 297 TextureParameters defaultTextureParameters(); |
| 287 | 298 |
| 288 void mailboxReleasedWithoutRecycling(const WebExternalTextureMailbox&); | |
| 289 | |
| 290 // Creates and binds a texture with the given parameters. Returns 0 on | 299 // Creates and binds a texture with the given parameters. Returns 0 on |
| 291 // failure, or the newly created texture id on success. The caller takes | 300 // failure, or the newly created texture id on success. The caller takes |
| 292 // ownership of the newly created texture. | 301 // ownership of the newly created texture. |
| 293 GLuint createColorTexture(const TextureParameters&); | 302 GLuint createColorTexture(const TextureParameters&); |
| 294 | 303 |
| 295 // Create the depth/stencil and multisample buffers, if needed. | 304 // Create the depth/stencil and multisample buffers, if needed. |
| 296 bool resizeMultisampleFramebuffer(const IntSize&); | 305 bool resizeMultisampleFramebuffer(const IntSize&); |
| 297 void resizeDepthStencil(const IntSize&); | 306 void resizeDepthStencil(const IntSize&); |
| 298 | 307 |
| 299 // Attempts to allocator storage for, or resize all buffers. Returns whether | 308 // Attempts to allocator storage for, or resize all buffers. Returns whether |
| 300 // the operation was successful. | 309 // the operation was successful. |
| 301 bool resizeDefaultFramebuffer(const IntSize&); | 310 bool resizeDefaultFramebuffer(const IntSize&); |
| 302 | 311 |
| 303 void clearPlatformLayer(); | 312 void clearPlatformLayer(); |
| 304 | 313 |
| 305 PassRefPtr<MailboxInfo> recycledMailbox(); | 314 PassRefPtr<MailboxInfo> takeRecycledMailbox(); |
| 306 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&); | 315 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&); |
| 307 void deleteMailbox(const WebExternalTextureMailbox&); | 316 void deleteMailbox(const gpu::Mailbox&, const gpu::SyncToken&); |
| 308 void freeRecycledMailboxes(); | 317 void freeRecycledMailboxes(); |
| 309 | 318 |
| 319 std::unique_ptr<cc::SharedBitmap> createOrRecycleBitmap(); |
| 320 |
| 310 // Updates the current size of the buffer, ensuring that s_currentResourceUs
ePixels is updated. | 321 // Updates the current size of the buffer, ensuring that s_currentResourceUs
ePixels is updated. |
| 311 void setSize(const IntSize& size); | 322 void setSize(const IntSize& size); |
| 312 | 323 |
| 313 // This is the order of bytes to use when doing a readback. | 324 // This is the order of bytes to use when doing a readback. |
| 314 enum ReadbackOrder { | 325 enum ReadbackOrder { |
| 315 ReadbackRGBA, | 326 ReadbackRGBA, |
| 316 ReadbackSkia | 327 ReadbackSkia |
| 317 }; | 328 }; |
| 318 | 329 |
| 319 // Helper function which does a readback from the currently-bound | 330 // Helper function which does a readback from the currently-bound |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 // Lifetime is tied to the m_contextProvider. | 384 // Lifetime is tied to the m_contextProvider. |
| 374 gpu::gles2::GLES2Interface* m_gl; | 385 gpu::gles2::GLES2Interface* m_gl; |
| 375 std::unique_ptr<Extensions3DUtil> m_extensionsUtil; | 386 std::unique_ptr<Extensions3DUtil> m_extensionsUtil; |
| 376 IntSize m_size = { -1, -1 }; | 387 IntSize m_size = { -1, -1 }; |
| 377 const bool m_discardFramebufferSupported; | 388 const bool m_discardFramebufferSupported; |
| 378 const bool m_wantAlphaChannel; | 389 const bool m_wantAlphaChannel; |
| 379 const bool m_premultipliedAlpha; | 390 const bool m_premultipliedAlpha; |
| 380 bool m_hasImplicitStencilBuffer = false; | 391 bool m_hasImplicitStencilBuffer = false; |
| 381 bool m_storageTextureSupported = false; | 392 bool m_storageTextureSupported = false; |
| 382 struct FrontBufferInfo { | 393 struct FrontBufferInfo { |
| 394 gpu::Mailbox mailbox; |
| 395 gpu::SyncToken produceSyncToken; |
| 383 TextureInfo texInfo; | 396 TextureInfo texInfo; |
| 384 WebExternalTextureMailbox mailbox; | |
| 385 }; | 397 }; |
| 386 FrontBufferInfo m_frontColorBuffer; | 398 FrontBufferInfo m_frontColorBuffer; |
| 387 | 399 |
| 388 std::unique_ptr<WTF::Closure> m_newMailboxCallback; | 400 std::unique_ptr<WTF::Closure> m_newMailboxCallback; |
| 389 | 401 |
| 390 // This is used when the user requests either a depth or stencil buffer. | 402 // This is used when the user requests either a depth or stencil buffer. |
| 391 GLuint m_depthStencilBuffer = 0; | 403 GLuint m_depthStencilBuffer = 0; |
| 392 | 404 |
| 393 // When wantExplicitResolve() returns true, the target of all draw | 405 // When wantExplicitResolve() returns true, the target of all draw |
| 394 // operations. | 406 // operations. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 int m_sampleCount = 0; | 442 int m_sampleCount = 0; |
| 431 int m_packAlignment = 4; | 443 int m_packAlignment = 4; |
| 432 bool m_destructionInProgress = false; | 444 bool m_destructionInProgress = false; |
| 433 bool m_isHidden = false; | 445 bool m_isHidden = false; |
| 434 SkFilterQuality m_filterQuality = kLow_SkFilterQuality; | 446 SkFilterQuality m_filterQuality = kLow_SkFilterQuality; |
| 435 | 447 |
| 436 std::unique_ptr<WebExternalTextureLayer> m_layer; | 448 std::unique_ptr<WebExternalTextureLayer> m_layer; |
| 437 | 449 |
| 438 // All of the mailboxes that this DrawingBuffer has ever created. | 450 // All of the mailboxes that this DrawingBuffer has ever created. |
| 439 Vector<RefPtr<MailboxInfo>> m_textureMailboxes; | 451 Vector<RefPtr<MailboxInfo>> m_textureMailboxes; |
| 452 struct RecycledMailbox : RefCounted<RecycledMailbox> { |
| 453 RecycledMailbox(const gpu::Mailbox& mailbox, const gpu::SyncToken& syncT
oken) |
| 454 : mailbox(mailbox) |
| 455 , syncToken(syncToken) |
| 456 { |
| 457 } |
| 458 |
| 459 gpu::Mailbox mailbox; |
| 460 gpu::SyncToken syncToken; |
| 461 |
| 462 private: |
| 463 WTF_MAKE_NONCOPYABLE(RecycledMailbox); |
| 464 }; |
| 440 // Mailboxes that were released by the compositor can be used again by this
DrawingBuffer. | 465 // Mailboxes that were released by the compositor can be used again by this
DrawingBuffer. |
| 441 Deque<WebExternalTextureMailbox> m_recycledMailboxQueue; | 466 Deque<RefPtr<RecycledMailbox>> m_recycledMailboxQueue; |
| 467 struct RecycledBitmap { |
| 468 std::unique_ptr<cc::SharedBitmap> bitmap; |
| 469 IntSize size; |
| 470 }; |
| 471 // Shared memory bitmaps that were released by the compositor and can be use
d again by this DrawingBuffer. |
| 472 Deque<RecycledBitmap> m_recycledBitmapQueue; |
| 442 | 473 |
| 443 // If the width and height of the Canvas's backing store don't | 474 // If the width and height of the Canvas's backing store don't |
| 444 // match those that we were given in the most recent call to | 475 // match those that we were given in the most recent call to |
| 445 // reshape(), then we need an intermediate bitmap to read back the | 476 // reshape(), then we need an intermediate bitmap to read back the |
| 446 // frame buffer into. This seems to happen when CSS styles are | 477 // frame buffer into. This seems to happen when CSS styles are |
| 447 // used to resize the Canvas. | 478 // used to resize the Canvas. |
| 448 SkBitmap m_resizingBitmap; | 479 SkBitmap m_resizingBitmap; |
| 449 | 480 |
| 450 // Used to flip a bitmap vertically. | 481 // Used to flip a bitmap vertically. |
| 451 Vector<uint8_t> m_scanline; | 482 Vector<uint8_t> m_scanline; |
| 452 }; | 483 }; |
| 453 | 484 |
| 454 } // namespace blink | 485 } // namespace blink |
| 455 | 486 |
| 456 #endif // DrawingBuffer_h | 487 #endif // DrawingBuffer_h |
| OLD | NEW |