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