Title: [161389] trunk/Source/WebCore
Revision
161389
Author
[email protected]
Date
2014-01-06 17:44:33 -0800 (Mon, 06 Jan 2014)

Log Message

[WebGL] Be safer about toggling OpenGL state by using a scoped object to control setting lifetime.
https://bugs.webkit.org/show_bug.cgi?id=126548

Reviewed by Anders Carlsson.

No new tests since there is no change in behavior.

* GNUmakefile.list.am: Updated to build new TemporaryOpenGLSetting files.
* PlatformBlackBerry.cmake: Ditto
* PlatformEfl.cmake: Ditto
* PlatformGTK.cmake: Ditto
* PlatformNix.cmake: Ditto
* WebCore.vcxproj/WebCore.vcxproj: Ditto
* WebCore.vcxproj/WebCore.vcxproj.filters: Ditto
* WebCore.xcodeproj/project.pbxproj: Ditto
* platform/graphics/opengl/GraphicsContext3DOpenGL.cpp:
(WebCore::GraphicsContext3D::resolveMultisamplingIfNecessary): Use new object.
* platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
(WebCore::GraphicsContext3D::prepareTexture): Ditto
(WebCore::GraphicsContext3D::reshape): Ditto
* platform/graphics/opengl/TemporaryOpenGLSetting.cpp: Added.
(WebCore::TemporaryOpenGLSetting::TemporaryOpenGLSetting):
(WebCore::TemporaryOpenGLSetting::~TemporaryOpenGLSetting):
* platform/graphics/opengl/TemporaryOpenGLSetting.h: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (161388 => 161389)


--- trunk/Source/WebCore/ChangeLog	2014-01-07 01:41:41 UTC (rev 161388)
+++ trunk/Source/WebCore/ChangeLog	2014-01-07 01:44:33 UTC (rev 161389)
@@ -1,3 +1,30 @@
+2014-01-06  Brent Fulgham  <[email protected]>
+
+        [WebGL] Be safer about toggling OpenGL state by using a scoped object to control setting lifetime.
+        https://bugs.webkit.org/show_bug.cgi?id=126548
+
+        Reviewed by Anders Carlsson.
+
+        No new tests since there is no change in behavior.
+
+        * GNUmakefile.list.am: Updated to build new TemporaryOpenGLSetting files.
+        * PlatformBlackBerry.cmake: Ditto
+        * PlatformEfl.cmake: Ditto
+        * PlatformGTK.cmake: Ditto
+        * PlatformNix.cmake: Ditto
+        * WebCore.vcxproj/WebCore.vcxproj: Ditto
+        * WebCore.vcxproj/WebCore.vcxproj.filters: Ditto
+        * WebCore.xcodeproj/project.pbxproj: Ditto
+        * platform/graphics/opengl/GraphicsContext3DOpenGL.cpp:
+        (WebCore::GraphicsContext3D::resolveMultisamplingIfNecessary): Use new object.
+        * platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
+        (WebCore::GraphicsContext3D::prepareTexture): Ditto
+        (WebCore::GraphicsContext3D::reshape): Ditto
+        * platform/graphics/opengl/TemporaryOpenGLSetting.cpp: Added.
+        (WebCore::TemporaryOpenGLSetting::TemporaryOpenGLSetting):
+        (WebCore::TemporaryOpenGLSetting::~TemporaryOpenGLSetting):
+        * platform/graphics/opengl/TemporaryOpenGLSetting.h: Added.
+
 2014-01-06  Simon Fraser  <[email protected]>
 
         Hook up the RemoteScrollingCoordinator

Modified: trunk/Source/WebCore/GNUmakefile.list.am (161388 => 161389)


--- trunk/Source/WebCore/GNUmakefile.list.am	2014-01-07 01:41:41 UTC (rev 161388)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2014-01-07 01:44:33 UTC (rev 161389)
@@ -5385,6 +5385,8 @@
 	Source/WebCore/platform/graphics/MediaPlayer.h \
 	Source/WebCore/platform/graphics/MediaPlayerPrivate.h \
 	Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp \
