| 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 // OpenGL state the the DrawingBuffer may modify, which it will need to | 
|  | 73 // restore before returning from any of its methods. | 
|  | 74 struct PLATFORM_EXPORT DrawingBufferRestoreState { | 
|  | 75   bool scissorEnabled = false; | 
|  | 76 | 
|  | 77   GLfloat clearColor[4] = {0, 0, 0, 0}; | 
|  | 78   GLfloat clearDepth = 0; | 
|  | 79   GLint clearStencil = 0; | 
|  | 80 | 
|  | 81   GLboolean colorMask[4] = {0, 0, 0, 0}; | 
|  | 82   GLboolean depthMask = 0; | 
|  | 83   GLuint stencilMask = 0; | 
|  | 84 | 
|  | 85   GLint packAlignment = 4; | 
|  | 86 | 
|  | 87   // The bound 2D texture for the active texture unit. | 
|  | 88   GLuint activeTexture2DBinding = 0; | 
|  | 89   GLuint renderbufferBinding = 0; | 
|  | 90   GLuint drawFramebufferBinding = 0; | 
|  | 91   GLuint readFramebufferBinding = 0; | 
|  | 92   GLuint pixelUnpackBufferBinding = 0; | 
|  | 93 }; | 
|  | 94 | 
|  | 95 // An interface through which DrawingBuffer may query the state that it will | 
|  | 96 // need to reset from an object that is tracking this state. | 
|  | 97 class PLATFORM_EXPORT DrawingBufferStateTracker { | 
|  | 98  public: | 
|  | 99   virtual void GetDrawingBufferRestoreState(DrawingBufferRestoreState*) = 0; | 
|  | 100 }; | 
|  | 101 | 
| 72 // Manages a rendering target (framebuffer + attachment) for a canvas.  Can | 102 // Manages a rendering target (framebuffer + attachment) for a canvas.  Can | 
| 73 // publish its rendering results to a WebLayer for compositing. | 103 // publish its rendering results to a WebLayer for compositing. | 
| 74 class PLATFORM_EXPORT DrawingBuffer | 104 class PLATFORM_EXPORT DrawingBuffer | 
| 75     : public NON_EXPORTED_BASE(cc::TextureLayerClient), | 105     : public NON_EXPORTED_BASE(cc::TextureLayerClient), | 
| 76       public RefCounted<DrawingBuffer> { | 106       public RefCounted<DrawingBuffer> { | 
| 77   WTF_MAKE_NONCOPYABLE(DrawingBuffer); | 107   WTF_MAKE_NONCOPYABLE(DrawingBuffer); | 
| 78 | 108 | 
| 79  public: | 109  public: | 
| 80   enum PreserveDrawingBuffer { | 110   enum PreserveDrawingBuffer { | 
| 81     Preserve, | 111     Preserve, | 
| 82     Discard, | 112     Discard, | 
| 83   }; | 113   }; | 
| 84   enum WebGLVersion { | 114   enum WebGLVersion { | 
| 85     WebGL1, | 115     WebGL1, | 
| 86     WebGL2, | 116     WebGL2, | 
| 87   }; | 117   }; | 
| 88 | 118 | 
| 89   enum ChromiumImageUsage { | 119   enum ChromiumImageUsage { | 
| 90     AllowChromiumImage, | 120     AllowChromiumImage, | 
| 91     DisallowChromiumImage, | 121     DisallowChromiumImage, | 
| 92   }; | 122   }; | 
| 93 | 123 | 
| 94   static PassRefPtr<DrawingBuffer> create( | 124   static PassRefPtr<DrawingBuffer> create( | 
| 95       std::unique_ptr<WebGraphicsContext3DProvider>, | 125       std::unique_ptr<WebGraphicsContext3DProvider>, | 
|  | 126       DrawingBufferStateTracker*, | 
| 96       const IntSize&, | 127       const IntSize&, | 
| 97       bool premultipliedAlpha, | 128       bool premultipliedAlpha, | 
| 98       bool wantAlphaChannel, | 129       bool wantAlphaChannel, | 
| 99       bool wantDepthBuffer, | 130       bool wantDepthBuffer, | 
| 100       bool wantStencilBuffer, | 131       bool wantStencilBuffer, | 
| 101       bool wantAntialiasing, | 132       bool wantAntialiasing, | 
| 102       PreserveDrawingBuffer, | 133       PreserveDrawingBuffer, | 
| 103       WebGLVersion, | 134       WebGLVersion, | 
| 104       ChromiumImageUsage); | 135       ChromiumImageUsage); | 
| 105   static void forceNextDrawingBufferCreationToFail(); | 136   static void forceNextDrawingBufferCreationToFail(); | 
| 106 | 137 | 
| 107   ~DrawingBuffer() override; | 138   ~DrawingBuffer() override; | 
| 108 | 139 | 
| 109   // Destruction will be completed after all mailboxes are released. | 140   // Destruction will be completed after all mailboxes are released. | 
| 110   void beginDestruction(); | 141   void beginDestruction(); | 
| 111 | 142 | 
| 112   // Issues a glClear() on all framebuffers associated with this DrawingBuffer. | 143   // Issues a glClear() on all framebuffers associated with this DrawingBuffer. | 
| 113   // The caller is responsible for making the context current and setting the | 144   // The caller is responsible for making the context current and setting the | 
| 114   // clear values and masks. Modifies the framebuffer binding. | 145   // clear values and masks. | 
| 115   void clearFramebuffers(GLbitfield clearMask); | 146   void clearFramebuffers(GLbitfield clearMask); | 
| 116 | 147 | 
| 117   // Indicates whether the DrawingBuffer internally allocated a packed | 148   // Indicates whether the DrawingBuffer internally allocated a packed | 
| 118   // depth-stencil renderbuffer in the situation where the end user only asked | 149   // depth-stencil renderbuffer in the situation where the end user only asked | 
| 119   // for a depth buffer. In this case, we need to upgrade clears of the depth | 150   // for a depth buffer. In this case, we need to upgrade clears of the depth | 
| 120   // buffer to clears of the depth and stencil buffers in order to avoid | 151   // buffer to clears of the depth and stencil buffers in order to avoid | 
| 121   // performance problems on some GPUs. | 152   // performance problems on some GPUs. | 
| 122   bool hasImplicitStencilBuffer() const { return m_hasImplicitStencilBuffer; } | 153   bool hasImplicitStencilBuffer() const { return m_hasImplicitStencilBuffer; } | 
| 123   bool hasDepthBuffer() const { return !!m_depthStencilBuffer; } | 154   bool hasDepthBuffer() const { return !!m_depthStencilBuffer; } | 
| 124   bool hasStencilBuffer() const { return !!m_depthStencilBuffer; } | 155   bool hasStencilBuffer() const { return !!m_depthStencilBuffer; } | 
| 125 | 156 | 
| 126   // Given the desired buffer size, provides the largest dimensions that will | 157   // Given the desired buffer size, provides the largest dimensions that will | 
| 127   // fit in the pixel budget. | 158   // fit in the pixel budget. | 
| 128   static IntSize adjustSize(const IntSize& desiredSize, | 159   static IntSize adjustSize(const IntSize& desiredSize, | 
| 129                             const IntSize& curSize, | 160                             const IntSize& curSize, | 
| 130                             int maxTextureSize); | 161                             int maxTextureSize); | 
| 131 | 162 | 
| 132   // Resizes (or allocates if necessary) all buffers attached to the default | 163   // Resizes (or allocates if necessary) all buffers attached to the default | 
| 133   // framebuffer. Returns whether the operation was successful. Leaves GL | 164   // framebuffer. Returns whether the operation was successful. | 
| 134   // bindings dirtied. | 165   bool resize(const IntSize&); | 
| 135   bool reset(const IntSize&); |  | 
| 136 | 166 | 
| 137   // Bind the default framebuffer to |target|. |target| must be | 167   // Bind the default framebuffer to |target|. |target| must be | 
| 138   // GL_FRAMEBUFFER, GL_READ_FRAMEBUFFER, or GL_DRAW_FRAMEBUFFER. | 168   // GL_FRAMEBUFFER, GL_READ_FRAMEBUFFER, or GL_DRAW_FRAMEBUFFER. | 
| 139   void bind(GLenum target); | 169   void bind(GLenum target); | 
| 140   IntSize size() const { return m_size; } | 170   IntSize size() const { return m_size; } | 
| 141 | 171 | 
| 142   // Copies the multisample color buffer to the normal color buffer and leaves | 172   // Resolves the multisample color buffer to the normal color buffer and leaves | 
| 143   // m_fbo bound. | 173   // the resolved color buffer bound to GL_READ_FRAMEBUFFER and | 
| 144   void commit(); | 174   // GL_DRAW_FRAMEBUFFER. | 
| 145 | 175   void resolveAndBindForReadAndDraw(); | 
| 146   // commit should copy the full multisample buffer, and not respect the |  | 
| 147   // current scissor bounds. Track the state of the scissor test so that it |  | 
| 148   // can be disabled during calls to commit. |  | 
| 149   void setScissorEnabled(bool scissorEnabled) { |  | 
| 150     m_scissorEnabled = scissorEnabled; |  | 
| 151   } |  | 
| 152 |  | 
| 153   // The DrawingBuffer needs to track the texture bound to texture unit 0. |  | 
| 154   // The bound texture is tracked to avoid costly queries during rendering. |  | 
| 155   void setTexture2DBinding(GLuint texture) { m_texture2DBinding = texture; } |  | 
| 156 |  | 
| 157   void setPixelUnpackBufferBinding(GLuint buffer) { |  | 
| 158     DCHECK(m_webGLVersion > WebGL1); |  | 
| 159     m_pixelUnpackBufferBinding = buffer; |  | 
| 160   } |  | 
| 161 |  | 
| 162   void notifyBufferDeleted(GLuint buffer) { |  | 
| 163     if (m_webGLVersion > WebGL1 && buffer == m_pixelUnpackBufferBinding) { |  | 
| 164       setPixelUnpackBufferBinding(0); |  | 
| 165     } |  | 
| 166   } |  | 
| 167 |  | 
| 168   // The DrawingBuffer needs to track the currently bound framebuffer so it |  | 
| 169   // restore the binding when needed. |  | 
| 170   void setFramebufferBinding(GLenum target, GLuint fbo) { |  | 
| 171     switch (target) { |  | 
| 172       case GL_FRAMEBUFFER: |  | 
| 173         m_drawFramebufferBinding = fbo; |  | 
| 174         m_readFramebufferBinding = fbo; |  | 
| 175         break; |  | 
| 176       case GL_DRAW_FRAMEBUFFER: |  | 
| 177         m_drawFramebufferBinding = fbo; |  | 
| 178         break; |  | 
| 179       case GL_READ_FRAMEBUFFER: |  | 
| 180         m_readFramebufferBinding = fbo; |  | 
| 181         break; |  | 
| 182       default: |  | 
| 183         ASSERT(0); |  | 
| 184     } |  | 
| 185   } |  | 
| 186 |  | 
| 187   // The DrawingBuffer needs to track the color mask and clear color so that |  | 
| 188   // it can restore it when needed. |  | 
| 189   void setClearColor(GLfloat* clearColor) { |  | 
| 190     memcpy(m_clearColor, clearColor, 4 * sizeof(GLfloat)); |  | 
| 191   } |  | 
| 192 |  | 
| 193   void setColorMask(GLboolean* colorMask) { |  | 
| 194     memcpy(m_colorMask, colorMask, 4 * sizeof(GLboolean)); |  | 
| 195   } |  | 
| 196 |  | 
| 197   // The DrawingBuffer needs to track the currently bound renderbuffer so it |  | 
| 198   // restore the binding when needed. |  | 
| 199   void setRenderbufferBinding(GLuint renderbuffer) { |  | 
| 200     m_renderbufferBinding = renderbuffer; |  | 
| 201   } |  | 
| 202 |  | 
| 203   // Track the currently active texture unit. Texture unit 0 is used as host for |  | 
| 204   // a scratch texture. |  | 
| 205   void setActiveTextureUnit(GLint textureUnit) { |  | 
| 206     m_activeTextureUnit = textureUnit; |  | 
| 207   } |  | 
| 208 | 176 | 
| 209   bool multisample() const; | 177   bool multisample() const; | 
| 210 | 178 | 
| 211   GLuint framebuffer() const; |  | 
| 212 |  | 
| 213   bool discardFramebufferSupported() const { | 179   bool discardFramebufferSupported() const { | 
| 214     return m_discardFramebufferSupported; | 180     return m_discardFramebufferSupported; | 
| 215   } | 181   } | 
| 216 | 182 | 
| 217   void markContentsChanged(); | 183   void markContentsChanged(); | 
| 218   void setBufferClearNeeded(bool); | 184   void setBufferClearNeeded(bool); | 
| 219   bool bufferClearNeeded() const; | 185   bool bufferClearNeeded() const; | 
| 220   void setIsHidden(bool); | 186   void setIsHidden(bool); | 
| 221   void setFilterQuality(SkFilterQuality); | 187   void setFilterQuality(SkFilterQuality); | 
| 222 | 188 | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 239   bool PrepareTextureMailbox( | 205   bool PrepareTextureMailbox( | 
| 240       cc::TextureMailbox* outMailbox, | 206       cc::TextureMailbox* outMailbox, | 
| 241       std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback) override; | 207       std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback) override; | 
| 242 | 208 | 
| 243   // Returns a StaticBitmapImage backed by a texture containing the current | 209   // Returns a StaticBitmapImage backed by a texture containing the current | 
| 244   // contents of the front buffer. This is done without any pixel copies. The | 210   // contents of the front buffer. This is done without any pixel copies. The | 
| 245   // texture in the ImageBitmap is from the active ContextProvider on the | 211   // texture in the ImageBitmap is from the active ContextProvider on the | 
| 246   // DrawingBuffer. | 212   // DrawingBuffer. | 
| 247   PassRefPtr<StaticBitmapImage> transferToStaticBitmapImage(); | 213   PassRefPtr<StaticBitmapImage> transferToStaticBitmapImage(); | 
| 248 | 214 | 
| 249   // Destroys the TEXTURE_2D binding for the owned context |  | 
| 250   bool copyToPlatformTexture(gpu::gles2::GLES2Interface*, | 215   bool copyToPlatformTexture(gpu::gles2::GLES2Interface*, | 
| 251                              GLuint texture, | 216                              GLuint texture, | 
| 252                              GLenum internalFormat, | 217                              GLenum internalFormat, | 
| 253                              GLenum destType, | 218                              GLenum destType, | 
| 254                              GLint level, | 219                              GLint level, | 
| 255                              bool premultiplyAlpha, | 220                              bool premultiplyAlpha, | 
| 256                              bool flipY, | 221                              bool flipY, | 
| 257                              SourceDrawingBuffer); | 222                              SourceDrawingBuffer); | 
| 258 | 223 | 
| 259   void setPackAlignment(GLint param); |  | 
| 260 |  | 
| 261   bool paintRenderingResultsToImageData(int&, | 224   bool paintRenderingResultsToImageData(int&, | 
| 262                                         int&, | 225                                         int&, | 
| 263                                         SourceDrawingBuffer, | 226                                         SourceDrawingBuffer, | 
| 264                                         WTF::ArrayBufferContents&); | 227                                         WTF::ArrayBufferContents&); | 
| 265 | 228 | 
| 266   int sampleCount() const { return m_sampleCount; } | 229   int sampleCount() const { return m_sampleCount; } | 
| 267   bool explicitResolveOfMultisampleData() const { | 230   bool explicitResolveOfMultisampleData() const { | 
| 268     return m_antiAliasingMode == MSAAExplicitResolve; | 231     return m_antiAliasingMode == MSAAExplicitResolve; | 
| 269   } | 232   } | 
| 270 | 233 | 
| 271   void restorePixelUnpackBufferBindings(); | 234   // Rebind the read and draw framebuffers that WebGL is expecting. | 
| 272 |  | 
| 273   // Bind to m_drawFramebufferBinding or m_readFramebufferBinding if it's not 0. |  | 
| 274   // Otherwise, bind to the default FBO. |  | 
| 275   void restoreFramebufferBindings(); | 235   void restoreFramebufferBindings(); | 
| 276 | 236 | 
| 277   void restoreTextureBindings(); |  | 
| 278 |  | 
| 279   void addNewMailboxCallback(std::unique_ptr<WTF::Closure> closure) { | 237   void addNewMailboxCallback(std::unique_ptr<WTF::Closure> closure) { | 
| 280     m_newMailboxCallback = std::move(closure); | 238     m_newMailboxCallback = std::move(closure); | 
| 281   } | 239   } | 
| 282 | 240 | 
| 283  protected:  // For unittests | 241  protected:  // For unittests | 
| 284   DrawingBuffer(std::unique_ptr<WebGraphicsContext3DProvider>, | 242   DrawingBuffer(std::unique_ptr<WebGraphicsContext3DProvider>, | 
| 285                 std::unique_ptr<Extensions3DUtil>, | 243                 std::unique_ptr<Extensions3DUtil>, | 
|  | 244                 DrawingBufferStateTracker*, | 
| 286                 bool discardFramebufferSupported, | 245                 bool discardFramebufferSupported, | 
| 287                 bool wantAlphaChannel, | 246                 bool wantAlphaChannel, | 
| 288                 bool premultipliedAlpha, | 247                 bool premultipliedAlpha, | 
| 289                 PreserveDrawingBuffer, | 248                 PreserveDrawingBuffer, | 
| 290                 WebGLVersion, | 249                 WebGLVersion, | 
| 291                 bool wantsDepth, | 250                 bool wantsDepth, | 
| 292                 bool wantsStencil, | 251                 bool wantsStencil, | 
| 293                 ChromiumImageUsage); | 252                 ChromiumImageUsage); | 
| 294 | 253 | 
| 295   bool initialize(const IntSize&, bool useMultisampling); | 254   bool initialize(const IntSize&, bool useMultisampling); | 
| 296 | 255 | 
| 297   // Shared memory bitmaps that were released by the compositor and can be used | 256   // Shared memory bitmaps that were released by the compositor and can be used | 
| 298   // again by this DrawingBuffer. | 257   // again by this DrawingBuffer. | 
| 299   struct RecycledBitmap { | 258   struct RecycledBitmap { | 
| 300     std::unique_ptr<cc::SharedBitmap> bitmap; | 259     std::unique_ptr<cc::SharedBitmap> bitmap; | 
| 301     IntSize size; | 260     IntSize size; | 
| 302   }; | 261   }; | 
| 303   Vector<RecycledBitmap> m_recycledBitmaps; | 262   Vector<RecycledBitmap> m_recycledBitmaps; | 
| 304 | 263 | 
| 305  private: | 264  private: | 
| 306   // All parameters necessary to generate the texture that will be passed to | 265   friend class ScopedStateRestorer; | 
| 307   // prepareMailbox. | 266   friend class ColorBuffer; | 
| 308   struct TextureParameters { | 267 | 
|  | 268   // This structure should wrap all public entrypoints that may modify GL state. | 
|  | 269   // It will restore all state when it drops out of scope. | 
|  | 270   class ScopedStateRestorer { | 
|  | 271    public: | 
|  | 272     ScopedStateRestorer(DrawingBuffer*); | 
|  | 273     ~ScopedStateRestorer(); | 
|  | 274 | 
|  | 275     // Mark parts of the state that are dirty and need to be restored. | 
|  | 276     void setClearStateDirty() { m_clearStateDirty = true; } | 
|  | 277     void setPixelPackAlignmentDirty() { m_pixelPackAlignmentDirty = true; } | 
|  | 278     void setTextureBindingDirty() { m_textureBindingDirty = true; } | 
|  | 279     void setRenderbufferBindingDirty() { m_renderbufferBindingDirty = true; } | 
|  | 280     void setFramebufferBindingDirty() { m_framebufferBindingDirty = true; } | 
|  | 281     void setPixelUnpackBufferBindingDirty() { | 
|  | 282       m_pixelUnpackBufferBindingDirty = true; | 
|  | 283     } | 
|  | 284 | 
|  | 285    private: | 
|  | 286     RefPtr<DrawingBuffer> m_drawingBuffer; | 
|  | 287     bool m_clearStateDirty = false; | 
|  | 288     bool m_pixelPackAlignmentDirty = false; | 
|  | 289     bool m_textureBindingDirty = false; | 
|  | 290     bool m_renderbufferBindingDirty = false; | 
|  | 291     bool m_framebufferBindingDirty = false; | 
|  | 292     bool m_pixelUnpackBufferBindingDirty = false; | 
|  | 293   }; | 
|  | 294 | 
|  | 295   // All parameters necessary to generate the texture for the ColorBuffer. | 
|  | 296   struct ColorBufferParameters { | 
| 309     DISALLOW_NEW(); | 297     DISALLOW_NEW(); | 
| 310     GLenum target = 0; | 298     GLenum target = 0; | 
| 311     GLenum internalColorFormat = 0; | 299     GLenum internalColorFormat = 0; | 
| 312 | 300 | 
| 313     // The internal color format used when allocating storage for the | 301     // The internal color format used when allocating storage for the | 
| 314     // texture. This may be different from internalColorFormat if RGB | 302     // texture. This may be different from internalColorFormat if RGB | 
| 315     // emulation is required. | 303     // emulation is required. | 
| 316     GLenum creationInternalColorFormat = 0; | 304     GLenum creationInternalColorFormat = 0; | 
| 317     GLenum colorFormat = 0; | 305     GLenum colorFormat = 0; | 
| 318   }; | 306   }; | 
| 319 | 307 | 
| 320   struct ColorBuffer : public RefCounted<ColorBuffer> { | 308   struct ColorBuffer : public RefCounted<ColorBuffer> { | 
| 321     ColorBuffer(DrawingBuffer*, const TextureParameters&, const IntSize&); | 309     ColorBuffer(DrawingBuffer*, | 
|  | 310                 const ColorBufferParameters&, | 
|  | 311                 const IntSize&, | 
|  | 312                 GLuint textureId, | 
|  | 313                 GLuint imageId); | 
| 322     ~ColorBuffer(); | 314     ~ColorBuffer(); | 
| 323 | 315 | 
| 324     // The owning DrawingBuffer. Note that DrawingBuffer is explicitly destroyed | 316     // The owning DrawingBuffer. Note that DrawingBuffer is explicitly destroyed | 
| 325     // by the beginDestruction method, which will eventually drain all of its | 317     // by the beginDestruction method, which will eventually drain all of its | 
| 326     // ColorBuffers. | 318     // ColorBuffers. | 
| 327     RefPtr<DrawingBuffer> drawingBuffer; | 319     RefPtr<DrawingBuffer> drawingBuffer; | 
| 328 | 320 | 
| 329     const TextureParameters parameters; | 321     const ColorBufferParameters parameters; | 
| 330     const IntSize size; | 322     const IntSize size; | 
| 331 | 323 | 
| 332     GLuint textureId = 0; | 324     const GLuint textureId = 0; | 
| 333     GLuint imageId = 0; | 325     const GLuint imageId = 0; | 
| 334 | 326 | 
| 335     // The mailbox used to send this buffer to the compositor. | 327     // The mailbox used to send this buffer to the compositor. | 
| 336     gpu::Mailbox mailbox; | 328     gpu::Mailbox mailbox; | 
| 337 | 329 | 
| 338     // The sync token for when this buffer was sent to the compositor. | 330     // The sync token for when this buffer was sent to the compositor. | 
| 339     gpu::SyncToken produceSyncToken; | 331     gpu::SyncToken produceSyncToken; | 
| 340 | 332 | 
| 341     // The sync token for when this buffer was received back from the | 333     // The sync token for when this buffer was received back from the | 
| 342     // compositor. | 334     // compositor. | 
| 343     gpu::SyncToken receiveSyncToken; | 335     gpu::SyncToken receiveSyncToken; | 
| 344 | 336 | 
| 345    private: | 337    private: | 
| 346     WTF_MAKE_NONCOPYABLE(ColorBuffer); | 338     WTF_MAKE_NONCOPYABLE(ColorBuffer); | 
| 347   }; | 339   }; | 
| 348 | 340 | 
|  | 341   // The same as clearFramebuffers(), but leaves GL state dirty. | 
|  | 342   void clearFramebuffersInternal(GLbitfield clearMask); | 
|  | 343 | 
|  | 344   // The same as reset(), but leaves GL state dirty. | 
|  | 345   bool resizeFramebufferInternal(const IntSize&); | 
|  | 346 | 
|  | 347   // The same as commit(), but leaves GL state dirty. | 
|  | 348   void resolveMultisampleFramebufferInternal(); | 
|  | 349 | 
| 349   bool prepareTextureMailboxInternal( | 350   bool prepareTextureMailboxInternal( | 
| 350       cc::TextureMailbox* outMailbox, | 351       cc::TextureMailbox* outMailbox, | 
| 351       std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback, | 352       std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback, | 
| 352       bool forceGpuResult); | 353       bool forceGpuResult); | 
| 353 | 354 | 
| 354   // Callbacks for mailboxes given to the compositor from PrepareTextureMailbox. | 355   // Helper functions to be called only by prepareTextureMailboxInternal. | 
| 355   void gpuMailboxReleased(RefPtr<ColorBuffer>, | 356   bool finishPrepareTextureMailboxGpu( | 
|  | 357       cc::TextureMailbox* outMailbox, | 
|  | 358       std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback); | 
|  | 359   bool finishPrepareTextureMailboxSoftware( | 
|  | 360       cc::TextureMailbox* outMailbox, | 
|  | 361       std::unique_ptr<cc::SingleReleaseCallback>* outReleaseCallback); | 
|  | 362 | 
|  | 363   // Callbacks for mailboxes given to the compositor from | 
|  | 364   // finishPrepareTextureMailboxGpu and finishPrepareTextureMailboxSoftware. | 
|  | 365   void mailboxReleasedGpu(RefPtr<ColorBuffer>, | 
| 356                           const gpu::SyncToken&, | 366                           const gpu::SyncToken&, | 
| 357                           bool lostResource); | 367                           bool lostResource); | 
| 358   void softwareMailboxReleased(std::unique_ptr<cc::SharedBitmap>, | 368   void mailboxReleasedSoftware(std::unique_ptr<cc::SharedBitmap>, | 
| 359                                const IntSize&, | 369                                const IntSize&, | 
| 360                                const gpu::SyncToken&, | 370                                const gpu::SyncToken&, | 
| 361                                bool lostResource); | 371                                bool lostResource); | 
| 362 | 372 | 
| 363   // The texture parameters to use for a texture that will be backed by a | 373   // The texture parameters to use for a texture that will be backed by a | 
| 364   // CHROMIUM_image. | 374   // CHROMIUM_image, backed by a GpuMemoryBuffer. | 
| 365   TextureParameters chromiumImageTextureParameters(); | 375   ColorBufferParameters gpuMemoryBufferColorBufferParameters(); | 
| 366 | 376 | 
| 367   // The texture parameters to use for a default texture. | 377   // The texture parameters to use for an ordinary GL texture. | 
| 368   TextureParameters defaultTextureParameters(); | 378   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 | 379 | 
| 375   // Attempts to allocator storage for, or resize all buffers. Returns whether | 380   // Attempts to allocator storage for, or resize all buffers. Returns whether | 
| 376   // the operation was successful. | 381   // the operation was successful. | 
| 377   bool resizeDefaultFramebuffer(const IntSize&); | 382   bool resizeDefaultFramebuffer(const IntSize&); | 
| 378 | 383 | 
| 379   void clearPlatformLayer(); | 384   void clearPlatformLayer(); | 
| 380 | 385 | 
| 381   PassRefPtr<ColorBuffer> takeRecycledMailbox(); |  | 
| 382 |  | 
| 383   std::unique_ptr<cc::SharedBitmap> createOrRecycleBitmap(); | 386   std::unique_ptr<cc::SharedBitmap> createOrRecycleBitmap(); | 
| 384 | 387 | 
| 385   // Updates the current size of the buffer, ensuring that | 388   // Updates the current size of the buffer, ensuring that | 
| 386   // s_currentResourceUsePixels is updated. | 389   // s_currentResourceUsePixels is updated. | 
| 387   void setSize(const IntSize& size); | 390   void setSize(const IntSize& size); | 
| 388 | 391 | 
| 389   // This is the order of bytes to use when doing a readback. | 392   // This is the order of bytes to use when doing a readback. | 
| 390   enum ReadbackOrder { ReadbackRGBA, ReadbackSkia }; | 393   enum ReadbackOrder { ReadbackRGBA, ReadbackSkia }; | 
| 391 | 394 | 
| 392   // Helper function which does a readback from the currently-bound | 395   // Helper function which does a readback from the currently-bound | 
| 393   // framebuffer into a buffer of a certain size with 4-byte pixels. | 396   // framebuffer into a buffer of a certain size with 4-byte pixels. | 
| 394   void readBackFramebuffer(unsigned char* pixels, | 397   void readBackFramebuffer(unsigned char* pixels, | 
| 395                            int width, | 398                            int width, | 
| 396                            int height, | 399                            int height, | 
| 397                            ReadbackOrder, | 400                            ReadbackOrder, | 
| 398                            WebGLImageConversion::AlphaOp); | 401                            WebGLImageConversion::AlphaOp); | 
| 399 | 402 | 
| 400   // Helper function to flip a bitmap vertically. | 403   // Helper function to flip a bitmap vertically. | 
| 401   void flipVertically(uint8_t* data, int width, int height); | 404   void flipVertically(uint8_t* data, int width, int height); | 
| 402 | 405 | 
| 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 | 406   // 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 | 407   // must be immediately cleared after it is bound to a texture. Nothing | 
| 415   // should be allowed to change the alpha channel after this. | 408   // should be allowed to change the alpha channel after this. | 
| 416   void clearChromiumImageAlpha(const ColorBuffer&); | 409   void clearChromiumImageAlpha(const ColorBuffer&); | 
| 417 | 410 | 
| 418   // Tries to create a CHROMIUM_image backed texture if | 411   // Tries to create a CHROMIUM_image backed texture if | 
| 419   // RuntimeEnabledFeatures::webGLImageChromiumEnabled() is true. On failure, | 412   // RuntimeEnabledFeatures::webGLImageChromiumEnabled() is true. On failure, | 
| 420   // or if the flag is false, creates a default texture. | 413   // or if the flag is false, creates a default texture. Always returns a valid | 
| 421   RefPtr<ColorBuffer> createTextureAndAllocateMemory(const IntSize&); | 414   // ColorBuffer. | 
|  | 415   RefPtr<ColorBuffer> createColorBuffer(const IntSize&); | 
| 422 | 416 | 
| 423   // Creates and allocates space for a default texture. | 417   // Creates or recycles a ColorBuffer of size |m_size|. | 
| 424   RefPtr<ColorBuffer> createDefaultTextureAndAllocateMemory(const IntSize&); | 418   PassRefPtr<ColorBuffer> createOrRecycleColorBuffer(); | 
| 425 | 419 | 
| 426   // Attaches |m_backColorBuffer| to |m_fbo|, which is always the source for | 420   // Attaches |m_backColorBuffer| to |m_fbo|, which is always the source for | 
| 427   // read operations. | 421   // read operations. | 
| 428   void attachColorBufferToReadFramebuffer(); | 422   void attachColorBufferToReadFramebuffer(); | 
| 429 | 423 | 
| 430   // Whether the WebGL client desires an explicit resolve. This is | 424   // Whether the WebGL client desires an explicit resolve. This is | 
| 431   // implemented by forwarding all draw operations to a multisample | 425   // implemented by forwarding all draw operations to a multisample | 
| 432   // renderbuffer, which is resolved before any read operations or swaps. | 426   // renderbuffer, which is resolved before any read operations or swaps. | 
| 433   bool wantExplicitResolve(); | 427   bool wantExplicitResolve(); | 
| 434 | 428 | 
| 435   // Whether the WebGL client wants a depth or stencil buffer. | 429   // Whether the WebGL client wants a depth or stencil buffer. | 
| 436   bool wantDepthOrStencil(); | 430   bool wantDepthOrStencil(); | 
| 437 | 431 | 
| 438   // The format to use when creating a multisampled renderbuffer. | 432   // The format to use when creating a multisampled renderbuffer. | 
| 439   GLenum getMultisampledRenderbufferFormat(); | 433   GLenum getMultisampledRenderbufferFormat(); | 
| 440 | 434 | 
|  | 435   // Weak, reset by beginDestruction. | 
|  | 436   DrawingBufferStateTracker* m_stateTracker = nullptr; | 
|  | 437 | 
| 441   const PreserveDrawingBuffer m_preserveDrawingBuffer; | 438   const PreserveDrawingBuffer m_preserveDrawingBuffer; | 
| 442   const WebGLVersion m_webGLVersion; | 439   const WebGLVersion m_webGLVersion; | 
| 443   bool m_scissorEnabled = false; |  | 
| 444   GLuint m_texture2DBinding = 0; |  | 
| 445   GLuint m_pixelUnpackBufferBinding = 0; |  | 
| 446   GLuint m_drawFramebufferBinding = 0; |  | 
| 447   GLuint m_readFramebufferBinding = 0; |  | 
| 448   GLuint m_renderbufferBinding = 0; |  | 
| 449   GLenum m_activeTextureUnit = GL_TEXTURE0; |  | 
| 450   GLfloat m_clearColor[4]; |  | 
| 451   GLboolean m_colorMask[4]; |  | 
| 452 | 440 | 
| 453   std::unique_ptr<WebGraphicsContext3DProvider> m_contextProvider; | 441   std::unique_ptr<WebGraphicsContext3DProvider> m_contextProvider; | 
| 454   // Lifetime is tied to the m_contextProvider. | 442   // Lifetime is tied to the m_contextProvider. | 
| 455   gpu::gles2::GLES2Interface* m_gl; | 443   gpu::gles2::GLES2Interface* m_gl; | 
| 456   std::unique_ptr<Extensions3DUtil> m_extensionsUtil; | 444   std::unique_ptr<Extensions3DUtil> m_extensionsUtil; | 
| 457   IntSize m_size = {-1, -1}; | 445   IntSize m_size = {-1, -1}; | 
| 458   const bool m_discardFramebufferSupported; | 446   const bool m_discardFramebufferSupported; | 
| 459   const bool m_wantAlphaChannel; | 447   const bool m_wantAlphaChannel; | 
| 460   const bool m_premultipliedAlpha; | 448   const bool m_premultipliedAlpha; | 
| 461   const bool m_softwareRendering; | 449   const bool m_softwareRendering; | 
| 462   bool m_hasImplicitStencilBuffer = false; | 450   bool m_hasImplicitStencilBuffer = false; | 
| 463   bool m_storageTextureSupported = false; | 451   bool m_storageTextureSupported = false; | 
| 464 | 452 | 
| 465   // This is the ColorBuffer that was most recently presented to the compositor | 453   std::unique_ptr<WTF::Closure> m_newMailboxCallback; | 
| 466   // by prepareTextureMailboxInternal. |  | 
| 467   RefPtr<ColorBuffer> m_frontColorBuffer; |  | 
| 468 | 454 | 
| 469   std::unique_ptr<WTF::Closure> m_newMailboxCallback; | 455   // The current state restorer, which is used to track state dirtying. It is in | 
|  | 456   // error to dirty state shared with WebGL while there is no existing state | 
|  | 457   // restorer. It is also in error to instantiate two state restorers at once. | 
|  | 458   ScopedStateRestorer* m_stateRestorer = nullptr; | 
| 470 | 459 | 
| 471   // This is used when the user requests either a depth or stencil buffer. | 460   // This is used when the user requests either a depth or stencil buffer. | 
| 472   GLuint m_depthStencilBuffer = 0; | 461   GLuint m_depthStencilBuffer = 0; | 
| 473 | 462 | 
| 474   // When wantExplicitResolve() returns true, the target of all draw | 463   // When wantExplicitResolve() returns true, the target of all draw | 
| 475   // operations. | 464   // operations. | 
| 476   GLuint m_multisampleFBO = 0; | 465   GLuint m_multisampleFBO = 0; | 
| 477 | 466 | 
| 478   // The id of the renderbuffer storage for |m_multisampleFBO|. | 467   // The id of the renderbuffer storage for |m_multisampleFBO|. | 
| 479   GLuint m_multisampleRenderbuffer = 0; | 468   GLuint m_multisampleRenderbuffer = 0; | 
| 480 | 469 | 
| 481   // When wantExplicitResolve() returns false, the target of all draw and | 470   // When wantExplicitResolve() returns false, the target of all draw and | 
| 482   // read operations. When wantExplicitResolve() returns true, the target of | 471   // read operations. When wantExplicitResolve() returns true, the target of | 
| 483   // all read operations. A swap is performed by exchanging |m_backColorBuffer| | 472   // all read operations. | 
| 484   // with |m_frontColorBuffer|. |  | 
| 485   GLuint m_fbo = 0; | 473   GLuint m_fbo = 0; | 
| 486 | 474 | 
| 487   // All information about the texture storage for |m_fbo|. | 475   // The ColorBuffer that backs |m_fbo|. | 
| 488   RefPtr<ColorBuffer> m_backColorBuffer; | 476   RefPtr<ColorBuffer> m_backColorBuffer; | 
| 489 | 477 | 
|  | 478   // The ColorBuffer that was most recently presented to the compositor by | 
|  | 479   // prepareTextureMailboxInternal. | 
|  | 480   RefPtr<ColorBuffer> m_frontColorBuffer; | 
|  | 481 | 
| 490   // True if our contents have been modified since the last presentation of this | 482   // True if our contents have been modified since the last presentation of this | 
| 491   // buffer. | 483   // buffer. | 
| 492   bool m_contentsChanged = true; | 484   bool m_contentsChanged = true; | 
| 493 | 485 | 
| 494   // True if commit() has been called since the last time markContentsChanged() | 486   // True if commit() has been called since the last time markContentsChanged() | 
| 495   // had been called. | 487   // had been called. | 
| 496   bool m_contentsChangeCommitted = false; | 488   bool m_contentsChangeCommitted = false; | 
| 497   bool m_bufferClearNeeded = false; | 489   bool m_bufferClearNeeded = false; | 
| 498 | 490 | 
| 499   // Whether the client wants a depth or stencil buffer. | 491   // Whether the client wants a depth or stencil buffer. | 
| 500   const bool m_wantDepth; | 492   const bool m_wantDepth; | 
| 501   const bool m_wantStencil; | 493   const bool m_wantStencil; | 
| 502 | 494 | 
| 503   enum AntialiasingMode { | 495   enum AntialiasingMode { | 
| 504     None, | 496     None, | 
| 505     MSAAImplicitResolve, | 497     MSAAImplicitResolve, | 
| 506     MSAAExplicitResolve, | 498     MSAAExplicitResolve, | 
| 507     ScreenSpaceAntialiasing, | 499     ScreenSpaceAntialiasing, | 
| 508   }; | 500   }; | 
| 509 | 501 | 
| 510   AntialiasingMode m_antiAliasingMode = None; | 502   AntialiasingMode m_antiAliasingMode = None; | 
| 511 | 503 | 
| 512   int m_maxTextureSize = 0; | 504   int m_maxTextureSize = 0; | 
| 513   int m_sampleCount = 0; | 505   int m_sampleCount = 0; | 
| 514   int m_packAlignment = 4; |  | 
| 515   bool m_destructionInProgress = false; | 506   bool m_destructionInProgress = false; | 
| 516   bool m_isHidden = false; | 507   bool m_isHidden = false; | 
| 517   SkFilterQuality m_filterQuality = kLow_SkFilterQuality; | 508   SkFilterQuality m_filterQuality = kLow_SkFilterQuality; | 
| 518 | 509 | 
| 519   std::unique_ptr<WebExternalTextureLayer> m_layer; | 510   std::unique_ptr<WebExternalTextureLayer> m_layer; | 
| 520 | 511 | 
| 521   // Mailboxes that were released by the compositor can be used again by this | 512   // Mailboxes that were released by the compositor can be used again by this | 
| 522   // DrawingBuffer. | 513   // DrawingBuffer. | 
| 523   Deque<RefPtr<ColorBuffer>> m_recycledMailboxQueue; | 514   Deque<RefPtr<ColorBuffer>> m_recycledColorBufferQueue; | 
| 524 | 515 | 
| 525   // If the width and height of the Canvas's backing store don't | 516   // 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 | 517   // match those that we were given in the most recent call to | 
| 527   // reshape(), then we need an intermediate bitmap to read back the | 518   // reshape(), then we need an intermediate bitmap to read back the | 
| 528   // frame buffer into. This seems to happen when CSS styles are | 519   // frame buffer into. This seems to happen when CSS styles are | 
| 529   // used to resize the Canvas. | 520   // used to resize the Canvas. | 
| 530   SkBitmap m_resizingBitmap; | 521   SkBitmap m_resizingBitmap; | 
| 531 | 522 | 
| 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 | 523   // In the case of OffscreenCanvas, we do not want to enable the | 
| 536   // WebGLImageChromium flag, so we replace all the | 524   // WebGLImageChromium flag, so we replace all the | 
| 537   // RuntimeEnabledFeatures::webGLImageChromiumEnabled() call with | 525   // RuntimeEnabledFeatures::webGLImageChromiumEnabled() call with | 
| 538   // shouldUseChromiumImage() calls, and set m_chromiumImageUsage to | 526   // shouldUseChromiumImage() calls, and set m_chromiumImageUsage to | 
| 539   // DisallowChromiumImage in the case of OffscreenCanvas. | 527   // DisallowChromiumImage in the case of OffscreenCanvas. | 
| 540   ChromiumImageUsage m_chromiumImageUsage; | 528   ChromiumImageUsage m_chromiumImageUsage; | 
| 541   bool shouldUseChromiumImage(); | 529   bool shouldUseChromiumImage(); | 
| 542 }; | 530 }; | 
| 543 | 531 | 
| 544 }  // namespace blink | 532 }  // namespace blink | 
| 545 | 533 | 
| 546 #endif  // DrawingBuffer_h | 534 #endif  // DrawingBuffer_h | 
| OLD | NEW | 
|---|