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

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: renamevar 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; }
104 bool hasDepthBuffer() const { return !!m_depthStencilBuffer; }
105 bool hasStencilBuffer() const { return !!m_depthStencilBuffer; }
96 106
97 // Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget. 107 // 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); 108 static IntSize adjustSize(const IntSize& desiredSize, const IntSize& curSize , int maxTextureSize);
99 bool reset(const IntSize&); 109 bool reset(const IntSize&, bool wantDepthOrStencilBuffer);
100 void bind(GLenum target); 110 void bind(GLenum target);
101 IntSize size() const { return m_size; } 111 IntSize size() const { return m_size; }
102 112
103 // Copies the multisample color buffer to the normal color buffer and leaves m_fbo bound. 113 // Copies the multisample color buffer to the normal color buffer and leaves m_fbo bound.
104 void commit(); 114 void commit();
105 115
106 // commit should copy the full multisample buffer, and not respect the 116 // 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 117 // current scissor bounds. Track the state of the scissor test so that it
108 // can be disabled during calls to commit. 118 // can be disabled during calls to commit.
109 void setScissorEnabled(bool scissorEnabled) { m_scissorEnabled = scissorEnab led; } 119 void setScissorEnabled(bool scissorEnabled) { m_scissorEnabled = scissorEnab led; }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 bool bufferClearNeeded() const; 157 bool bufferClearNeeded() const;
148 void setIsHidden(bool); 158 void setIsHidden(bool);
149 void setFilterQuality(SkFilterQuality); 159 void setFilterQuality(SkFilterQuality);
150 160
151 WebLayer* platformLayer(); 161 WebLayer* platformLayer();
152 162
153 WebGraphicsContext3D* context(); 163 WebGraphicsContext3D* context();
154 gpu::gles2::GLES2Interface* contextGL(); 164 gpu::gles2::GLES2Interface* contextGL();
155 WebGraphicsContext3DProvider* contextProvider(); 165 WebGraphicsContext3DProvider* contextProvider();
156 166
157 // Returns the actual context attributes for this drawing buffer which may d iffer from the
158 // requested context attributes due to implementation limits.
159 WebGraphicsContext3D::Attributes getActualAttributes() const { return m_actu alAttributes; }
160
161 // WebExternalTextureLayerClient implementation. 167 // WebExternalTextureLayerClient implementation.
162 bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*) override ; 168 bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*) override ;
163 void mailboxReleased(const WebExternalTextureMailbox&, bool lostResource = f alse) override; 169 void mailboxReleased(const WebExternalTextureMailbox&, bool lostResource = f alse) override;
164 170
165 // Destroys the TEXTURE_2D binding for the owned context 171 // Destroys the TEXTURE_2D binding for the owned context
166 bool copyToPlatformTexture(WebGraphicsContext3D*, gpu::gles2::GLES2Interface *, GLuint texture, GLenum internalFormat, 172 bool copyToPlatformTexture(WebGraphicsContext3D*, gpu::gles2::GLES2Interface *, GLuint texture, GLenum internalFormat,
167 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceD rawingBuffer); 173 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceD rawingBuffer);
168 174
169 void setPackAlignment(GLint param); 175 void setPackAlignment(GLint param);
170 176
171 bool paintRenderingResultsToImageData(int&, int&, SourceDrawingBuffer, WTF:: ArrayBufferContents&); 177 bool paintRenderingResultsToImageData(int&, int&, SourceDrawingBuffer, WTF:: ArrayBufferContents&);
172 178
173 int sampleCount() const { return m_sampleCount; } 179 int sampleCount() const { return m_sampleCount; }
174 bool explicitResolveOfMultisampleData() const { return m_antiAliasingMode == MSAAExplicitResolve; } 180 bool explicitResolveOfMultisampleData() const { return m_antiAliasingMode == MSAAExplicitResolve; }
175 181
176 // Bind to m_drawFramebufferBinding or m_readFramebufferBinding if it's not 0. 182 // Bind to m_drawFramebufferBinding or m_readFramebufferBinding if it's not 0.
177 // Otherwise, bind to the default FBO. 183 // Otherwise, bind to the default FBO.
178 void restoreFramebufferBindings(); 184 void restoreFramebufferBindings();
179 185
180 void addNewMailboxCallback(PassOwnPtr<SameThreadClosure> closure) { m_newMai lboxCallback = std::move(closure); } 186 void addNewMailboxCallback(PassOwnPtr<SameThreadClosure> closure) { m_newMai lboxCallback = std::move(closure); }
181 187
182 protected: // For unittests 188 protected: // For unittests
183 DrawingBuffer( 189 DrawingBuffer(
184 PassOwnPtr<WebGraphicsContext3DProvider>, 190 PassOwnPtr<WebGraphicsContext3DProvider>,
185 PassOwnPtr<Extensions3DUtil>, 191 PassOwnPtr<Extensions3DUtil>,
186 bool multisampleExtensionSupported,
187 bool discardFramebufferSupported, 192 bool discardFramebufferSupported,
193 bool wantAlphaChannel,
188 bool premultipliedAlpha, 194 bool premultipliedAlpha,
189 PreserveDrawingBuffer, 195 PreserveDrawingBuffer);
190 WebGraphicsContext3D::Attributes requestedAttributes);
191 196
192 bool initialize(const IntSize&); 197 bool initialize(const IntSize&, bool wantDepthBuffer, bool wantStencilBuffer , bool useMultisampling);
193 198
194 private: 199 private:
195 struct TextureParameters { 200 struct TextureParameters {
196 DISALLOW_NEW(); 201 DISALLOW_NEW();
197 GLenum target; 202 GLenum target;
198 GLenum internalColorFormat; 203 GLenum internalColorFormat;
199 GLenum colorFormat; 204 GLenum colorFormat;
200 GLenum internalRenderbufferFormat; 205 GLenum internalRenderbufferFormat;
201 206
202 TextureParameters() 207 TextureParameters()
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 252
248 void mailboxReleasedWithoutRecycling(const WebExternalTextureMailbox&); 253 void mailboxReleasedWithoutRecycling(const WebExternalTextureMailbox&);
249 254
250 // Creates and binds a texture with the given parameters. Returns 0 on 255 // 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 256 // failure, or the newly created texture id on success. The caller takes
252 // ownership of the newly created texture. 257 // ownership of the newly created texture.
253 GLuint createColorTexture(const TextureParameters&); 258 GLuint createColorTexture(const TextureParameters&);
254 259
255 // Create the depth/stencil and multisample buffers, if needed. 260 // Create the depth/stencil and multisample buffers, if needed.
256 void createSecondaryBuffers(); 261 void createSecondaryBuffers();
257 bool resizeFramebuffer(const IntSize&); 262 bool resizeFramebuffer(const IntSize&, bool wantDepthOrStencilBuffer);
258 bool resizeMultisampleFramebuffer(const IntSize&); 263 bool resizeMultisampleFramebuffer(const IntSize&, bool wantDepthOrStencilBuf fer);
259 void resizeDepthStencil(const IntSize&); 264 void resizeDepthStencil(const IntSize&);
260 265
261 void clearPlatformLayer(); 266 void clearPlatformLayer();
262 267
263 PassRefPtr<MailboxInfo> recycledMailbox(); 268 PassRefPtr<MailboxInfo> recycledMailbox();
264 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&); 269 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&);
265 void deleteMailbox(const WebExternalTextureMailbox&); 270 void deleteMailbox(const WebExternalTextureMailbox&);
266 void freeRecycledMailboxes(); 271 void freeRecycledMailboxes();
267 272
268 // Updates the current size of the buffer, ensuring that s_currentResourceUs ePixels is updated. 273 // 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. 297 // or if the flag is false, creates a default texture.
293 TextureInfo createTextureAndAllocateMemory(const IntSize&); 298 TextureInfo createTextureAndAllocateMemory(const IntSize&);
294 299
295 // Creates and allocates space for a default texture. 300 // Creates and allocates space for a default texture.
296 TextureInfo createDefaultTextureAndAllocateMemory(const IntSize&); 301 TextureInfo createDefaultTextureAndAllocateMemory(const IntSize&);
297 302
298 void resizeTextureMemory(TextureInfo*, const IntSize&); 303 void resizeTextureMemory(TextureInfo*, const IntSize&);
299 304
300 void attachColorBufferToCurrentFBO(); 305 void attachColorBufferToCurrentFBO();
301 306
302 PreserveDrawingBuffer m_preserveDrawingBuffer; 307 const PreserveDrawingBuffer m_preserveDrawingBuffer;
303 bool m_scissorEnabled; 308 bool m_scissorEnabled;
304 GLuint m_texture2DBinding; 309 GLuint m_texture2DBinding;
305 GLuint m_drawFramebufferBinding; 310 GLuint m_drawFramebufferBinding;
306 GLuint m_readFramebufferBinding; 311 GLuint m_readFramebufferBinding;
307 GLenum m_activeTextureUnit; 312 GLenum m_activeTextureUnit;
308 313
309 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; 314 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider;
310 WebGraphicsContext3D* m_context; // Lifetime is tied to the m_contextProvide r. 315 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. 316 gpu::gles2::GLES2Interface* m_gl; // Lifetime is tied to the m_contextProvid er.
312 OwnPtr<Extensions3DUtil> m_extensionsUtil; 317 OwnPtr<Extensions3DUtil> m_extensionsUtil;
313 IntSize m_size; 318 IntSize m_size;
314 WebGraphicsContext3D::Attributes m_requestedAttributes; 319 const bool m_discardFramebufferSupported;
315 bool m_multisampleExtensionSupported; 320 const bool m_wantAlphaChannel;
316 bool m_discardFramebufferSupported; 321 const bool m_premultipliedAlpha;
317 bool m_premultipliedAlpha; 322 bool m_hasImplicitStencilBuffer;
318 GLuint m_fbo; 323 GLuint m_fbo;
319 // DrawingBuffer's output is double-buffered. m_colorBuffer is the back buff er. 324 // DrawingBuffer's output is double-buffered. m_colorBuffer is the back buff er.
320 TextureInfo m_colorBuffer; 325 TextureInfo m_colorBuffer;
321 struct FrontBufferInfo { 326 struct FrontBufferInfo {
322 TextureInfo texInfo; 327 TextureInfo texInfo;
323 WebExternalTextureMailbox mailbox; 328 WebExternalTextureMailbox mailbox;
324 }; 329 };
325 FrontBufferInfo m_frontColorBuffer; 330 FrontBufferInfo m_frontColorBuffer;
326 331
327 OwnPtr<SameThreadClosure> m_newMailboxCallback; 332 OwnPtr<SameThreadClosure> m_newMailboxCallback;
(...skipping 14 matching lines...) Expand all
342 347
343 enum AntialiasingMode { 348 enum AntialiasingMode {
344 None, 349 None,
345 MSAAImplicitResolve, 350 MSAAImplicitResolve,
346 MSAAExplicitResolve, 351 MSAAExplicitResolve,
347 ScreenSpaceAntialiasing, 352 ScreenSpaceAntialiasing,
348 }; 353 };
349 354
350 AntialiasingMode m_antiAliasingMode; 355 AntialiasingMode m_antiAliasingMode;
351 356
352 WebGraphicsContext3D::Attributes m_actualAttributes;
353 int m_maxTextureSize; 357 int m_maxTextureSize;
354 int m_sampleCount; 358 int m_sampleCount;
355 int m_packAlignment; 359 int m_packAlignment;
356 bool m_destructionInProgress; 360 bool m_destructionInProgress;
357 bool m_isHidden; 361 bool m_isHidden;
358 SkFilterQuality m_filterQuality; 362 SkFilterQuality m_filterQuality;
359 363
360 OwnPtr<WebExternalTextureLayer> m_layer; 364 OwnPtr<WebExternalTextureLayer> m_layer;
361 365
362 // All of the mailboxes that this DrawingBuffer has ever created. 366 // All of the mailboxes that this DrawingBuffer has ever created.
363 Vector<RefPtr<MailboxInfo>> m_textureMailboxes; 367 Vector<RefPtr<MailboxInfo>> m_textureMailboxes;
364 // Mailboxes that were released by the compositor can be used again by this DrawingBuffer. 368 // Mailboxes that were released by the compositor can be used again by this DrawingBuffer.
365 Deque<WebExternalTextureMailbox> m_recycledMailboxQueue; 369 Deque<WebExternalTextureMailbox> m_recycledMailboxQueue;
366 370
367 // If the width and height of the Canvas's backing store don't 371 // 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 372 // match those that we were given in the most recent call to
369 // reshape(), then we need an intermediate bitmap to read back the 373 // reshape(), then we need an intermediate bitmap to read back the
370 // frame buffer into. This seems to happen when CSS styles are 374 // frame buffer into. This seems to happen when CSS styles are
371 // used to resize the Canvas. 375 // used to resize the Canvas.
372 SkBitmap m_resizingBitmap; 376 SkBitmap m_resizingBitmap;
373 377
374 // Used to flip a bitmap vertically. 378 // Used to flip a bitmap vertically.
375 Vector<uint8_t> m_scanline; 379 Vector<uint8_t> m_scanline;
376 }; 380 };
377 381
378 } // namespace blink 382 } // namespace blink
379 383
380 #endif // DrawingBuffer_h 384 #endif // DrawingBuffer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698