+	Source/WebCore/platform/graphics/opengl/TemporaryOpenGLSetting.cpp \
+	Source/WebCore/platform/graphics/opengl/TemporaryOpenGLSetting.h \
 	Source/WebCore/platform/graphics/transforms/PerspectiveTransformOperation.cpp \
 	Source/WebCore/platform/graphics/transforms/PerspectiveTransformOperation.h \
 	Source/WebCore/platform/graphics/transforms/TranslateTransformOperation.cpp \

Modified: trunk/Source/WebCore/PlatformBlackBerry.cmake (161388 => 161389)


--- trunk/Source/WebCore/PlatformBlackBerry.cmake	2014-01-07 01:41:41 UTC (rev 161388)
+++ trunk/Source/WebCore/PlatformBlackBerry.cmake	2014-01-07 01:44:33 UTC (rev 161389)
@@ -177,6 +177,7 @@
         platform/graphics/opengl/Extensions3DOpenGLES.cpp
         platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
         platform/graphics/opengl/GraphicsContext3DOpenGLES.cpp
+        platform/graphics/opengl/TemporaryOpenGLSetting.cpp
     )
 endif ()
 

Modified: trunk/Source/WebCore/PlatformEfl.cmake (161388 => 161389)


--- trunk/Source/WebCore/PlatformEfl.cmake	2014-01-07 01:41:41 UTC (rev 161388)
+++ trunk/Source/WebCore/PlatformEfl.cmake	2014-01-07 01:44:33 UTC (rev 161389)
@@ -310,6 +310,7 @@
         platform/graphics/opengl/GLPlatformContext.cpp
         platform/graphics/opengl/GLPlatformSurface.cpp
         platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
+        platform/graphics/opengl/TemporaryOpenGLSetting.cpp
 
         platform/graphics/surfaces/GLTransportSurface.cpp
         platform/graphics/surfaces/GraphicsSurface.cpp

Modified: trunk/Source/WebCore/PlatformGTK.cmake (161388 => 161389)


--- trunk/Source/WebCore/PlatformGTK.cmake	2014-01-07 01:41:41 UTC (rev 161388)
+++ trunk/Source/WebCore/PlatformGTK.cmake	2014-01-07 01:44:33 UTC (rev 161389)
@@ -97,6 +97,7 @@
     platform/graphics/opengl/Extensions3DOpenGLES.cpp
     platform/graphics/opengl/GraphicsContext3DOpenGL.cpp
     platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
+    platform/graphics/opengl/TemporaryOpenGLSetting.cpp
 
     platform/graphics/opentype/OpenTypeVerticalData.cpp
 

Modified: trunk/Source/WebCore/PlatformNix.cmake (161388 => 161389)


--- trunk/Source/WebCore/PlatformNix.cmake	2014-01-07 01:41:41 UTC (rev 161388)
+++ trunk/Source/WebCore/PlatformNix.cmake	2014-01-07 01:44:33 UTC (rev 161389)
@@ -70,6 +70,7 @@
 
     platform/graphics/opengl/Extensions3DOpenGLCommon.cpp
     platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp
+    platform/graphics/opengl/TemporaryOpenGLSetting.cpp
 
     platform/graphics/opentype/OpenTypeVerticalData.cpp
 

Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj (161388 => 161389)


--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2014-01-07 01:41:41 UTC (rev 161388)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj	2014-01-07 01:44:33 UTC (rev 161389)
@@ -7433,6 +7433,7 @@
     <ClCompile Include="..\platform\graphics\opengl\GLPlatformSurface.cpp" />
     <ClCompile Include="..\platform\graphics\opengl\GraphicsContext3DOpenGLCommon.cpp" />
     <ClCompile Include="..\platform\graphics\opengl\GraphicsContext3DOpenGLES.cpp" />
