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

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

Issue 2831733003: Fix blits from multisampled renderbuffers to alpha:false WebGL back buffer. (Closed)
Patch Set: Created 3 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // Rebind the read and draw framebuffers that WebGL is expecting. 223 // Rebind the read and draw framebuffers that WebGL is expecting.
224 void RestoreFramebufferBindings(); 224 void RestoreFramebufferBindings();
225 225
226 // Restore all state that may have been dirtied by any call. 226 // Restore all state that may have been dirtied by any call.
227 void RestoreAllState(); 227 void RestoreAllState();
228 228
229 void AddNewMailboxCallback(std::unique_ptr<WTF::Closure> closure) { 229 void AddNewMailboxCallback(std::unique_ptr<WTF::Closure> closure) {
230 new_mailbox_callback_ = std::move(closure); 230 new_mailbox_callback_ = std::move(closure);
231 } 231 }
232 232
233 // This class helps implement correct semantics for BlitFramebuffer
234 // when the DrawingBuffer is using a CHROMIUM image for its backing
235 // store and RGB emulation is in use (basically, macOS only).
236 class ScopedRGBEmulationForBlitFramebuffer {
237 public:
238 ScopedRGBEmulationForBlitFramebuffer(DrawingBuffer*);
239 ~ScopedRGBEmulationForBlitFramebuffer();
240
241 private:
242 RefPtr<DrawingBuffer> drawing_buffer_;
243 bool doing_work_ = false;
244 };
245
233 protected: // For unittests 246 protected: // For unittests
234 DrawingBuffer(std::unique_ptr<WebGraphicsContext3DProvider>, 247 DrawingBuffer(std::unique_ptr<WebGraphicsContext3DProvider>,
235 std::unique_ptr<Extensions3DUtil>, 248 std::unique_ptr<Extensions3DUtil>,
236 Client*, 249 Client*,
237 bool discard_framebuffer_supported, 250 bool discard_framebuffer_supported,
238 bool want_alpha_channel, 251 bool want_alpha_channel,
239 bool premultiplied_alpha, 252 bool premultiplied_alpha,
240 PreserveDrawingBuffer, 253 PreserveDrawingBuffer,
241 WebGLVersion, 254 WebGLVersion,
242 bool wants_depth, 255 bool wants_depth,
243 bool wants_stencil, 256 bool wants_stencil,
244 ChromiumImageUsage); 257 ChromiumImageUsage);
245 258
246 bool Initialize(const IntSize&, bool use_multisampling); 259 bool Initialize(const IntSize&, bool use_multisampling);
247 260
248 // Shared memory bitmaps that were released by the compositor and can be used 261 // Shared memory bitmaps that were released by the compositor and can be used
249 // again by this DrawingBuffer. 262 // again by this DrawingBuffer.
250 struct RecycledBitmap { 263 struct RecycledBitmap {
251 std::unique_ptr<cc::SharedBitmap> bitmap; 264 std::unique_ptr<cc::SharedBitmap> bitmap;
252 IntSize size; 265 IntSize size;
253 }; 266 };
254 Vector<RecycledBitmap> recycled_bitmaps_; 267 Vector<RecycledBitmap> recycled_bitmaps_;
255 268
256 private: 269 private:
270 friend class ScopedRGBEmulationForBlitFramebuffer;
257 friend class ScopedStateRestorer; 271 friend class ScopedStateRestorer;
258 friend class ColorBuffer; 272 friend class ColorBuffer;
259 273
260 // This structure should wrap all public entrypoints that may modify GL state. 274 // This structure should wrap all public entrypoints that may modify GL state.
261 // It will restore all state when it drops out of scope. 275 // It will restore all state when it drops out of scope.
262 class ScopedStateRestorer { 276 class ScopedStateRestorer {
263 public: 277 public:
264 ScopedStateRestorer(DrawingBuffer*); 278 ScopedStateRestorer(DrawingBuffer*);
265 ~ScopedStateRestorer(); 279 ~ScopedStateRestorer();
266 280
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // ColorBuffers. 327 // ColorBuffers.
314 RefPtr<DrawingBuffer> drawing_buffer; 328 RefPtr<DrawingBuffer> drawing_buffer;
315 329
316 const ColorBufferParameters parameters; 330 const ColorBufferParameters parameters;
317 const IntSize size; 331 const IntSize size;
318 332
319 const GLuint texture_id = 0; 333 const GLuint texture_id = 0;
320 const GLuint image_id = 0; 334 const GLuint image_id = 0;
321 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer; 335 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer;
322 336
337 // If we're emulating an RGB back buffer using an RGBA Chromium
338 // image (essentially macOS only), then when performing
339 // BlitFramebuffer calls, we have to swap in an RGB texture in
340 // place of the RGBA texture bound to the image. The reason is
341 // that BlitFramebuffer requires the internal formats of the
342 // source and destination to match (e.g. RGB8 on both sides).
343 // There are bugs in the semantics of RGB8 textures in this
344 // situation (the alpha channel is zeroed), requiring more fixups.
345 GLuint rgb_workaround_texture_id = 0;
346
323 // The mailbox used to send this buffer to the compositor. 347 // The mailbox used to send this buffer to the compositor.
324 gpu::Mailbox mailbox; 348 gpu::Mailbox mailbox;
325 349
326 // The sync token for when this buffer was sent to the compositor. 350 // The sync token for when this buffer was sent to the compositor.
327 gpu::SyncToken produce_sync_token; 351 gpu::SyncToken produce_sync_token;
328 352
329 // The sync token for when this buffer was received back from the 353 // The sync token for when this buffer was received back from the
330 // compositor. 354 // compositor.
331 gpu::SyncToken receive_sync_token; 355 gpu::SyncToken receive_sync_token;
332 356
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 // implemented by forwarding all draw operations to a multisample 448 // implemented by forwarding all draw operations to a multisample
425 // renderbuffer, which is resolved before any read operations or swaps. 449 // renderbuffer, which is resolved before any read operations or swaps.
426 bool WantExplicitResolve(); 450 bool WantExplicitResolve();
427 451
428 // Whether the WebGL client wants a depth or stencil buffer. 452 // Whether the WebGL client wants a depth or stencil buffer.
429 bool WantDepthOrStencil(); 453 bool WantDepthOrStencil();
430 454
431 // The format to use when creating a multisampled renderbuffer. 455 // The format to use when creating a multisampled renderbuffer.
432 GLenum GetMultisampledRenderbufferFormat(); 456 GLenum GetMultisampledRenderbufferFormat();
433 457
458 // Helpers to ensure correct behavior of BlitFramebuffer when using
459 // an emulated RGB CHROMIUM_image back buffer.
460 bool SetupRGBEmulationForBlitFramebuffer();
461 void CleanupRGBEmulationForBlitFramebuffer();
462
434 // Weak, reset by beginDestruction. 463 // Weak, reset by beginDestruction.
435 Client* client_ = nullptr; 464 Client* client_ = nullptr;
436 465
437 const PreserveDrawingBuffer preserve_drawing_buffer_; 466 const PreserveDrawingBuffer preserve_drawing_buffer_;
438 const WebGLVersion web_gl_version_; 467 const WebGLVersion web_gl_version_;
439 468
440 std::unique_ptr<WebGraphicsContext3DProviderWrapper> context_provider_; 469 std::unique_ptr<WebGraphicsContext3DProviderWrapper> context_provider_;
441 // Lifetime is tied to the m_contextProvider. 470 // Lifetime is tied to the m_contextProvider.
442 gpu::gles2::GLES2Interface* gl_; 471 gpu::gles2::GLES2Interface* gl_;
443 std::unique_ptr<Extensions3DUtil> extensions_util_; 472 std::unique_ptr<Extensions3DUtil> extensions_util_;
444 IntSize size_ = {-1, -1}; 473 IntSize size_ = {-1, -1};
445 const bool discard_framebuffer_supported_; 474 const bool discard_framebuffer_supported_;
446 const bool want_alpha_channel_; 475 const bool want_alpha_channel_;
447 const bool premultiplied_alpha_; 476 const bool premultiplied_alpha_;
448 const bool software_rendering_; 477 const bool software_rendering_;
449 bool has_implicit_stencil_buffer_ = false; 478 bool has_implicit_stencil_buffer_ = false;
450 bool storage_texture_supported_ = false; 479 bool storage_texture_supported_ = false;
451 480
452 std::unique_ptr<WTF::Closure> new_mailbox_callback_; 481 std::unique_ptr<WTF::Closure> new_mailbox_callback_;
453 482
454 // The current state restorer, which is used to track state dirtying. It is in 483 // The current state restorer, which is used to track state dirtying. It is an
455 // error to dirty state shared with WebGL while there is no existing state 484 // error to dirty state shared with WebGL while there is no existing state
456 // restorer. It is also in error to instantiate two state restorers at once. 485 // restorer.
457 ScopedStateRestorer* state_restorer_ = nullptr; 486 ScopedStateRestorer* state_restorer_ = nullptr;
458 487
459 // This is used when the user requests either a depth or stencil buffer. 488 // This is used when the user requests either a depth or stencil buffer.
460 GLuint depth_stencil_buffer_ = 0; 489 GLuint depth_stencil_buffer_ = 0;
461 490
462 // When wantExplicitResolve() returns true, the target of all draw 491 // When wantExplicitResolve() returns true, the target of all draw
463 // operations. 492 // operations.
464 GLuint multisample_fbo_ = 0; 493 GLuint multisample_fbo_ = 0;
465 494
466 // The id of the renderbuffer storage for |m_multisampleFBO|. 495 // The id of the renderbuffer storage for |m_multisampleFBO|.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() call with 557 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() call with
529 // shouldUseChromiumImage() calls, and set m_chromiumImageUsage to 558 // shouldUseChromiumImage() calls, and set m_chromiumImageUsage to
530 // DisallowChromiumImage in the case of OffscreenCanvas. 559 // DisallowChromiumImage in the case of OffscreenCanvas.
531 ChromiumImageUsage chromium_image_usage_; 560 ChromiumImageUsage chromium_image_usage_;
532 bool ShouldUseChromiumImage(); 561 bool ShouldUseChromiumImage();
533 }; 562 };
534 563
535 } // namespace blink 564 } // namespace blink
536 565
537 #endif // DrawingBuffer_h 566 #endif // DrawingBuffer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698