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

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

Issue 1950053003: Clean up DrawingBuffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // Indicates whether the DrawingBuffer internally allocated a packed depth-s tencil renderbuffer 98 // Indicates whether the DrawingBuffer internally allocated a packed depth-s tencil renderbuffer
99 // in the situation where the end user only asked for a depth buffer. In thi s case, we need to 99 // in the situation where the end user only asked for a depth buffer. In thi s case, we need to
100 // upgrade clears of the depth buffer to clears of the depth and stencil buf fers in order to 100 // upgrade clears of the depth buffer to clears of the depth and stencil buf fers in order to
101 // avoid performance problems on some GPUs. 101 // avoid performance problems on some GPUs.
102 bool hasImplicitStencilBuffer() const { return m_hasImplicitStencilBuffer; } 102 bool hasImplicitStencilBuffer() const { return m_hasImplicitStencilBuffer; }
103 bool hasDepthBuffer() const { return !!m_depthStencilBuffer; } 103 bool hasDepthBuffer() const { return !!m_depthStencilBuffer; }
104 bool hasStencilBuffer() const { return !!m_depthStencilBuffer; } 104 bool hasStencilBuffer() const { return !!m_depthStencilBuffer; }
105 105
106 // Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget. 106 // Given the desired buffer size, provides the largest dimensions that will fit in the pixel budget.
107 static IntSize adjustSize(const IntSize& desiredSize, const IntSize& curSize , int maxTextureSize); 107 static IntSize adjustSize(const IntSize& desiredSize, const IntSize& curSize , int maxTextureSize);
108 bool reset(const IntSize&, bool wantDepthOrStencilBuffer); 108
109 // Resizes (or allocates if necessary) all buffers attached to the default
110 // framebuffer. Returns whether the operation was successful. Leaves GL
111 // bindings dirtied.
112 bool reset(const IntSize&);
113
114 // Bind the default framebuffer to |target|. |target| must be
115 // GL_FRAMEBUFFER, GL_READ_FRAMEBUFFER, or GL_DRAW_FRAMEBUFFER.
109 void bind(GLenum target); 116 void bind(GLenum target);
110 IntSize size() const { return m_size; } 117 IntSize size() const { return m_size; }
111 118
112 // Copies the multisample color buffer to the normal color buffer and leaves m_fbo bound. 119 // Copies the multisample color buffer to the normal color buffer and leaves m_fbo bound.
113 void commit(); 120 void commit();
114 121
115 // commit should copy the full multisample buffer, and not respect the 122 // commit should copy the full multisample buffer, and not respect the
116 // current scissor bounds. Track the state of the scissor test so that it 123 // current scissor bounds. Track the state of the scissor test so that it
117 // can be disabled during calls to commit. 124 // can be disabled during calls to commit.
118 void setScissorEnabled(bool scissorEnabled) { m_scissorEnabled = scissorEnab led; } 125 void setScissorEnabled(bool scissorEnabled) { m_scissorEnabled = scissorEnab led; }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 GLuint framebuffer() const; 176 GLuint framebuffer() const;
170 177
171 bool discardFramebufferSupported() const { return m_discardFramebufferSuppor ted; } 178 bool discardFramebufferSupported() const { return m_discardFramebufferSuppor ted; }
172 179
173 void markContentsChanged(); 180 void markContentsChanged();
174 void setBufferClearNeeded(bool); 181 void setBufferClearNeeded(bool);
175 bool bufferClearNeeded() const; 182 bool bufferClearNeeded() const;
176 void setIsHidden(bool); 183 void setIsHidden(bool);
177 void setFilterQuality(SkFilterQuality); 184 void setFilterQuality(SkFilterQuality);
178 185
179 // Indicates that the currently bound framebuffer has internalformat 186 // Whether the target for draw operations has format GL_RGBA, but is
180 // GL_RGBA, but is emulating GL_RGB. This happens to the backbuffer when the 187 // emulating format GL_RGB. When the target's storage is first
181 // client requests alpha:False, but GL_RGB textures are unusable because of 188 // allocated, its alpha channel must be cleared to 1. All future drawing
182 // driver bugs. 189 // operations must use a color mask with alpha=GL_FALSE.
183 bool requiresRGBEmulation(); 190 bool requiresAlphaMask();
Ken Russell (switch to Gerrit) 2016/05/04 21:13:11 It's confusing to understand whether alpha is mask
erikchen 2016/05/04 21:17:53 Done.
184 191
185 WebLayer* platformLayer(); 192 WebLayer* platformLayer();
186 193
187 gpu::gles2::GLES2Interface* contextGL(); 194 gpu::gles2::GLES2Interface* contextGL();
188 WebGraphicsContext3DProvider* contextProvider(); 195 WebGraphicsContext3DProvider* contextProvider();
189 196
190 // WebExternalTextureLayerClient implementation. 197 // WebExternalTextureLayerClient implementation.
191 bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*) override ; 198 bool prepareMailbox(WebExternalTextureMailbox*, WebExternalBitmap*) override ;
192 void mailboxReleased(const WebExternalTextureMailbox&, bool lostResource = f alse) override; 199 void mailboxReleased(const WebExternalTextureMailbox&, bool lostResource = f alse) override;
193 200
194 // Destroys the TEXTURE_2D binding for the owned context 201 // Destroys the TEXTURE_2D binding for the owned context
195 bool copyToPlatformTexture(gpu::gles2::GLES2Interface*, GLuint texture, GLen um internalFormat, 202 bool copyToPlatformTexture(gpu::gles2::GLES2Interface*, GLuint texture, GLen um internalFormat,
196 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceD rawingBuffer); 203 GLenum destType, GLint level, bool premultiplyAlpha, bool flipY, SourceD rawingBuffer);
197 204
198 void setPackAlignment(GLint param); 205 void setPackAlignment(GLint param);
199 206
200 bool paintRenderingResultsToImageData(int&, int&, SourceDrawingBuffer, WTF:: ArrayBufferContents&); 207 bool paintRenderingResultsToImageData(int&, int&, SourceDrawingBuffer, WTF:: ArrayBufferContents&);
201 208
202 int sampleCount() const { return m_sampleCount; } 209 int sampleCount() const { return m_sampleCount; }
203 bool explicitResolveOfMultisampleData() const { return m_antiAliasingMode == MSAAExplicitResolve; } 210 bool explicitResolveOfMultisampleData() const { return m_antiAliasingMode == MSAAExplicitResolve; }
204 211
205 // Bind to m_drawFramebufferBinding or m_readFramebufferBinding if it's not 0. 212 // Bind to m_drawFramebufferBinding or m_readFramebufferBinding if it's not 0.
206 // Otherwise, bind to the default FBO. 213 // Otherwise, bind to the default FBO.
207 void restoreFramebufferBindings(); 214 void restoreFramebufferBindings();
208 215
216 void restoreTextureBindings();
217
209 void addNewMailboxCallback(PassOwnPtr<SameThreadClosure> closure) { m_newMai lboxCallback = std::move(closure); } 218 void addNewMailboxCallback(PassOwnPtr<SameThreadClosure> closure) { m_newMai lboxCallback = std::move(closure); }
210 219
211 protected: // For unittests 220 protected: // For unittests
212 DrawingBuffer( 221 DrawingBuffer(
213 PassOwnPtr<WebGraphicsContext3DProvider>, 222 PassOwnPtr<WebGraphicsContext3DProvider>,
214 PassOwnPtr<Extensions3DUtil>, 223 PassOwnPtr<Extensions3DUtil>,
215 bool discardFramebufferSupported, 224 bool discardFramebufferSupported,
216 bool wantAlphaChannel, 225 bool wantAlphaChannel,
217 bool premultipliedAlpha, 226 bool premultipliedAlpha,
218 PreserveDrawingBuffer); 227 PreserveDrawingBuffer,
228 bool wantsDepth,
229 bool wantsStencil);
219 230
220 bool initialize(const IntSize&, bool wantDepthBuffer, bool wantStencilBuffer , bool useMultisampling); 231 bool initialize(const IntSize&, bool useMultisampling);
221 232
222 private: 233 private:
234 // All parameters necessary to generate the texture that will be passed to
235 // prepareMailbox.
223 struct TextureParameters { 236 struct TextureParameters {
224 DISALLOW_NEW(); 237 DISALLOW_NEW();
225 GLenum target; 238 GLenum target = 0;
226 GLenum internalColorFormat; 239 GLenum internalColorFormat = 0;
227 240
228 // The internal color format used when allocating storage for the 241 // The internal color format used when allocating storage for the
229 // texture. This may be different from internalColorFormat if RGB 242 // texture. This may be different from internalColorFormat if RGB
230 // emulation is required. 243 // emulation is required.
231 GLenum creationInternalColorFormat; 244 GLenum creationInternalColorFormat = 0;
232 GLenum colorFormat; 245 GLenum colorFormat = 0;
233 GLenum internalRenderbufferFormat; 246 GLenum internalRenderbufferFormat = 0;
234
235 TextureParameters()
236 : target(0)
237 , internalColorFormat(0)
238 , creationInternalColorFormat(0)
239 , colorFormat(0)
240 , internalRenderbufferFormat(0)
241 {
242 }
243 }; 247 };
244 248
245 // If we used CHROMIUM_image as the backing storage for our buffers, 249 // If we used CHROMIUM_image as the backing storage for our buffers,
246 // we need to know the mapping from texture id to image. 250 // we need to know the mapping from texture id to image.
247 struct TextureInfo { 251 struct TextureInfo {
248 DISALLOW_NEW(); 252 DISALLOW_NEW();
249 GLuint textureId; 253 GLuint textureId = 0;
250 GLuint imageId; 254 GLuint imageId = 0;
251 TextureParameters parameters; 255 TextureParameters parameters;
252
253 TextureInfo()
254 : textureId(0)
255 , imageId(0)
256 {
257 }
258 }; 256 };
259 257
260 struct MailboxInfo : public RefCounted<MailboxInfo> { 258 struct MailboxInfo : public RefCounted<MailboxInfo> {
261 WTF_MAKE_NONCOPYABLE(MailboxInfo); 259 WTF_MAKE_NONCOPYABLE(MailboxInfo);
262 260
263 public: 261 public:
264 MailboxInfo() {} 262 MailboxInfo() {}
265 263
266 WebExternalTextureMailbox mailbox; 264 WebExternalTextureMailbox mailbox;
267 TextureInfo textureInfo; 265 TextureInfo textureInfo;
(...skipping 12 matching lines...) Expand all
280 TextureParameters defaultTextureParameters(); 278 TextureParameters defaultTextureParameters();
281 279
282 void mailboxReleasedWithoutRecycling(const WebExternalTextureMailbox&); 280 void mailboxReleasedWithoutRecycling(const WebExternalTextureMailbox&);
283 281
284 // Creates and binds a texture with the given parameters. Returns 0 on 282 // Creates and binds a texture with the given parameters. Returns 0 on
285 // failure, or the newly created texture id on success. The caller takes 283 // failure, or the newly created texture id on success. The caller takes
286 // ownership of the newly created texture. 284 // ownership of the newly created texture.
287 GLuint createColorTexture(const TextureParameters&); 285 GLuint createColorTexture(const TextureParameters&);
288 286
289 // Create the depth/stencil and multisample buffers, if needed. 287 // Create the depth/stencil and multisample buffers, if needed.
290 void createSecondaryBuffers(); 288 bool resizeMultisampleFramebuffer(const IntSize&);
291 bool resizeFramebuffer(const IntSize&, bool wantDepthOrStencilBuffer);
292 bool resizeMultisampleFramebuffer(const IntSize&, bool wantDepthOrStencilBuf fer);
293 void resizeDepthStencil(const IntSize&); 289 void resizeDepthStencil(const IntSize&);
294 290
291 // Attempts to allocator storage for, or resize all buffers. Returns whether
292 // the operation was successful.
293 bool resizeDefaultFramebuffer(const IntSize&);
294
295 void clearPlatformLayer(); 295 void clearPlatformLayer();
296 296
297 PassRefPtr<MailboxInfo> recycledMailbox(); 297 PassRefPtr<MailboxInfo> recycledMailbox();
298 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&); 298 PassRefPtr<MailboxInfo> createNewMailbox(const TextureInfo&);
299 void deleteMailbox(const WebExternalTextureMailbox&); 299 void deleteMailbox(const WebExternalTextureMailbox&);
300 void freeRecycledMailboxes(); 300 void freeRecycledMailboxes();
301 301
302 // Updates the current size of the buffer, ensuring that s_currentResourceUs ePixels is updated. 302 // Updates the current size of the buffer, ensuring that s_currentResourceUs ePixels is updated.
303 void setSize(const IntSize& size); 303 void setSize(const IntSize& size);
304 304
(...skipping 24 matching lines...) Expand all
329 // Tries to create a CHROMIUM_image backed texture if 329 // Tries to create a CHROMIUM_image backed texture if
330 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() is true. On failure, 330 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() is true. On failure,
331 // or if the flag is false, creates a default texture. 331 // or if the flag is false, creates a default texture.
332 TextureInfo createTextureAndAllocateMemory(const IntSize&); 332 TextureInfo createTextureAndAllocateMemory(const IntSize&);
333 333
334 // Creates and allocates space for a default texture. 334 // Creates and allocates space for a default texture.
335 TextureInfo createDefaultTextureAndAllocateMemory(const IntSize&); 335 TextureInfo createDefaultTextureAndAllocateMemory(const IntSize&);
336 336
337 void resizeTextureMemory(TextureInfo*, const IntSize&); 337 void resizeTextureMemory(TextureInfo*, const IntSize&);
338 338
339 void attachColorBufferToCurrentFBO(); 339 // Attaches |m_colorBuffer| to |m_fbo|, which is always the source for read
340 // operations.
341 void attachColorBufferToReadFramebuffer();
342
343 // Whether the WebGL client desires an explicit resolve. This is
344 // implemented by forwarding all draw operations to a multisample
345 // renderbuffer, which is resolved before any read operations or swaps.
346 bool wantExplicitResolve();
347
348 // Whether the WebGL client wants a depth or stencil buffer.
349 bool wantDepthOrStencil();
340 350
341 const PreserveDrawingBuffer m_preserveDrawingBuffer; 351 const PreserveDrawingBuffer m_preserveDrawingBuffer;
342 bool m_scissorEnabled; 352 bool m_scissorEnabled = false;
Ken Russell (switch to Gerrit) 2016/05/04 21:13:11 I don't remember whether these inline default valu
danakj 2016/05/04 21:13:59 They are allowed
343 GLuint m_texture2DBinding; 353 GLuint m_texture2DBinding = 0;
344 GLuint m_drawFramebufferBinding; 354 GLuint m_drawFramebufferBinding = 0;
345 GLuint m_readFramebufferBinding; 355 GLuint m_readFramebufferBinding = 0;
346 GLuint m_renderbufferBinding; 356 GLuint m_renderbufferBinding = 0;
347 GLenum m_activeTextureUnit; 357 GLenum m_activeTextureUnit = GL_TEXTURE0;
348 GLfloat m_clearColor[4]; 358 GLfloat m_clearColor[4];
349 GLboolean m_colorMask[4]; 359 GLboolean m_colorMask[4];
350 360
351 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; 361 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider;
352 // Lifetime is tied to the m_contextProvider. 362 // Lifetime is tied to the m_contextProvider.
353 gpu::gles2::GLES2Interface* m_gl; 363 gpu::gles2::GLES2Interface* m_gl;
354 OwnPtr<Extensions3DUtil> m_extensionsUtil; 364 OwnPtr<Extensions3DUtil> m_extensionsUtil;
355 IntSize m_size; 365 IntSize m_size = { -1, -1 };
356 const bool m_discardFramebufferSupported; 366 const bool m_discardFramebufferSupported;
357 const bool m_wantAlphaChannel; 367 const bool m_wantAlphaChannel;
358 const bool m_premultipliedAlpha; 368 const bool m_premultipliedAlpha;
359 bool m_hasImplicitStencilBuffer; 369 bool m_hasImplicitStencilBuffer = false;
360 GLuint m_fbo;
361 // DrawingBuffer's output is double-buffered. m_colorBuffer is the back buff er.
362 TextureInfo m_colorBuffer;
363 struct FrontBufferInfo { 370 struct FrontBufferInfo {
364 TextureInfo texInfo; 371 TextureInfo texInfo;
365 WebExternalTextureMailbox mailbox; 372 WebExternalTextureMailbox mailbox;
366 }; 373 };
367 FrontBufferInfo m_frontColorBuffer; 374 FrontBufferInfo m_frontColorBuffer;
368 375
369 OwnPtr<SameThreadClosure> m_newMailboxCallback; 376 OwnPtr<SameThreadClosure> m_newMailboxCallback;
370 377
371 // This is used when the user requests either a depth or stencil buffer. 378 // This is used when the user requests either a depth or stencil buffer.
372 GLuint m_depthStencilBuffer; 379 GLuint m_depthStencilBuffer = 0;
373 380
374 // For multisampling. 381 // For explicit resolve.
375 GLuint m_multisampleFBO; 382 GLuint m_intermediateFBO = 0;
376 GLuint m_intermediateFBO; 383 GLuint m_intermediateRenderbuffer = 0;
377 GLuint m_intermediateRenderbuffer; 384
378 GLuint m_multisampleColorBuffer; 385 // When wantsExplicitResolve() returns true, the target of all draw
386 // operations.
387 GLuint m_multisampleFBO = 0;
388
389 // The id of the renderbuffer storage for |m_multisampleFBO|.
390 GLuint m_multisampleRenderbuffer = 0;
391
392 // When wantsExplicitResolve() returns false, the target of all draw and
393 // read operations. When wantsExplicitResolve() returns true, the target of
394 // all read operations. A swap is performed by exchanging |m_colorBuffer|
395 // with |m_frontColorBuffer|.
396 GLuint m_fbo = 0;
397
398 // All information about the texture storage for |m_fbo|.
399 TextureInfo m_colorBuffer;
379 400
380 // True if our contents have been modified since the last presentation of th is buffer. 401 // True if our contents have been modified since the last presentation of th is buffer.
381 bool m_contentsChanged; 402 bool m_contentsChanged = true;
382 403
383 // True if commit() has been called since the last time markContentsChanged( ) had been called. 404 // True if commit() has been called since the last time markContentsChanged( ) had been called.
384 bool m_contentsChangeCommitted; 405 bool m_contentsChangeCommitted = false;
385 bool m_bufferClearNeeded; 406 bool m_bufferClearNeeded = false;
407
408 // Whether the client wants a depth or stencil buffer.
409 const bool m_wantDepth;
410 const bool m_wantStencil;
386 411
387 enum AntialiasingMode { 412 enum AntialiasingMode {
388 None, 413 None,
389 MSAAImplicitResolve, 414 MSAAImplicitResolve,
390 MSAAExplicitResolve, 415 MSAAExplicitResolve,
391 ScreenSpaceAntialiasing, 416 ScreenSpaceAntialiasing,
392 }; 417 };
393 418
394 AntialiasingMode m_antiAliasingMode; 419 AntialiasingMode m_antiAliasingMode = None;
395 420
396 int m_maxTextureSize; 421 int m_maxTextureSize = 0;
397 int m_sampleCount; 422 int m_sampleCount = 0;
398 int m_packAlignment; 423 int m_packAlignment = 4;
399 bool m_destructionInProgress; 424 bool m_destructionInProgress = false;
400 bool m_isHidden; 425 bool m_isHidden = false;
401 SkFilterQuality m_filterQuality; 426 SkFilterQuality m_filterQuality = kLow_SkFilterQuality;
402 427
403 OwnPtr<WebExternalTextureLayer> m_layer; 428 OwnPtr<WebExternalTextureLayer> m_layer;
404 429
405 // All of the mailboxes that this DrawingBuffer has ever created. 430 // All of the mailboxes that this DrawingBuffer has ever created.
406 Vector<RefPtr<MailboxInfo>> m_textureMailboxes; 431 Vector<RefPtr<MailboxInfo>> m_textureMailboxes;
407 // Mailboxes that were released by the compositor can be used again by this DrawingBuffer. 432 // Mailboxes that were released by the compositor can be used again by this DrawingBuffer.
408 Deque<WebExternalTextureMailbox> m_recycledMailboxQueue; 433 Deque<WebExternalTextureMailbox> m_recycledMailboxQueue;
409 434
410 // If the width and height of the Canvas's backing store don't 435 // If the width and height of the Canvas's backing store don't
411 // match those that we were given in the most recent call to 436 // match those that we were given in the most recent call to
412 // reshape(), then we need an intermediate bitmap to read back the 437 // reshape(), then we need an intermediate bitmap to read back the
413 // frame buffer into. This seems to happen when CSS styles are 438 // frame buffer into. This seems to happen when CSS styles are
414 // used to resize the Canvas. 439 // used to resize the Canvas.
415 SkBitmap m_resizingBitmap; 440 SkBitmap m_resizingBitmap;
416 441
417 // Used to flip a bitmap vertically. 442 // Used to flip a bitmap vertically.
418 Vector<uint8_t> m_scanline; 443 Vector<uint8_t> m_scanline;
419 }; 444 };
420 445
421 } // namespace blink 446 } // namespace blink
422 447
423 #endif // DrawingBuffer_h 448 #endif // DrawingBuffer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698