+    <ClCompile Include="..\platform\graphics\opengl\TemporaryOpenGLSetting.cpp" />
     <ClCompile Include="..\platform\graphics\texmap\coordinated\AreaAllocator.cpp" />
     <ClCompile Include="..\platform\graphics\texmap\coordinated\CompositingCoordinator.cpp" />
     <ClCompile Include="..\platform\graphics\texmap\coordinated\CoordinatedBackingStore.cpp" />
@@ -21135,4 +21136,4 @@
   <ImportGroup Label="ExtensionTargets">
     <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>

Modified: trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters (161388 => 161389)


--- trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters	2014-01-07 01:41:41 UTC (rev 161388)
+++ trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters	2014-01-07 01:44:33 UTC (rev 161389)
@@ -6814,6 +6814,9 @@
     <ClCompile Include="..\platform\graphics\opengl\GraphicsContext3DOpenGLCommon.cpp">
       <Filter>platform\graphics\opengl</Filter>
     </ClCompile>
+    <ClCompile Include="..\platform\graphics\opengl\TemporaryOpenGLSetting.cpp">
+      <Filter>platform\graphics\opengl</Filter>
+    </ClCompile>
     <ClCompile Include="..\page\CaptionUserPreferencesMediaAF.cpp">
       <Filter>page</Filter>
     </ClCompile>

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (161388 => 161389)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-01-07 01:41:41 UTC (rev 161388)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2014-01-07 01:44:33 UTC (rev 161389)
@@ -1966,9 +1966,9 @@
 		5DF7F5C20F01F92A00526B4B /* CSSPropertyNames.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 656580EF09D12B20000E61D7 /* CSSPropertyNames.h */; };
 		5DFE8F560D16477B0076E937 /* ScheduledAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCA378BA0D15F64200B793D6 /* ScheduledAction.cpp */; };
 		5DFE8F570D16477C0076E937 /* ScheduledAction.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA378BB0D15F64200B793D6 /* ScheduledAction.h */; };
+		5DFEBAB718592B6D00C75BEB /* WebKitAvailability.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DFEBAB618592B6D00C75BEB /* WebKitAvailability.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		5F2DBBE9178E3C8100141486 /* CertificateInfoMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5F2DBBE7178E332D00141486 /* CertificateInfoMac.mm */; };
 		5FA904CA178E61F5004C8A2D /* CertificateInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F2DBBE8178E336900141486 /* CertificateInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		5DFEBAB718592B6D00C75BEB /* WebKitAvailability.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DFEBAB618592B6D00C75BEB /* WebKitAvailability.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		5FC7DC26CFE2563200B85AE4 /* JSEventTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = 5FC7DC26CFE2563200B85AE5 /* JSEventTarget.h */; };
 		5FE1D292178FD1F3001AA3C3 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5FE1D291178FD1F3001AA3C3 /* Security.framework */; };
 		626CDE0E1140424C001E5A68 /* SpatialNavigation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 626CDE0C1140424C001E5A68 /* SpatialNavigation.cpp */; };
@@ -2205,6 +2205,7 @@
 		7A1F2B52126C61B20006A7E6 /* InspectorClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A1F2B51126C61B20006A7E6 /* InspectorClient.cpp */; };
 		7A24587B1021EAF4000A00AA /* InspectorDOMAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A2458791021EAF4000A00AA /* InspectorDOMAgent.cpp */; };
 		7A24587C1021EAF4000A00AA /* InspectorDOMAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A24587A1021EAF4000A00AA /* InspectorDOMAgent.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		7A29BA6A187B7C1D00F29CEB /* TemporaryOpenGLSetting.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A29BA69187B781C00F29CEB /* TemporaryOpenGLSetting.cpp */; };
 		7A54857F14E02D51006AE05A /* InspectorHistory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A54857D14E02D51006AE05A /* InspectorHistory.cpp */; };
 		7A54858014E02D51006AE05A /* InspectorHistory.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A54857E14E02D51006AE05A /* InspectorHistory.h */; };
 		7A54881714E432A1006AE05A /* DOMPatchSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A54881514E432A1006AE05A /* DOMPatchSupport.h */; };
