| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 310     GLenum target = 0; | 310     GLenum target = 0; | 
| 311     GLenum internalColorFormat = 0; | 311     GLenum internalColorFormat = 0; | 
| 312 | 312 | 
| 313     // The internal color format used when allocating storage for the | 313     // The internal color format used when allocating storage for the | 
| 314     // texture. This may be different from internalColorFormat if RGB | 314     // texture. This may be different from internalColorFormat if RGB | 
| 315     // emulation is required. | 315     // emulation is required. | 
| 316     GLenum creationInternalColorFormat = 0; | 316     GLenum creationInternalColorFormat = 0; | 
| 317     GLenum colorFormat = 0; | 317     GLenum colorFormat = 0; | 
| 318   }; | 318   }; | 
| 319 | 319 | 
| 320   // If we used CHROMIUM_image as the backing storage for our buffers, | 320   struct ColorBuffer : public RefCounted<ColorBuffer> { | 
| 321   // we need to know the mapping from texture id to image. | 321     ColorBuffer(DrawingBuffer*, const TextureParameters&, const IntSize&); | 
| 322   struct TextureInfo { | 322     ~ColorBuffer(); | 
| 323     DISALLOW_NEW(); | 323 | 
|  | 324     // The owning DrawingBuffer. Note that DrawingBuffer is explicitly destroyed | 
|  | 325     // by the beginDestruction method, which will eventually drain all of its | 
|  | 326     // ColorBuffers. | 
|  | 327     RefPtr<DrawingBuffer> drawingBuffer; | 
|  | 328 | 
|  | 329     const TextureParameters parameters; | 
|  | 330     const IntSize size; | 
|  | 331 | 
| 324     GLuint textureId = 0; | 332     GLuint textureId = 0; | 
| 325     GLuint imageId = 0; | 333     GLuint imageId = 0; | 
| 326     TextureParameters parameters; |  | 
| 327   }; |  | 
| 328 | 334 | 
| 329   struct MailboxInfo : public RefCounted<MailboxInfo> { | 335     // The mailbox used to send this buffer to the compositor. | 
| 330     MailboxInfo() = default; |  | 
| 331     gpu::Mailbox mailbox; | 336     gpu::Mailbox mailbox; | 
| 332     TextureInfo textureInfo; | 337 | 
| 333     IntSize size; | 338     // The sync token for when this buffer was sent to the compositor. | 
|  | 339     gpu::SyncToken produceSyncToken; | 
|  | 340 | 
|  | 341     // The sync token for when this buffer was received back from the | 
|  | 342     // compositor. | 
|  | 343     gpu::SyncToken receiveSyncToken; | 
| 334 | 344 | 
| 335    private: | 345    private: | 
| 336     WTF_MAKE_NONCOPYABLE(MailboxInfo); | 346     WTF_MAKE_NONCOPYABLE(ColorBuffer); | 
| 337   }; | 347   }; | 
| 338 | 348 | 
| 339   bool prepareTextureMailboxInternal( | 349   bool prepareTextureMailboxInternal( | 
| 340       cc::TextureMailbox* outMailbox, | 350       cc::TextureMailbox* outMailbox, | 
| 341       std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback, | 351       std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback, | 
| 342       bool forceGpuResult); | 352       bool forceGpuResult); | 
| 343 | 353 | 
| 344   // Callbacks for mailboxes given to the compositor from PrepareTextureMailbox. | 354   // Callbacks for mailboxes given to the compositor from PrepareTextureMailbox. | 
| 345   void gpuMailboxReleased(const gpu::Mailbox&, | 355   void gpuMailboxReleased(RefPtr<ColorBuffer>, | 
| 346                           const gpu::SyncToken&, | 356                           const gpu::SyncToken&, | 
| 347                           bool lostResource); | 357                           bool lostResource); | 
| 348   void softwareMailboxReleased(std::unique_ptr<cc::SharedBitmap>, | 358   void softwareMailboxReleased(std::unique_ptr<cc::SharedBitmap>, | 
| 349                                const IntSize&, | 359                                const IntSize&, | 
| 350                                const gpu::SyncToken&, | 360                                const gpu::SyncToken&, | 
| 351                                bool lostResource); | 361                                bool lostResource); | 
| 352 | 362 | 
| 353   // The texture parameters to use for a texture that will be backed by a | 363   // The texture parameters to use for a texture that will be backed by a | 
| 354   // CHROMIUM_image. | 364   // CHROMIUM_image. | 
| 355   TextureParameters chromiumImageTextureParameters(); | 365   TextureParameters chromiumImageTextureParameters(); | 
| 356 | 366 | 
| 357   // The texture parameters to use for a default texture. | 367   // The texture parameters to use for a default texture. | 
| 358   TextureParameters defaultTextureParameters(); | 368   TextureParameters defaultTextureParameters(); | 
| 359 | 369 | 
| 360   // Creates and binds a texture with the given parameters. Returns 0 on | 370   // Creates and binds a texture with the given parameters. Returns 0 on | 
| 361   // failure, or the newly created texture id on success. The caller takes | 371   // failure, or the newly created texture id on success. The caller takes | 
| 362   // ownership of the newly created texture. | 372   // ownership of the newly created texture. | 
| 363   GLuint createColorTexture(const TextureParameters&); | 373   GLuint createColorTexture(const TextureParameters&); | 
| 364 | 374 | 
| 365   // Attempts to allocator storage for, or resize all buffers. Returns whether | 375   // Attempts to allocator storage for, or resize all buffers. Returns whether | 
| 366   // the operation was successful. | 376   // the operation was successful. | 
| 367   bool resizeDefaultFramebuffer(const IntSize&); | 377   bool resizeDefaultFramebuffer(const IntSize&); | 
| 368 | 378 | 
| 369   void clearPlatformLayer(); | 379   void clearPlatformLayer(); | 
| 370 | 380 | 
| 371   PassRefPtr<MailboxInfo> takeRecycledMailbox(); | 381   PassRefPtr<ColorBuffer> takeRecycledMailbox(); | 
| 372   PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&); |  | 
| 373   void deleteMailbox(const gpu::Mailbox&, const gpu::SyncToken&); |  | 
| 374   void freeRecycledMailboxes(); |  | 
| 375 | 382 | 
| 376   std::unique_ptr<cc::SharedBitmap> createOrRecycleBitmap(); | 383   std::unique_ptr<cc::SharedBitmap> createOrRecycleBitmap(); | 
| 377 | 384 | 
| 378   // Updates the current size of the buffer, ensuring that | 385   // Updates the current size of the buffer, ensuring that | 
| 379   // s_currentResourceUsePixels is updated. | 386   // s_currentResourceUsePixels is updated. | 
| 380   void setSize(const IntSize& size); | 387   void setSize(const IntSize& size); | 
| 381 | 388 | 
| 382   // This is the order of bytes to use when doing a readback. | 389   // This is the order of bytes to use when doing a readback. | 
| 383   enum ReadbackOrder { ReadbackRGBA, ReadbackSkia }; | 390   enum ReadbackOrder { ReadbackRGBA, ReadbackSkia }; | 
| 384 | 391 | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 395 | 402 | 
| 396   // Allocate a storage texture if possible. Otherwise, allocate a regular | 403   // Allocate a storage texture if possible. Otherwise, allocate a regular | 
| 397   // texture. | 404   // texture. | 
| 398   void allocateConditionallyImmutableTexture(GLenum target, | 405   void allocateConditionallyImmutableTexture(GLenum target, | 
| 399                                              GLenum internalformat, | 406                                              GLenum internalformat, | 
| 400                                              GLsizei width, | 407                                              GLsizei width, | 
| 401                                              GLsizei height, | 408                                              GLsizei height, | 
| 402                                              GLint border, | 409                                              GLint border, | 
| 403                                              GLenum format, | 410                                              GLenum format, | 
| 404                                              GLenum type); | 411                                              GLenum type); | 
| 405   // Allocate buffer storage to be sent to compositor using either texImage2D or |  | 
| 406   // CHROMIUM_image based on available support. |  | 
| 407   void deleteChromiumImageForTexture(TextureInfo*); |  | 
| 408 | 412 | 
| 409   // If RGB emulation is required, then the CHROMIUM image's alpha channel | 413   // If RGB emulation is required, then the CHROMIUM image's alpha channel | 
| 410   // must be immediately cleared after it is bound to a texture. Nothing | 414   // must be immediately cleared after it is bound to a texture. Nothing | 
| 411   // should be allowed to change the alpha channel after this. | 415   // should be allowed to change the alpha channel after this. | 
| 412   void clearChromiumImageAlpha(const TextureInfo&); | 416   void clearChromiumImageAlpha(const ColorBuffer&); | 
| 413 | 417 | 
| 414   // Tries to create a CHROMIUM_image backed texture if | 418   // Tries to create a CHROMIUM_image backed texture if | 
| 415   // RuntimeEnabledFeatures::webGLImageChromiumEnabled() is true. On failure, | 419   // RuntimeEnabledFeatures::webGLImageChromiumEnabled() is true. On failure, | 
| 416   // or if the flag is false, creates a default texture. | 420   // or if the flag is false, creates a default texture. | 
| 417   TextureInfo createTextureAndAllocateMemory(const IntSize&); | 421   RefPtr<ColorBuffer> createTextureAndAllocateMemory(const IntSize&); | 
| 418 | 422 | 
| 419   // Creates and allocates space for a default texture. | 423   // Creates and allocates space for a default texture. | 
| 420   TextureInfo createDefaultTextureAndAllocateMemory(const IntSize&); | 424   RefPtr<ColorBuffer> createDefaultTextureAndAllocateMemory(const IntSize&); | 
| 421 | 425 | 
| 422   // Attaches |m_colorBuffer| to |m_fbo|, which is always the source for read | 426   // Attaches |m_backColorBuffer| to |m_fbo|, which is always the source for | 
| 423   // operations. | 427   // read operations. | 
| 424   void attachColorBufferToReadFramebuffer(); | 428   void attachColorBufferToReadFramebuffer(); | 
| 425 | 429 | 
| 426   // Whether the WebGL client desires an explicit resolve. This is | 430   // Whether the WebGL client desires an explicit resolve. This is | 
| 427   // implemented by forwarding all draw operations to a multisample | 431   // implemented by forwarding all draw operations to a multisample | 
| 428   // renderbuffer, which is resolved before any read operations or swaps. | 432   // renderbuffer, which is resolved before any read operations or swaps. | 
| 429   bool wantExplicitResolve(); | 433   bool wantExplicitResolve(); | 
| 430 | 434 | 
| 431   // Whether the WebGL client wants a depth or stencil buffer. | 435   // Whether the WebGL client wants a depth or stencil buffer. | 
| 432   bool wantDepthOrStencil(); | 436   bool wantDepthOrStencil(); | 
| 433 | 437 | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 450   // Lifetime is tied to the m_contextProvider. | 454   // Lifetime is tied to the m_contextProvider. | 
| 451   gpu::gles2::GLES2Interface* m_gl; | 455   gpu::gles2::GLES2Interface* m_gl; | 
| 452   std::unique_ptr<Extensions3DUtil> m_extensionsUtil; | 456   std::unique_ptr<Extensions3DUtil> m_extensionsUtil; | 
| 453   IntSize m_size = {-1, -1}; | 457   IntSize m_size = {-1, -1}; | 
| 454   const bool m_discardFramebufferSupported; | 458   const bool m_discardFramebufferSupported; | 
| 455   const bool m_wantAlphaChannel; | 459   const bool m_wantAlphaChannel; | 
| 456   const bool m_premultipliedAlpha; | 460   const bool m_premultipliedAlpha; | 
| 457   const bool m_softwareRendering; | 461   const bool m_softwareRendering; | 
| 458   bool m_hasImplicitStencilBuffer = false; | 462   bool m_hasImplicitStencilBuffer = false; | 
| 459   bool m_storageTextureSupported = false; | 463   bool m_storageTextureSupported = false; | 
| 460   struct FrontBufferInfo { | 464 | 
| 461     gpu::Mailbox mailbox; | 465   // This is the ColorBuffer that was most recently presented to the compositor | 
| 462     gpu::SyncToken produceSyncToken; | 466   // by prepareTextureMailboxInternal. | 
| 463     TextureInfo texInfo; | 467   RefPtr<ColorBuffer> m_frontColorBuffer; | 
| 464   }; |  | 
| 465   FrontBufferInfo m_frontColorBuffer; |  | 
| 466 | 468 | 
| 467   std::unique_ptr<WTF::Closure> m_newMailboxCallback; | 469   std::unique_ptr<WTF::Closure> m_newMailboxCallback; | 
| 468 | 470 | 
| 469   // This is used when the user requests either a depth or stencil buffer. | 471   // This is used when the user requests either a depth or stencil buffer. | 
| 470   GLuint m_depthStencilBuffer = 0; | 472   GLuint m_depthStencilBuffer = 0; | 
| 471 | 473 | 
| 472   // When wantExplicitResolve() returns true, the target of all draw | 474   // When wantExplicitResolve() returns true, the target of all draw | 
| 473   // operations. | 475   // operations. | 
| 474   GLuint m_multisampleFBO = 0; | 476   GLuint m_multisampleFBO = 0; | 
| 475 | 477 | 
| 476   // The id of the renderbuffer storage for |m_multisampleFBO|. | 478   // The id of the renderbuffer storage for |m_multisampleFBO|. | 
| 477   GLuint m_multisampleRenderbuffer = 0; | 479   GLuint m_multisampleRenderbuffer = 0; | 
| 478 | 480 | 
| 479   // When wantExplicitResolve() returns false, the target of all draw and | 481   // When wantExplicitResolve() returns false, the target of all draw and | 
| 480   // read operations. When wantExplicitResolve() returns true, the target of | 482   // read operations. When wantExplicitResolve() returns true, the target of | 
| 481   // all read operations. A swap is performed by exchanging |m_colorBuffer| | 483   // all read operations. A swap is performed by exchanging |m_backColorBuffer| | 
| 482   // with |m_frontColorBuffer|. | 484   // with |m_frontColorBuffer|. | 
| 483   GLuint m_fbo = 0; | 485   GLuint m_fbo = 0; | 
| 484 | 486 | 
| 485   // All information about the texture storage for |m_fbo|. | 487   // All information about the texture storage for |m_fbo|. | 
| 486   TextureInfo m_colorBuffer; | 488   RefPtr<ColorBuffer> m_backColorBuffer; | 
| 487 | 489 | 
| 488   // True if our contents have been modified since the last presentation of this | 490   // True if our contents have been modified since the last presentation of this | 
| 489   // buffer. | 491   // buffer. | 
| 490   bool m_contentsChanged = true; | 492   bool m_contentsChanged = true; | 
| 491 | 493 | 
| 492   // True if commit() has been called since the last time markContentsChanged() | 494   // True if commit() has been called since the last time markContentsChanged() | 
| 493   // had been called. | 495   // had been called. | 
| 494   bool m_contentsChangeCommitted = false; | 496   bool m_contentsChangeCommitted = false; | 
| 495   bool m_bufferClearNeeded = false; | 497   bool m_bufferClearNeeded = false; | 
| 496 | 498 | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 509 | 511 | 
| 510   int m_maxTextureSize = 0; | 512   int m_maxTextureSize = 0; | 
| 511   int m_sampleCount = 0; | 513   int m_sampleCount = 0; | 
| 512   int m_packAlignment = 4; | 514   int m_packAlignment = 4; | 
| 513   bool m_destructionInProgress = false; | 515   bool m_destructionInProgress = false; | 
| 514   bool m_isHidden = false; | 516   bool m_isHidden = false; | 
| 515   SkFilterQuality m_filterQuality = kLow_SkFilterQuality; | 517   SkFilterQuality m_filterQuality = kLow_SkFilterQuality; | 
| 516 | 518 | 
| 517   std::unique_ptr<WebExternalTextureLayer> m_layer; | 519   std::unique_ptr<WebExternalTextureLayer> m_layer; | 
| 518 | 520 | 
| 519   // All of the mailboxes that this DrawingBuffer has ever created. |  | 
| 520   Vector<RefPtr<MailboxInfo>> m_textureMailboxes; |  | 
| 521   struct RecycledMailbox : RefCounted<RecycledMailbox> { |  | 
| 522     RecycledMailbox(const gpu::Mailbox& mailbox, |  | 
| 523                     const gpu::SyncToken& syncToken) |  | 
| 524         : mailbox(mailbox), syncToken(syncToken) {} |  | 
| 525 |  | 
| 526     gpu::Mailbox mailbox; |  | 
| 527     gpu::SyncToken syncToken; |  | 
| 528 |  | 
| 529    private: |  | 
| 530     WTF_MAKE_NONCOPYABLE(RecycledMailbox); |  | 
| 531   }; |  | 
| 532   // Mailboxes that were released by the compositor can be used again by this | 521   // Mailboxes that were released by the compositor can be used again by this | 
| 533   // DrawingBuffer. | 522   // DrawingBuffer. | 
| 534   Deque<RefPtr<RecycledMailbox>> m_recycledMailboxQueue; | 523   Deque<RefPtr<ColorBuffer>> m_recycledMailboxQueue; | 
| 535 | 524 | 
| 536   // If the width and height of the Canvas's backing store don't | 525   // If the width and height of the Canvas's backing store don't | 
| 537   // match those that we were given in the most recent call to | 526   // match those that we were given in the most recent call to | 
| 538   // reshape(), then we need an intermediate bitmap to read back the | 527   // reshape(), then we need an intermediate bitmap to read back the | 
| 539   // frame buffer into. This seems to happen when CSS styles are | 528   // frame buffer into. This seems to happen when CSS styles are | 
| 540   // used to resize the Canvas. | 529   // used to resize the Canvas. | 
| 541   SkBitmap m_resizingBitmap; | 530   SkBitmap m_resizingBitmap; | 
| 542 | 531 | 
| 543   // Used to flip a bitmap vertically. | 532   // Used to flip a bitmap vertically. | 
| 544   Vector<uint8_t> m_scanline; | 533   Vector<uint8_t> m_scanline; | 
| 545 | 534 | 
| 546   // In the case of OffscreenCanvas, we do not want to enable the | 535   // In the case of OffscreenCanvas, we do not want to enable the | 
| 547   // WebGLImageChromium flag, so we replace all the | 536   // WebGLImageChromium flag, so we replace all the | 
| 548   // RuntimeEnabledFeatures::webGLImageChromiumEnabled() call with | 537   // RuntimeEnabledFeatures::webGLImageChromiumEnabled() call with | 
| 549   // shouldUseChromiumImage() calls, and set m_chromiumImageUsage to | 538   // shouldUseChromiumImage() calls, and set m_chromiumImageUsage to | 
| 550   // DisallowChromiumImage in the case of OffscreenCanvas. | 539   // DisallowChromiumImage in the case of OffscreenCanvas. | 
| 551   ChromiumImageUsage m_chromiumImageUsage; | 540   ChromiumImageUsage m_chromiumImageUsage; | 
| 552   bool shouldUseChromiumImage(); | 541   bool shouldUseChromiumImage(); | 
| 553 }; | 542 }; | 
| 554 | 543 | 
| 555 }  // namespace blink | 544 }  // namespace blink | 
| 556 | 545 | 
| 557 #endif  // DrawingBuffer_h | 546 #endif  // DrawingBuffer_h | 
| OLD | NEW | 
|---|