Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/gpu/DrawingBuffer.h

Issue 1852533002: Remove alpha/depth/stencil/antialias from WGC3D::Attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@premul
Patch Set: rm-alphadepthetc: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ ish its rendering 69 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ ish its rendering
70 // results to a WebLayer for compositing. 70 // results to a WebLayer for compositing.
71 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public W ebExternalTextureLayerClient { 71 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public W ebExternalTextureLayerClient {
72 WTF_MAKE_NONCOPYABLE(DrawingBuffer); 72 WTF_MAKE_NONCOPYABLE(DrawingBuffer);
73 public: 73 public:
74 enum PreserveDrawingBuffer { 74 enum PreserveDrawingBuffer {
75 Preserve, 75 Preserve,
76 Discard 76 Discard
77 }; 77 };
78 78
79 static PassRefPtr<DrawingBuffer> create(PassOwnPtr<WebGraphicsContext3DProvi der>, const IntSize&, bool premultipliedAlpha, PreserveDrawingBuffer, WebGraphic sContext3D::Attributes requestedAttributes); 79 static PassRefPtr<DrawingBuffer> create(
80 PassOwnPtr<WebGraphicsContext3DProvider>,
81 const IntSize&,
82 bool premultipliedAlpha,
83 bool wantAlphaChannel,
84 bool wantDepthBuffer,
85 bool wantStencilBuffer,
86 bool wantAntialiasing,
87 PreserveDrawingBuffer);
80 static void forceNextDrawingBufferCreationToFail(); 88 static void forceNextDrawingBufferCreationToFail();
81 89
82 ~DrawingBuffer() override; 90 ~DrawingBuffer() override;
83 91
84 // Destruction will be completed after all mailboxes are released. 92 // Destruction will be completed after all mailboxes are released.
85 void beginDestruction(); 93 void beginDestruction();
86 94
87 // Issues a glClear() on all framebuffers associated with this DrawingBuffer . The caller is responsible for 95 // Issues a glClear() on all framebuffers associated with this DrawingBuffer . The caller is responsible for
88 // making the context current and setting the clear values and masks. Modifi es the framebuffer binding. 96 // making the context current and setting the clear values and masks. Modifi es the framebuffer binding.
89 void clearFramebuffers(GLbitfield clearMask); 97 void clearFramebuffers(GLbitfield clearMask);
90 98
91 // Indicates whether the DrawingBuffer internally allocated a packed depth-s tencil renderbuffer 99 // Indicates whether the DrawingBuffer internally allocated a packed depth-s tencil renderbuffer
92 // in the situation where the end user only asked for a depth buffer. In thi s case, we need to 100 // in the situation where the end user only asked for a depth buffer. In thi s case, we need to
93 // upgrade clears of the depth buffer to clears of the depth and stencil buf fers in order to 101 // upgrade clears of the depth buffer to clears of the depth and stencil buf fers in order to
94 // avoid performance problems on some GPUs. 102 // avoid performance problems on some GPUs.
95 bool hasImplicitStencilBuffer() const; 103 bool hasImplicitStencilBuffer() const { return m_hasImplicitStencilBuffer; }
96 104
97 // Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget. 105 // Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget.
98 static IntSize adjustSize(const IntSize& desiredSize, const IntSize& curSize , int maxTextureSize); 106 static IntSize adjustSize(const IntSize& desiredSize, const IntSize& curSize , int maxTextureSize);
99 bool reset(const IntSize&); 107 bool reset(const IntSize&, bool wantDepthOrStencilBuffer);
100 void bind(GLenum target); 108 void bind(GLenum target);
101 IntSize size() const { return m_size; } 109 IntSize size() const { return m_size; }
102 110
103 // Copies the multisample color buffer to the normal color buffer and leaves m_fbo bound. 111 // Copies the multisample color buffer to the normal color buffer and leaves m_fbo bound.
104 void commit(); 112 void commit();
105 113
106 // commit should copy the full multisample buffer, and not respect the 114 // commit should copy the full multisample buffer, and not respect the
107 // current scissor bounds. Track the state of the scissor test so that it 115 // current scissor bounds. Track the state of the scissor test so that it
108 // can be disabled during calls to commit. 116 // can be disabled during calls to commit.
109 void setScissorEnabled(bool scissorEnabled) { m_scissorEnabled = scissorEnab led; } 117 void setScissorEnabled(bool scissorEnabled) { m_scissorEnabled = scissorEnab led; }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 bool bufferClearNeeded() const; 155 bool bufferClearNeeded() const;
148 void setIsHidden(bool); 156 void setIsHidden(bool);
149 void setFilterQuality(SkFilterQuality); 157 void setFilterQuality(SkFilterQuality);
150 158
151 WebLayer* platformLayer(); 159 WebLayer* platformLayer();
152 160
153 WebGraphicsContext3D* context(); 161 WebGraphicsContext3D* context();
154 gpu::gles2::GLES2Interface* contextGL(); 162 gpu::gles2::GLES2Interface* contextGL();
155 WebGraphicsContext3DProvider* contextProvider(); 163 WebGraphicsContext3DProvider* contextProvider();
156 164
157 // Returns the actual context attributes for this drawing buffer which may d iffer from the 165 bool hasDepthBuffer() const { return m_hasDepthBuffer; }
158 // requested context attributes due to implementation limits. 166 bool hasStencilBuffer() const { return m_hasStencilBuffer; }
159 WebGraphicsContext3D::Attributes getActualAttributes() const { return m_actu alAttributes; }
160 167
161 // WebExternalTextureLayerClient implementation. 168 // WebExternalTextureLayerClient implementation.
162 bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*) override ; 169 bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*) override ;
163 void mailboxReleased(const WebExternalTextureMailbox&, bool lostResource = f alse) override; 170 void mailboxReleased(const WebExternalTextureMailbox&, bool lostResource = f alse) override;
164 171
165 // Destroys the TEXTURE_2D binding for the owned context 172 // Destroys the TEXTURE_2D binding for the owned context
166 bool copyToPlatformTexture(WebGraphicsContext3D*, gpu::gles2::GLES2Interface *, GLuint texture, GLenum internalFormat, 173 bool copyToPlatformTexture(WebGraphicsContext3D*, gpu::gles2::GLES2Interface *, GLuint texture, GLenum internalFormat,
167 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceD rawingBuffer); 174 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceD rawingBuffer);
168 175
169 void setPackAlignment(GLint param); 176 void setPackAlignment(GLint param);
170 177
171 bool paintRenderingResultsToImageData(int&, int&, SourceDrawingBuffer, WTF:: ArrayBufferContents&); 178 bool paintRenderingResultsToImageData(int&, int&, SourceDrawingBuffer, WTF:: ArrayBufferContents&);
172 179
173 int sampleCount() const { return m_sampleCount; } 180 int sampleCount() const { return m_sampleCount; }
174 bool explicitResolveOfMultisampleData() const { return m_antiAliasingMode == MSAAExplicitResolve; } 181 bool explicitResolveOfMultisampleData() const { return m_antiAliasingMode == MSAAExplicitResolve; }
175 182
176 // Bind to m_drawFramebufferBinding or m_readFramebufferBinding if it's not 0. 183 // Bind to m_drawFramebufferBinding or m_readFramebufferBinding if it's not 0.
177 // Otherwise, bind to the default FBO. 184 // Otherwise, bind to the default FBO.
178 void restoreFramebufferBindings(); 185 void restoreFramebufferBindings();
179 186
180 void addNewMailboxCallback(PassOwnPtr<SameThreadClosure> closure) { m_newMai lboxCallback = std::move(closure); } 187 void addNewMailboxCallback(PassOwnPtr<SameThreadClosure> closure) { m_newMai lboxCallback = std::move(closure); }
181 188
182 protected: // For unittests 189 protected: // For unittests
183 DrawingBuffer( 190 DrawingBuffer(
184 PassOwnPtr<WebGraphicsContext3DProvider>, 191 PassOwnPtr<WebGraphicsContext3DProvider>,
185 PassOwnPtr<Extensions3DUtil>, 192 PassOwnPtr<Extensions3DUtil>,
186 bool multisampleExtensionSupported,
187 bool discardFramebufferSupported, 193 bool discardFramebufferSupported,
194 bool wantAlphaChannel,
188 bool premultipliedAlpha, 195 bool premultipliedAlpha,
189 PreserveDrawingBuffer, 196 PreserveDrawingBuffer);
190 WebGraphicsContext3D::Attributes requestedAttributes);
191 197
192 bool initialize(const IntSize&); 198 bool initialize(const IntSize&, bool wantDepthBuffer, bool wantStencilBuffer , bool multisampleExtensionSupported);
193 199
194 private: 200 private:
195 struct TextureParameters { 201 struct TextureParameters {
196 DISALLOW_NEW(); 202 DISALLOW_NEW();
197 GLenum target; 203 GLenum target;
198 GLenum internalColorFormat; 204 GLenum internalColorFormat;
199 GLenum colorFormat; 205 GLenum colorFormat;
200 GLenum internalRenderbufferFormat; 206 GLenum internalRenderbufferFormat;
201 207
202 TextureParameters() 208 TextureParameters()
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 253
248 void mailboxReleasedWithoutRecycling(const WebExternalTextureMailbox&); 254 void mailboxReleasedWithoutRecycling(const WebExternalTextureMailbox&);
249 255
250 // Creates and binds a texture with the given parameters. Returns 0 on 256 // Creates and binds a texture with the given parameters. Returns 0 on
251 // failure, or the newly created texture id on success. The caller takes 257 // failure, or the newly created texture id on success. The caller takes
252 // ownership of the newly created texture. 258 // ownership of the newly created texture.
253 GLuint createColorTexture(const TextureParameters&); 259 GLuint createColorTexture(const TextureParameters&);
254 260
255 // Create the depth/stencil and multisample buffers, if needed. 261 // Create the depth/stencil and multisample buffers, if needed.
256 void createSecondaryBuffers(); 262 void createSecondaryBuffers();
257 bool resizeFramebuffer(const IntSize&); 263 bool resizeFramebuffer(const IntSize&, bool wantDepthOrStencilBuffer);
258 bool resizeMultisampleFramebuffer(const IntSize&); 264 bool resizeMultisampleFramebuffer(const IntSize&, bool wantDepthOrStencilBuf fer);
259 void resizeDepthStencil(const IntSize&); 265 void resizeDepthStencil(const IntSize&);
260 266
261 void clearPlatformLayer(); 267 void clearPlatformLayer();
262 268
263 PassRefPtr<MailboxInfo> recycledMailbox(); 269 PassRefPtr<MailboxInfo> recycledMailbox();
264 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&); 270 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&);
265 void deleteMailbox(const WebExternalTextureMailbox&); 271 void deleteMailbox(const WebExternalTextureMailbox&);
266 void freeRecycledMailboxes(); 272 void freeRecycledMailboxes();
267 273
268 // Updates the current size of the buffer, ensuring that s_currentResourceUs ePixels is updated. 274 // Updates the current size of the buffer, ensuring that s_currentResourceUs ePixels is updated.
(...skipping 23 matching lines...) Expand all
292 // or if the flag is false, creates a default texture. 298 // or if the flag is false, creates a default texture.
293 TextureInfo createTextureAndAllocateMemory(const IntSize&); 299 TextureInfo createTextureAndAllocateMemory(const IntSize&);
294 300
295 // Creates and allocates space for a default texture. 301 // Creates and allocates space for a default texture.
296 TextureInfo createDefaultTextureAndAllocateMemory(const IntSize&); 302 TextureInfo createDefaultTextureAndAllocateMemory(const IntSize&);
297 303
298 void resizeTextureMemory(TextureInfo*, const IntSize&); 304 void resizeTextureMemory(TextureInfo*, const IntSize&);
299 305
300 void attachColorBufferToCurrentFBO(); 306 void attachColorBufferToCurrentFBO();
301 307
302 PreserveDrawingBuffer m_preserveDrawingBuffer; 308 const PreserveDrawingBuffer m_preserveDrawingBuffer;
303 bool m_scissorEnabled; 309 bool m_scissorEnabled;
304 GLuint m_texture2DBinding; 310 GLuint m_texture2DBinding;
305 GLuint m_drawFramebufferBinding; 311 GLuint m_drawFramebufferBinding;
306 GLuint m_readFramebufferBinding; 312 GLuint m_readFramebufferBinding;
307 GLenum m_activeTextureUnit; 313 GLenum m_activeTextureUnit;
308 314
309 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; 315 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider;
310 WebGraphicsContext3D* m_context; // Lifetime is tied to the m_contextProvide r. 316 WebGraphicsContext3D* m_context; // Lifetime is tied to the m_contextProvide r.
311 gpu::gles2::GLES2Interface* m_gl; // Lifetime is tied to the m_contextProvid er. 317 gpu::gles2::GLES2Interface* m_gl; // Lifetime is tied to the m_contextProvid er.
312 OwnPtr<Extensions3DUtil> m_extensionsUtil; 318 OwnPtr<Extensions3DUtil> m_extensionsUtil;
313 IntSize m_size; 319 IntSize m_size;
314 WebGraphicsContext3D::Attributes m_requestedAttributes; 320 const bool m_discardFramebufferSupported;
315 bool m_multisampleExtensionSupported; 321 const bool m_wantAlphaChannel;
316 bool m_discardFramebufferSupported; 322 const bool m_premultipliedAlpha;
317 bool m_premultipliedAlpha; 323 bool m_hasDepthBuffer;
324 bool m_hasStencilBuffer;
325 bool m_hasImplicitStencilBuffer;
318 GLuint m_fbo; 326 GLuint m_fbo;
319 // DrawingBuffer's output is double-buffered. m_colorBuffer is the back buff er. 327 // DrawingBuffer's output is double-buffered. m_colorBuffer is the back buff er.
320 TextureInfo m_colorBuffer; 328 TextureInfo m_colorBuffer;
321 struct FrontBufferInfo { 329 struct FrontBufferInfo {
322 TextureInfo texInfo; 330 TextureInfo texInfo;
323 WebExternalTextureMailbox mailbox; 331 WebExternalTextureMailbox mailbox;
324 }; 332 };
325 FrontBufferInfo m_frontColorBuffer; 333 FrontBufferInfo m_frontColorBuffer;
326 334
327 OwnPtr<SameThreadClosure> m_newMailboxCallback; 335 OwnPtr<SameThreadClosure> m_newMailboxCallback;
(...skipping 14 matching lines...) Expand all
342 350
343 enum AntialiasingMode { 351 enum AntialiasingMode {
344 None, 352 None,
345 MSAAImplicitResolve, 353 MSAAImplicitResolve,
346 MSAAExplicitResolve, 354 MSAAExplicitResolve,
347 ScreenSpaceAntialiasing, 355 ScreenSpaceAntialiasing,
348 }; 356 };
349 357
350 AntialiasingMode m_antiAliasingMode; 358 AntialiasingMode m_antiAliasingMode;
351 359
352 WebGraphicsContext3D::Attributes m_actualAttributes;
353 int m_maxTextureSize; 360 int m_maxTextureSize;
354 int m_sampleCount; 361 int m_sampleCount;
355 int m_packAlignment; 362 int m_packAlignment;
356 bool m_destructionInProgress; 363 bool m_destructionInProgress;
357 bool m_isHidden; 364 bool m_isHidden;
358 SkFilterQuality m_filterQuality; 365 SkFilterQuality m_filterQuality;
359 366
360 OwnPtr<WebExternalTextureLayer> m_layer; 367 OwnPtr<WebExternalTextureLayer> m_layer;
361 368
362 // All of the mailboxes that this DrawingBuffer has ever created. 369 // All of the mailboxes that this DrawingBuffer has ever created.
363 Vector<RefPtr<MailboxInfo>> m_textureMailboxes; 370 Vector<RefPtr<MailboxInfo>> m_textureMailboxes;
364 // Mailboxes that were released by the compositor can be used again by this DrawingBuffer. 371 // Mailboxes that were released by the compositor can be used again by this DrawingBuffer.
365 Deque<WebExternalTextureMailbox> m_recycledMailboxQueue; 372 Deque<WebExternalTextureMailbox> m_recycledMailboxQueue;
366 373
367 // If the width and height of the Canvas's backing store don't 374 // If the width and height of the Canvas's backing store don't
368 // match those that we were given in the most recent call to 375 // match those that we were given in the most recent call to
369 // reshape(), then we need an intermediate bitmap to read back the 376 // reshape(), then we need an intermediate bitmap to read back the
370 // frame buffer into. This seems to happen when CSS styles are 377 // frame buffer into. This seems to happen when CSS styles are
371 // used to resize the Canvas. 378 // used to resize the Canvas.
372 SkBitmap m_resizingBitmap; 379 SkBitmap m_resizingBitmap;
373 380
374 // Used to flip a bitmap vertically. 381 // Used to flip a bitmap vertically.
375 Vector<uint8_t> m_scanline; 382 Vector<uint8_t> m_scanline;
376 }; 383 };
377 384
378 } // namespace blink 385 } // namespace blink
379 386
380 #endif // DrawingBuffer_h 387 #endif // DrawingBuffer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698