@@ -8767,9 +8768,9 @@
 		5DA97ECC168E787B000E3676 /* SystemVersionMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemVersionMac.mm; sourceTree = "<group>"; };
 		5DB1BC6810715A6400EFAA49 /* TransformSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TransformSource.h; sourceTree = "<group>"; };
 		5DB1BC6910715A6400EFAA49 /* TransformSourceLibxslt.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TransformSourceLibxslt.cpp; sourceTree = "<group>"; };
+		5DFEBAB618592B6D00C75BEB /* WebKitAvailability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitAvailability.h; sourceTree = "<group>"; };
 		5F2DBBE7178E332D00141486 /* CertificateInfoMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CertificateInfoMac.mm; sourceTree = "<group>"; };
 		5F2DBBE8178E336900141486 /* CertificateInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CertificateInfo.h; sourceTree = "<group>"; };
-		5DFEBAB618592B6D00C75BEB /* WebKitAvailability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitAvailability.h; sourceTree = "<group>"; };
 		5FC7DC26CFE2563200B85AE5 /* JSEventTarget.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSEventTarget.h; sourceTree = "<group>"; };
 		5FE1D291178FD1F3001AA3C3 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
 		626CDE0C1140424C001E5A68 /* SpatialNavigation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpatialNavigation.cpp; sourceTree = "<group>"; };
@@ -9036,6 +9037,8 @@
 		7A1F2B51126C61B20006A7E6 /* InspectorClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorClient.cpp; sourceTree = "<group>"; };
 		7A2458791021EAF4000A00AA /* InspectorDOMAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorDOMAgent.cpp; sourceTree = "<group>"; };
 		7A24587A1021EAF4000A00AA /* InspectorDOMAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorDOMAgent.h; sourceTree = "<group>"; };
+		7A29BA67187B732200F29CEB /* TemporaryOpenGLSetting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TemporaryOpenGLSetting.h; sourceTree = "<group>"; };
+		7A29BA69187B781C00F29CEB /* TemporaryOpenGLSetting.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TemporaryOpenGLSetting.cpp; sourceTree = "<group>"; };
 		7A54857D14E02D51006AE05A /* InspectorHistory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorHistory.cpp; sourceTree = "<group>"; };
 		7A54857E14E02D51006AE05A /* InspectorHistory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorHistory.h; sourceTree = "<group>"; };
 		7A54881514E432A1006AE05A /* DOMPatchSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMPatchSupport.h; sourceTree = "<group>"; };
@@ -21863,6 +21866,8 @@
 		FBC220DD1237FBEB00BCF788 /* opengl */ = {
 			isa = PBXGroup;
 			children = (
+				7A29BA69187B781C00F29CEB /* TemporaryOpenGLSetting.cpp */,
+				7A29BA67187B732200F29CEB /* TemporaryOpenGLSetting.h */,
 				6E67D2A41280E8A4008758F7 /* Extensions3DOpenGL.cpp */,
 				6E67D2A51280E8A4008758F7 /* Extensions3DOpenGL.h */,
 				44DAB5AF15A623580097C1E4 /* Extensions3DOpenGLCommon.cpp */,
@@ -25850,6 +25855,7 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				7A29BA6A187B7C1D00F29CEB /* TemporaryOpenGLSetting.cpp in Sources */,
 				41E1B1D00FF5986900576B3B /* AbstractWorker.cpp in Sources */,
 				0F29C16E1300C2E2002D794E /* AccessibilityAllInOne.cpp in Sources */,
 				76CDD2F21103DA6600680521 /* AccessibilityMenuList.cpp in Sources */,

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp (161388 => 161389)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp	2014-01-07 01:41:41 UTC (rev 161388)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp	2014-01-07 01:44:33 UTC (rev 161389)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2013 Apple Inc. All rights reserved.
  * Copyright (C) 2011 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -34,6 +34,7 @@
 #include "IntRect.h"
 #include "IntSize.h"
 #include "NotImplemented.h"
+#include "TemporaryOpenGLSetting.h"
 
 #include <algorithm>
 #include <cstring>
@@ -161,11 +162,9 @@
 
 void GraphicsContext3D::resolveMultisamplingIfNecessary(const IntRect& rect)
 {
-    GLboolean isScissorEnabled = ::glIsEnabled(GL_SCISSOR_TEST);
-    ::glDisable(GL_SCISSOR_TEST);
-    GLboolean isDitherEnabled = ::glIsEnabled(GL_DITHER);
-    ::glDisable(GL_DITHER);
-    
+    TemporaryOpenGLSetting scopedScissor(GL_SCISSOR_TEST, GL_FALSE);
+    TemporaryOpenGLSetting scopedDither(GL_SCISSOR_TEST, GL_FALSE);
+
     ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
     ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
 
@@ -174,11 +173,6 @@
         resolveRect = IntRect(0, 0, m_currentWidth, m_currentHeight);
 
     ::glBlitFramebufferEXT(resolveRect.x(), resolveRect.y(), resolveRect.maxX(), resolveRect.maxY(), resolveRect.x(), resolveRect.y(), resolveRect.maxX(), resolveRect.maxY(), GL_COLOR_BUFFER_BIT, GL_LINEAR);
-
-    if (isScissorEnabled)
-        ::glEnable(GL_SCISSOR_TEST);
-    if (isDitherEnabled)
-        ::glEnable(GL_DITHER);
 }
 
 void GraphicsContext3D::renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height)

Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp (161388 => 161389)


--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp	2014-01-07 01:41:41 UTC (rev 161388)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp	2014-01-07 01:44:33 UTC (rev 161389)
@@ -44,6 +44,7 @@
 #include "IntSize.h"
 #include "Logging.h"
 #include "NotImplemented.h"
+#include "TemporaryOpenGLSetting.h"
 #include <cstring>
 #include <runtime/ArrayBuffer.h>
 #include <runtime/ArrayBufferView.h>
@@ -196,10 +197,8 @@
 
     makeContextCurrent();
 
-    GLboolean isScissorEnabled = ::glIsEnabled(GL_SCISSOR_TEST);
-    ::glDisable(GL_SCISSOR_TEST);
-    GLboolean isDitherEnabled = ::glIsEnabled(GL_DITHER);
-    ::glDisable(GL_DITHER);
+    TemporaryOpenGLSetting scopedScissor(GL_SCISSOR_TEST, GL_FALSE);
+    TemporaryOpenGLSetting scopedDither(GL_SCISSOR_TEST, GL_FALSE);
     
     if (m_attrs.antialias)
         resolveMultisamplingIfNecessary();
@@ -214,11 +213,6 @@
         ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_state.boundFBO);
     ::glFinish();
     m_layerComposited = true;
