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