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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h

Issue 2402273002: DrawingBuffer: Clean up GL state restoration (Closed)
Patch Set: Incorporate review feedback Created 4 years, 2 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) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 GLboolean* colorMask, 126 GLboolean* colorMask,
127 DrawingBuffer*); 127 DrawingBuffer*);
128 ~ScopedRGBEmulationColorMask(); 128 ~ScopedRGBEmulationColorMask();
129 129
130 private: 130 private:
131 gpu::gles2::GLES2Interface* m_contextGL; 131 gpu::gles2::GLES2Interface* m_contextGL;
132 GLboolean m_colorMask[4]; 132 GLboolean m_colorMask[4];
133 const bool m_requiresEmulation; 133 const bool m_requiresEmulation;
134 }; 134 };
135 135
136 class MODULES_EXPORT WebGLRenderingContextBase : public CanvasRenderingContext { 136 class MODULES_EXPORT WebGLRenderingContextBase : public CanvasRenderingContext,
137 public DrawingBuffer::Client {
137 WTF_MAKE_NONCOPYABLE(WebGLRenderingContextBase); 138 WTF_MAKE_NONCOPYABLE(WebGLRenderingContextBase);
138 139
139 public: 140 public:
140 ~WebGLRenderingContextBase() override; 141 ~WebGLRenderingContextBase() override;
141 142
142 virtual String contextName() const = 0; 143 virtual String contextName() const = 0;
143 virtual void registerContextExtensions() = 0; 144 virtual void registerContextExtensions() = 0;
144 145
145 virtual void initializeNewContext(); 146 virtual void initializeNewContext();
146 147
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 void forceLostContext(LostContextMode, AutoRecoveryMethod); 540 void forceLostContext(LostContextMode, AutoRecoveryMethod);
540 void forceRestoreContext(); 541 void forceRestoreContext();
541 void loseContextImpl(LostContextMode, AutoRecoveryMethod); 542 void loseContextImpl(LostContextMode, AutoRecoveryMethod);
542 543
543 // Utilities to restore GL state to match the rendering context's 544 // Utilities to restore GL state to match the rendering context's
544 // saved state. Use these after contextGL()-based state changes that 545 // saved state. Use these after contextGL()-based state changes that
545 // bypass the rendering context. 546 // bypass the rendering context.
546 void restoreScissorEnabled(); 547 void restoreScissorEnabled();
547 void restoreScissorBox(); 548 void restoreScissorBox();
548 void restoreClearColor(); 549 void restoreClearColor();
549 void restoreClearDepthf();
550 void restoreClearStencil();
551 void restoreStencilMaskSeparate();
552 void restoreColorMask(); 550 void restoreColorMask();
553 void restoreDepthMask();
554 551
555 gpu::gles2::GLES2Interface* contextGL() const { 552 gpu::gles2::GLES2Interface* contextGL() const {
556 DrawingBuffer* d = drawingBuffer(); 553 DrawingBuffer* d = drawingBuffer();
557 if (!d) 554 if (!d)
558 return nullptr; 555 return nullptr;
559 return d->contextGL(); 556 return d->contextGL();
560 } 557 }
561 WebGLContextGroup* contextGroup() const { return m_contextGroup.get(); } 558 WebGLContextGroup* contextGroup() const { return m_contextGroup.get(); }
562 Extensions3DUtil* extensionsUtil(); 559 Extensions3DUtil* extensionsUtil();
563 560
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 friend class WebGLDebugShaders; 611 friend class WebGLDebugShaders;
615 friend class WebGLCompressedTextureASTC; 612 friend class WebGLCompressedTextureASTC;
616 friend class WebGLCompressedTextureATC; 613 friend class WebGLCompressedTextureATC;
617 friend class WebGLCompressedTextureETC; 614 friend class WebGLCompressedTextureETC;
618 friend class WebGLCompressedTextureETC1; 615 friend class WebGLCompressedTextureETC1;
619 friend class WebGLCompressedTexturePVRTC; 616 friend class WebGLCompressedTexturePVRTC;
620 friend class WebGLCompressedTextureS3TC; 617 friend class WebGLCompressedTextureS3TC;
621 friend class WebGLCompressedTextureS3TCsRGB; 618 friend class WebGLCompressedTextureS3TCsRGB;
622 friend class WebGLRenderingContextErrorMessageCallback; 619 friend class WebGLRenderingContextErrorMessageCallback;
623 friend class WebGLVertexArrayObjectBase; 620 friend class WebGLVertexArrayObjectBase;
621 friend class ScopedDrawingBufferBinder;
624 friend class ScopedTexture2DRestorer; 622 friend class ScopedTexture2DRestorer;
625 friend class ScopedFramebufferRestorer; 623 friend class ScopedFramebufferRestorer;
626 // To allow V8WebGL[2]RenderingContext to call visitChildDOMWrappers. 624 // To allow V8WebGL[2]RenderingContext to call visitChildDOMWrappers.
627 friend class V8WebGLRenderingContext; 625 friend class V8WebGLRenderingContext;
628 626
629 WebGLRenderingContextBase(HTMLCanvasElement*, 627 WebGLRenderingContextBase(HTMLCanvasElement*,
630 std::unique_ptr<WebGraphicsContext3DProvider>, 628 std::unique_ptr<WebGraphicsContext3DProvider>,
631 const CanvasContextCreationAttributes&, 629 const CanvasContextCreationAttributes&,
632 unsigned); 630 unsigned);
633 WebGLRenderingContextBase(OffscreenCanvas*, 631 WebGLRenderingContextBase(OffscreenCanvas*,
634 std::unique_ptr<WebGraphicsContext3DProvider>, 632 std::unique_ptr<WebGraphicsContext3DProvider>,
635 const CanvasContextCreationAttributes&, 633 const CanvasContextCreationAttributes&,
636 unsigned); 634 unsigned);
637 PassRefPtr<DrawingBuffer> createDrawingBuffer( 635 PassRefPtr<DrawingBuffer> createDrawingBuffer(
638 std::unique_ptr<WebGraphicsContext3DProvider>, 636 std::unique_ptr<WebGraphicsContext3DProvider>,
639 DrawingBuffer::ChromiumImageUsage); 637 DrawingBuffer::ChromiumImageUsage);
640 void setupFlags(); 638 void setupFlags();
641 639
642 // CanvasRenderingContext implementation. 640 // CanvasRenderingContext implementation.
643 bool is3d() const override { return true; } 641 bool is3d() const override { return true; }
644 bool isAccelerated() const override { return true; } 642 bool isAccelerated() const override { return true; }
645 void setIsHidden(bool) override; 643 void setIsHidden(bool) override;
646 bool paintRenderingResultsToCanvas(SourceDrawingBuffer) override; 644 bool paintRenderingResultsToCanvas(SourceDrawingBuffer) override;
647 WebLayer* platformLayer() const override; 645 WebLayer* platformLayer() const override;
648 void stop() override; 646 void stop() override;
649 647
648 // DrawingBuffer::Client implementation.
649 bool DrawingBufferClientIsBoundForDraw() override;
650 void DrawingBufferClientRestoreScissorTest() override;
651 void DrawingBufferClientRestoreMaskAndClearValues() override;
652 void DrawingBufferClientRestorePixelPackAlignment() override;
653 void DrawingBufferClientRestoreTexture2DBinding() override;
654 void DrawingBufferClientRestoreRenderbufferBinding() override;
655 void DrawingBufferClientRestoreFramebufferBinding() override;
656 void DrawingBufferClientRestorePixelUnpackBufferBinding() override;
657
650 void addSharedObject(WebGLSharedObject*); 658 void addSharedObject(WebGLSharedObject*);
651 void addContextObject(WebGLContextObject*); 659 void addContextObject(WebGLContextObject*);
652 void detachAndRemoveAllObjects(); 660 void detachAndRemoveAllObjects();
653 661
654 virtual void destroyContext(); 662 virtual void destroyContext();
655 void markContextChanged(ContentChangeType); 663 void markContextChanged(ContentChangeType);
656 664
657 void onErrorMessage(const char*, int32_t id); 665 void onErrorMessage(const char*, int32_t id);
658 666
659 void notifyCanvasContextChanged(); 667 void notifyCanvasContextChanged();
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 class ScopedDrawingBufferBinder { 918 class ScopedDrawingBufferBinder {
911 STACK_ALLOCATED(); 919 STACK_ALLOCATED();
912 920
913 public: 921 public:
914 ScopedDrawingBufferBinder(DrawingBuffer* drawingBuffer, 922 ScopedDrawingBufferBinder(DrawingBuffer* drawingBuffer,
915 WebGLFramebuffer* framebufferBinding) 923 WebGLFramebuffer* framebufferBinding)
916 : m_drawingBuffer(drawingBuffer), 924 : m_drawingBuffer(drawingBuffer),
917 m_readFramebufferBinding(framebufferBinding) { 925 m_readFramebufferBinding(framebufferBinding) {
918 // Commit DrawingBuffer if needed (e.g., for multisampling) 926 // Commit DrawingBuffer if needed (e.g., for multisampling)
919 if (!m_readFramebufferBinding && m_drawingBuffer) 927 if (!m_readFramebufferBinding && m_drawingBuffer)
920 m_drawingBuffer->commit(); 928 m_drawingBuffer->resolveAndBindForReadAndDraw();
921 } 929 }
922 930
923 ~ScopedDrawingBufferBinder() { 931 ~ScopedDrawingBufferBinder() {
924 // Restore DrawingBuffer if needed 932 // Restore DrawingBuffer if needed
925 if (!m_readFramebufferBinding && m_drawingBuffer) 933 if (!m_readFramebufferBinding && m_drawingBuffer)
926 m_drawingBuffer->restoreFramebufferBindings(); 934 m_drawingBuffer->restoreFramebufferBindings();
927 } 935 }
928 936
929 private: 937 private:
930 DrawingBuffer* m_drawingBuffer; 938 DrawingBuffer* m_drawingBuffer;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 // Skip clearing the backbuffer. 978 // Skip clearing the backbuffer.
971 Skipped, 979 Skipped,
972 // Clear the backbuffer. 980 // Clear the backbuffer.
973 JustClear, 981 JustClear,
974 // Combine webgl.clear() API with the backbuffer clear, so webgl.clear() 982 // Combine webgl.clear() API with the backbuffer clear, so webgl.clear()
975 // doesn't have to call glClear() again. 983 // doesn't have to call glClear() again.
976 CombinedClear 984 CombinedClear
977 }; 985 };
978 HowToClear clearIfComposited(GLbitfield clearMask = 0); 986 HowToClear clearIfComposited(GLbitfield clearMask = 0);
979 987
980 // Helper to restore state that clearing the framebuffer may destroy.
981 void restoreStateAfterClear();
982
983 // Convert texture internal format. 988 // Convert texture internal format.
984 GLenum convertTexInternalFormat(GLenum internalformat, GLenum type); 989 GLenum convertTexInternalFormat(GLenum internalformat, GLenum type);
985 990
986 enum TexImageFunctionType { 991 enum TexImageFunctionType {
987 TexImage, 992 TexImage,
988 TexSubImage, 993 TexSubImage,
989 CopyTexImage, 994 CopyTexImage,
990 CompressedTexImage 995 CompressedTexImage
991 }; 996 };
992 enum TexImageFunctionID { 997 enum TexImageFunctionID {
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 context, 1557 context,
1553 context->is3d(), 1558 context->is3d(),
1554 context.is3d()); 1559 context.is3d());
1555 1560
1556 } // namespace blink 1561 } // namespace blink
1557 1562
1558 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS( 1563 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(
1559 blink::WebGLRenderingContextBase::TextureUnitState); 1564 blink::WebGLRenderingContextBase::TextureUnitState);
1560 1565
1561 #endif // WebGLRenderingContextBase_h 1566 #endif // WebGLRenderingContextBase_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698