-
-    if (isScissorEnabled)
-        ::glEnable(GL_SCISSOR_TEST);
-    if (isDitherEnabled)
-        ::glEnable(GL_DITHER);
 }
 #endif
 
@@ -284,8 +278,6 @@
     GLint clearStencil = 0;
     GLboolean colorMask[] = {GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE}, depthMask = GL_TRUE;
     GLuint stencilMask = 0xffffffff;
-    GLboolean isScissorEnabled = GL_FALSE;
-    GLboolean isDitherEnabled = GL_FALSE;
     GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
     ::glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor);
     ::glClearColor(0, 0, 0, 0);
@@ -305,11 +297,10 @@
         ::glStencilMaskSeparate(GL_FRONT, 0xffffffff);
         clearMask |= GL_STENCIL_BUFFER_BIT;
     }
-    isScissorEnabled = ::glIsEnabled(GL_SCISSOR_TEST);
-    ::glDisable(GL_SCISSOR_TEST);
-    isDitherEnabled = ::glIsEnabled(GL_DITHER);
-    ::glDisable(GL_DITHER);
 
+    TemporaryOpenGLSetting scopedScissor(GL_SCISSOR_TEST, GL_FALSE);
+    TemporaryOpenGLSetting scopedDither(GL_SCISSOR_TEST, GL_FALSE);
+
     ::glClear(clearMask);
 
     ::glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
