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 PLATFORM_EXPORT 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // ColorBuffers. | 324 // ColorBuffers. |
311 RefPtr<DrawingBuffer> drawing_buffer; | 325 RefPtr<DrawingBuffer> drawing_buffer; |
312 | 326 |
313 const ColorBufferParameters parameters; | 327 const ColorBufferParameters parameters; |
314 const IntSize size; | 328 const IntSize size; |
315 | 329 |
316 const GLuint texture_id = 0; | 330 const GLuint texture_id = 0; |
317 const GLuint image_id = 0; | 331 const GLuint image_id = 0; |
318 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer; | 332 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer; |
319 | 333 |
| 334 // If we're emulating an RGB back buffer using an RGBA Chromium |
| 335 // image (essentially macOS only), then when performing |
| 336 // BlitFramebuffer calls, we have to swap in an RGB texture in |
| 337 // place of the RGBA texture bound to the image. The reason is |
| 338 // that BlitFramebuffer requires the internal formats of the |
| 339 // source and destination to match (e.g. RGB8 on both sides). |
| 340 // There are bugs in the semantics of RGB8 textures in this |
| 341 // situation (the alpha channel is zeroed), requiring more fixups. |
| 342 GLuint rgb_workaround_texture_id = 0; |
| 343 |
320 // The mailbox used to send this buffer to the compositor. | 344 // The mailbox used to send this buffer to the compositor. |
321 gpu::Mailbox mailbox; | 345 gpu::Mailbox mailbox; |
322 | 346 |
323 // The sync token for when this buffer was sent to the compositor. | 347 // The sync token for when this buffer was sent to the compositor. |
324 gpu::SyncToken produce_sync_token; | 348 gpu::SyncToken produce_sync_token; |
325 | 349 |
326 // The sync token for when this buffer was received back from the | 350 // The sync token for when this buffer was received back from the |
327 // compositor. | 351 // compositor. |
328 gpu::SyncToken receive_sync_token; | 352 gpu::SyncToken receive_sync_token; |
329 | 353 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 // implemented by forwarding all draw operations to a multisample | 445 // implemented by forwarding all draw operations to a multisample |
422 // renderbuffer, which is resolved before any read operations or swaps. | 446 // renderbuffer, which is resolved before any read operations or swaps. |
423 bool WantExplicitResolve(); | 447 bool WantExplicitResolve(); |
424 | 448 |
425 // Whether the WebGL client wants a depth or stencil buffer. | 449 // Whether the WebGL client wants a depth or stencil buffer. |
426 bool WantDepthOrStencil(); | 450 bool WantDepthOrStencil(); |
427 | 451 |
428 // The format to use when creating a multisampled renderbuffer. | 452 // The format to use when creating a multisampled renderbuffer. |
429 GLenum GetMultisampledRenderbufferFormat(); | 453 GLenum GetMultisampledRenderbufferFormat(); |
430 | 454 |
| 455 // Helpers to ensure correct behavior of BlitFramebuffer when using |
| 456 // an emulated RGB CHROMIUM_image back buffer. |
| 457 bool SetupRGBEmulationForBlitFramebuffer(); |
| 458 void CleanupRGBEmulationForBlitFramebuffer(); |
| 459 |
431 // Weak, reset by beginDestruction. | 460 // Weak, reset by beginDestruction. |
432 Client* client_ = nullptr; | 461 Client* client_ = nullptr; |
433 | 462 |
434 const PreserveDrawingBuffer preserve_drawing_buffer_; | 463 const PreserveDrawingBuffer preserve_drawing_buffer_; |
435 const WebGLVersion web_gl_version_; | 464 const WebGLVersion web_gl_version_; |
436 | 465 |
437 std::unique_ptr<WebGraphicsContext3DProviderWrapper> context_provider_; | 466 std::unique_ptr<WebGraphicsContext3DProviderWrapper> context_provider_; |
438 // Lifetime is tied to the m_contextProvider. | 467 // Lifetime is tied to the m_contextProvider. |
439 gpu::gles2::GLES2Interface* gl_; | 468 gpu::gles2::GLES2Interface* gl_; |
440 std::unique_ptr<Extensions3DUtil> extensions_util_; | 469 std::unique_ptr<Extensions3DUtil> extensions_util_; |
441 IntSize size_ = {-1, -1}; | 470 IntSize size_ = {-1, -1}; |
442 const bool discard_framebuffer_supported_; | 471 const bool discard_framebuffer_supported_; |
443 const bool want_alpha_channel_; | 472 const bool want_alpha_channel_; |
444 const bool premultiplied_alpha_; | 473 const bool premultiplied_alpha_; |
445 const bool software_rendering_; | 474 const bool software_rendering_; |
446 bool has_implicit_stencil_buffer_ = false; | 475 bool has_implicit_stencil_buffer_ = false; |
447 bool storage_texture_supported_ = false; | 476 bool storage_texture_supported_ = false; |
448 | 477 |
449 std::unique_ptr<WTF::Closure> new_mailbox_callback_; | 478 std::unique_ptr<WTF::Closure> new_mailbox_callback_; |
450 | 479 |
451 // The current state restorer, which is used to track state dirtying. It is in | 480 // The current state restorer, which is used to track state dirtying. It is an |
452 // error to dirty state shared with WebGL while there is no existing state | 481 // error to dirty state shared with WebGL while there is no existing state |
453 // restorer. It is also in error to instantiate two state restorers at once. | 482 // restorer. |
454 ScopedStateRestorer* state_restorer_ = nullptr; | 483 ScopedStateRestorer* state_restorer_ = nullptr; |
455 | 484 |
456 // This is used when the user requests either a depth or stencil buffer. | 485 // This is used when the user requests either a depth or stencil buffer. |
457 GLuint depth_stencil_buffer_ = 0; | 486 GLuint depth_stencil_buffer_ = 0; |
458 | 487 |
459 // When wantExplicitResolve() returns true, the target of all draw | 488 // When wantExplicitResolve() returns true, the target of all draw |
460 // operations. | 489 // operations. |
461 GLuint multisample_fbo_ = 0; | 490 GLuint multisample_fbo_ = 0; |
462 | 491 |
463 // The id of the renderbuffer storage for |m_multisampleFBO|. | 492 // The id of the renderbuffer storage for |m_multisampleFBO|. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() call with | 554 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() call with |
526 // shouldUseChromiumImage() calls, and set m_chromiumImageUsage to | 555 // shouldUseChromiumImage() calls, and set m_chromiumImageUsage to |
527 // DisallowChromiumImage in the case of OffscreenCanvas. | 556 // DisallowChromiumImage in the case of OffscreenCanvas. |
528 ChromiumImageUsage chromium_image_usage_; | 557 ChromiumImageUsage chromium_image_usage_; |
529 bool ShouldUseChromiumImage(); | 558 bool ShouldUseChromiumImage(); |
530 }; | 559 }; |
531 | 560 |
532 } // namespace blink | 561 } // namespace blink |
533 | 562 |
534 #endif // DrawingBuffer_h | 563 #endif // DrawingBuffer_h |
OLD | NEW |