@@ -322,14 +313,6 @@
         ::glClearStencil(clearStencil);
         ::glStencilMaskSeparate(GL_FRONT, stencilMask);
     }
-    if (isScissorEnabled)
-        ::glEnable(GL_SCISSOR_TEST);
-    else
-        ::glDisable(GL_SCISSOR_TEST);
-    if (isDitherEnabled)
-        ::glEnable(GL_DITHER);
-    else
-        ::glDisable(GL_DITHER);
 
     if (mustRestoreFBO)
         ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_state.boundFBO);

Added: trunk/Source/WebCore/platform/graphics/opengl/TemporaryOpenGLSetting.cpp (0 => 161389)


--- trunk/Source/WebCore/platform/graphics/opengl/TemporaryOpenGLSetting.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/opengl/TemporaryOpenGLSetting.cpp	2014-01-07 01:44:33 UTC (rev 161389)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if USE(3D_GRAPHICS)
+#include "TemporaryOpenGLSetting.h"
+
+#if USE(OPENGL_ES_2)
+#include "OpenGLESShims.h"
+#elif PLATFORM(MAC)
+#include <OpenGL/gl.h>
+#elif PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN) || PLATFORM(NIX)
+#include "OpenGLShims.h"
+#endif
+
+namespace WebCore {
+
+TemporaryOpenGLSetting::TemporaryOpenGLSetting(GLenum capability, GLenum scopedState)
+    : m_capability(capability)
+    , m_scopedState(scopedState)
+{
+    m_originalState = ::glIsEnabled(m_capability);
+    if (m_originalState == m_scopedState)
+        return;
+
+    if (GL_TRUE == m_scopedState)
+        ::glEnable(m_capability);
+    else
+        ::glDisable(m_capability);
+}
+
+TemporaryOpenGLSetting::~TemporaryOpenGLSetting()
+{
+    if (m_originalState == m_scopedState)
+        return;
+
+    if (GL_TRUE == m_originalState)
+        ::glEnable(m_capability);
+    else
+        ::glDisable(m_capability);
+}
+
+}
+
+#endif

Added: trunk/Source/WebCore/platform/graphics/opengl/TemporaryOpenGLSetting.h (0 => 161389)


--- trunk/Source/WebCore/platform/graphics/opengl/TemporaryOpenGLSetting.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/opengl/TemporaryOpenGLSetting.h	2014-01-07 01:44:33 UTC (rev 161389)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TemporaryOpenGLSetting_h
+#define TemporaryOpenGLSetting_h
+
+#include "GraphicsTypes3D.h"
+
+#include <wtf/Noncopyable.h>
+
+namespace WebCore {
+
+// TemporaryOpenGLSetting<> is useful for temporarily disabling (or enabling) a particular OpenGL
+// feature with a particular scope. A TemporaryOpenGLSetting<> object returns the flag to its original
+// value upon destruction, making it an alternative to checking, clearing, and resetting each flag
+// at all of a block's exit points.
+//
+// Based on WTF::TemporaryChange<>
+
+class TemporaryOpenGLSetting {
+    WTF_MAKE_NONCOPYABLE(TemporaryOpenGLSetting);
+public:
+    TemporaryOpenGLSetting(GC3Denum capability, GC3Denum scopedState);
+    ~TemporaryOpenGLSetting();
+
+private:
+    const GC3Denum m_capability;
+    const GC3Denum m_scopedState;
+    GC3Denum m_originalState;
+};
+
+}
+
+using WebCore::TemporaryOpenGLSetting;
+
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to