Diff
Modified: trunk/Source/WebKit/chromium/ChangeLog (94105 => 94106)
--- trunk/Source/WebKit/chromium/ChangeLog 2011-08-30 20:42:46 UTC (rev 94105)
+++ trunk/Source/WebKit/chromium/ChangeLog 2011-08-30 20:43:14 UTC (rev 94106)
@@ -1,3 +1,23 @@
+2011-08-30 Nat Duca <[email protected]>
+
+ [chromium] Allow GraphicsContexts to be created from MockWebGraphicsContexts
+ https://bugs.webkit.org/show_bug.cgi?id=67179
+
+ Reviewed by Kenneth Russell.
+
+ * WebKit.gypi:
+ * src/GraphicsContext3DChromium.cpp:
+ (WebCore::GraphicsContext3DInternal::GraphicsContext3DInternal):
+ (WebCore::GraphicsContext3DInternal::create):
+ (WebCore::GraphicsContext3DInternal::createFromWebContext):
+ (WebCore::GraphicsContext3D::create):
+ * src/GraphicsContext3DInternal.h:
+ * tests/MockGraphicsContext3DTest.cpp: Renamed from Source/WebKit/chromium/tests/MockWebGraphicsContext3DTest.cpp.
+ (FrameCountingContext::FrameCountingContext):
+ (FrameCountingContext::prepareTexture):
+ (FrameCountingContext::frameCount):
+ (TEST):
+
2011-08-30 Adam Barth <[email protected]>
[Chromium] Add null checks for document()->loader()
Modified: trunk/Source/WebKit/chromium/WebKit.gypi (94105 => 94106)
--- trunk/Source/WebKit/chromium/WebKit.gypi 2011-08-30 20:42:46 UTC (rev 94105)
+++ trunk/Source/WebKit/chromium/WebKit.gypi 2011-08-30 20:43:14 UTC (rev 94106)
@@ -63,8 +63,9 @@
'tests/InnerGestureRecognizerTest.cpp',
'tests/KeyboardTest.cpp',
'tests/KURLTest.cpp',
+ 'tests/MockGraphicsContext3D.h',
+ 'tests/MockGraphicsContext3DTest.cpp',
'tests/MockWebGraphicsContext3D.h',
- 'tests/MockWebGraphicsContext3DTest.cpp',
'tests/PODArenaTest.cpp',
'tests/PODIntervalTreeTest.cpp',
'tests/PODRedBlackTreeTest.cpp',
Modified: trunk/Source/WebKit/chromium/src/GraphicsContext3DChromium.cpp (94105 => 94106)
--- trunk/Source/WebKit/chromium/src/GraphicsContext3DChromium.cpp 2011-08-30 20:42:46 UTC (rev 94105)
+++ trunk/Source/WebKit/chromium/src/GraphicsContext3DChromium.cpp 2011-08-30 20:43:14 UTC (rev 94106)
@@ -83,8 +83,9 @@
//----------------------------------------------------------------------
// GraphicsContext3DPrivate
-GraphicsContext3DPrivate::GraphicsContext3DPrivate()
- : m_webViewImpl(0)
+GraphicsContext3DPrivate::GraphicsContext3DPrivate(WebKit::WebViewImpl* webViewImpl, PassOwnPtr<WebKit::WebGraphicsContext3D> webContext)
+ : m_impl(webContext)
+ , m_webViewImpl(webViewImpl)
, m_initializedAvailableExtensions(false)
, m_layerComposited(false)
, m_resourceSafety(ResourceSafetyUnknown)
@@ -96,6 +97,9 @@
#error Must port to your platform
#endif
{
+#if USE(ACCELERATED_COMPOSITING)
+ m_compositingLayer = WebGLLayerChromium::create(0);
+#endif
}
GraphicsContext3DPrivate::~GraphicsContext3DPrivate()
@@ -108,32 +112,22 @@
#endif
}
-bool GraphicsContext3DPrivate::initialize(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, bool renderDirectlyToHostWindow)
+
+PassOwnPtr<GraphicsContext3DPrivate> GraphicsContext3DPrivate::create(WebKit::WebViewImpl* webViewImpl, PassOwnPtr<WebKit::WebGraphicsContext3D> webContext)
{
- WebKit::WebGraphicsContext3D::Attributes webAttributes;
- webAttributes.alpha = attrs.alpha;
- webAttributes.depth = attrs.depth;
- webAttributes.stencil = attrs.stencil;
- webAttributes.antialias = attrs.antialias;
- webAttributes.premultipliedAlpha = attrs.premultipliedAlpha;
- webAttributes.canRecoverFromContextLoss = attrs.canRecoverFromContextLoss;
- webAttributes.noExtensions = attrs.noExtensions;
- webAttributes.shareResources = attrs.shareResources;
- OwnPtr<WebKit::WebGraphicsContext3D> webContext = adoptPtr(WebKit::webKitClient()->createGraphicsContext3D());
- if (!webContext)
- return false;
+ return adoptPtr(new GraphicsContext3DPrivate(webViewImpl, webContext));
+}
- Chrome* chrome = static_cast<Chrome*>(hostWindow);
- m_webViewImpl = chrome ? static_cast<WebKit::WebViewImpl*>(chrome->client()->webView()) : 0;
+PassRefPtr<GraphicsContext3D> GraphicsContext3DPrivate::createGraphicsContextFromWebContext(PassOwnPtr<WebKit::WebGraphicsContext3D> webContext, GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle)
+{
+ OwnPtr<GraphicsContext3DPrivate> priv = GraphicsContext3DPrivate::create(0, webContext);
+ if (!priv)
+ return 0;
- if (!webContext->initialize(webAttributes, m_webViewImpl, renderDirectlyToHostWindow))
- return false;
- m_impl = webContext.release();
-
-#if USE(ACCELERATED_COMPOSITING)
- m_compositingLayer = WebGLLayerChromium::create(0);
-#endif
- return true;
+ bool renderDirectlyToHostWindow = renderStyle == GraphicsContext3D::RenderDirectlyToHostWindow;
+ RefPtr<GraphicsContext3D> result = adoptRef(new GraphicsContext3D(attrs, hostWindow, renderDirectlyToHostWindow));
+ result->m_private = priv.release();
+ return result.release();
}
WebKit::WebGraphicsContext3D* GraphicsContext3DPrivate::extractWebGraphicsContext3D(GraphicsContext3D* context)
@@ -978,13 +972,28 @@
PassRefPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle)
{
- OwnPtr<GraphicsContext3DPrivate> priv = adoptPtr(new GraphicsContext3DPrivate());
- if (!priv->initialize(attrs, hostWindow, renderStyle == RenderDirectlyToHostWindow))
+ bool renderDirectlyToHostWindow = renderStyle == RenderDirectlyToHostWindow;
+
+ WebKit::WebGraphicsContext3D::Attributes webAttributes;
+ webAttributes.alpha = attrs.alpha;
+ webAttributes.depth = attrs.depth;
+ webAttributes.stencil = attrs.stencil;
+ webAttributes.antialias = attrs.antialias;
+ webAttributes.premultipliedAlpha = attrs.premultipliedAlpha;
+ webAttributes.canRecoverFromContextLoss = attrs.canRecoverFromContextLoss;
+ webAttributes.noExtensions = attrs.noExtensions;
+ webAttributes.shareResources = attrs.shareResources;
+ OwnPtr<WebKit::WebGraphicsContext3D> webContext = adoptPtr(WebKit::webKitClient()->createGraphicsContext3D());
+ if (!webContext)
return 0;
- RefPtr<GraphicsContext3D> result = adoptRef(new GraphicsContext3D(attrs, hostWindow, renderStyle == RenderDirectlyToHostWindow));
- result->m_private = priv.release();
- return result.release();
+ Chrome* chrome = static_cast<Chrome*>(hostWindow);
+ WebKit::WebViewImpl* webViewImpl = chrome ? static_cast<WebKit::WebViewImpl*>(chrome->client()->webView()) : 0;
+
+ if (!webContext->initialize(webAttributes, webViewImpl, renderDirectlyToHostWindow))
+ return 0;
+
+ return GraphicsContext3DPrivate::createGraphicsContextFromWebContext(webContext.release(), attrs, hostWindow, renderStyle);
}
PlatformGraphicsContext3D GraphicsContext3D::platformGraphicsContext3D() const
Modified: trunk/Source/WebKit/chromium/src/GraphicsContext3DPrivate.h (94105 => 94106)
--- trunk/Source/WebKit/chromium/src/GraphicsContext3DPrivate.h 2011-08-30 20:42:46 UTC (rev 94105)
+++ trunk/Source/WebKit/chromium/src/GraphicsContext3DPrivate.h 2011-08-30 20:43:14 UTC (rev 94106)
@@ -55,7 +55,11 @@
class GraphicsContext3DPrivate {
public:
- GraphicsContext3DPrivate();
+ static PassOwnPtr<GraphicsContext3DPrivate> create(WebKit::WebViewImpl*, PassOwnPtr<WebKit::WebGraphicsContext3D>);
+
+ // Used in tests to create a GraphicsContext3D from a mocked WebGraphicsContext3D.
+ static PassRefPtr<GraphicsContext3D> createGraphicsContextFromWebContext(PassOwnPtr<WebKit::WebGraphicsContext3D>, GraphicsContext3D::Attributes, HostWindow*, GraphicsContext3D::RenderStyle);
+
~GraphicsContext3DPrivate();
bool initialize(GraphicsContext3D::Attributes, HostWindow*, bool renderDirectlyToHostWindow);
@@ -290,6 +294,8 @@
GC3Denum getGraphicsResetStatusARB();
private:
+ GraphicsContext3DPrivate(WebKit::WebViewImpl*, PassOwnPtr<WebKit::WebGraphicsContext3D>);
+
OwnPtr<WebKit::WebGraphicsContext3D> m_impl;
OwnPtr<Extensions3DChromium> m_extensions;
OwnPtr<GraphicsContextLostCallbackAdapter> m_contextLostCallbackAdapter;
Copied: trunk/Source/WebKit/chromium/tests/MockGraphicsContext3DTest.cpp (from rev 94104, trunk/Source/WebKit/chromium/tests/MockWebGraphicsContext3DTest.cpp) (0 => 94106)
--- trunk/Source/WebKit/chromium/tests/MockGraphicsContext3DTest.cpp (rev 0)
+++ trunk/Source/WebKit/chromium/tests/MockGraphicsContext3DTest.cpp 2011-08-30 20:43:14 UTC (rev 94106)
@@ -0,0 +1,90 @@
+/*
+ * 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"
+
+#include "GraphicsContext3D.h"
+
+#include "GraphicsContext3DPrivate.h"
+#include "MockWebGraphicsContext3D.h"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+using namespace WebCore;
+using namespace WebKit;
+using namespace testing;
+
+class FrameCountingContext : public MockWebGraphicsContext3D {
+public:
+ FrameCountingContext() : m_frame(0) { }
+
+ // This method would normally do a glSwapBuffers under the hood.
+ virtual void prepareTexture() { m_frame++; }
+
+ int frameCount() { return m_frame; }
+
+private:
+ int m_frame;
+};
+
+TEST(MockGraphicsContext3DTest, CanOverrideManually)
+{
+ GraphicsContext3D::Attributes attrs;
+ RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new FrameCountingContext()), attrs, 0, GraphicsContext3D::RenderDirectlyToHostWindow);
+ FrameCountingContext& mockContext = *static_cast<FrameCountingContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(context.get()));
+
+ context->makeContextCurrent();
+ for (int i = 0; i < 10; i++) {
+ context->clearColor(0, 0, 0, 1);
+ context->prepareTexture();
+ }
+ context->finish();
+
+ EXPECT_EQ(10, mockContext.frameCount());
+}
+
+
+class GMockContext : public MockWebGraphicsContext3D {
+public:
+ MOCK_METHOD0(getError, WGC3Denum());
+};
+
+TEST(MockGraphicsContext3DTest, CanUseGMock)
+{
+ GraphicsContext3D::Attributes attrs;
+ RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new GMockContext()), attrs, 0, GraphicsContext3D::RenderDirectlyToHostWindow);
+ GMockContext& mockContext = *static_cast<GMockContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(context.get()));
+
+ EXPECT_CALL(mockContext, getError())
+ .WillRepeatedly(Return(314));
+
+ // It's OK to call methods GMock doesn't know about.
+ context->makeContextCurrent();
+
+ // Check that the mocked method is returning as intended.
+ for (int i = 0; i < 10; i++)
+ EXPECT_EQ((int)context->getError(), 314);
+}
Deleted: trunk/Source/WebKit/chromium/tests/MockWebGraphicsContext3DTest.cpp (94105 => 94106)
--- trunk/Source/WebKit/chromium/tests/MockWebGraphicsContext3DTest.cpp 2011-08-30 20:42:46 UTC (rev 94105)
+++ trunk/Source/WebKit/chromium/tests/MockWebGraphicsContext3DTest.cpp 2011-08-30 20:43:14 UTC (rev 94106)
@@ -1,100 +0,0 @@
-/*
- * 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"
-
-#include "MockWebGraphicsContext3D.h"
-
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-
-using namespace WebKit;
-using namespace testing;
-
-TEST(MockWebGraphicsContext3DTest, BasicMockDoesNothing)
-{
- MockWebGraphicsContext3D context;
- EXPECT_FALSE(context.makeContextCurrent());
-}
-
-class FrameCountingContext : public MockWebGraphicsContext3D {
-public:
- FrameCountingContext() : m_frame(0) { }
-
- // This method would normally do a glSwapBuffers under the hood.
- virtual void prepareTexture() { m_frame++; }
-
- int frameCount() { return m_frame; }
-
-private:
- int m_frame;
-};
-
-TEST(MockWebGraphicsContext3DTest, CanOverrideManually)
-{
- FrameCountingContext context;
-
- context.makeContextCurrent();
- for (int i = 0; i < 10; i++) {
- context.clearColor(0, 0, 0, 1);
- context.prepareTexture();
- }
- context.finish();
-
- EXPECT_EQ(10, context.frameCount());
-}
-
-class GMockContext : public MockWebGraphicsContext3D {
-public:
- MOCK_METHOD0(width, int());
- MOCK_METHOD0(height, int());
- MOCK_METHOD1(synthesizeGLError, void(WGC3Denum error));
- MOCK_METHOD0(getError, WGC3Denum());
-};
-
-TEST(MockWebGraphicsContext3DTest, CanUseGMock)
-{
- GMockContext context;
-
- EXPECT_CALL(context, width())
- .WillRepeatedly(Return(512));
-
- EXPECT_CALL(context, height())
- .WillRepeatedly(Return(384));
-
- EXPECT_CALL(context, synthesizeGLError(_)) // Any parameter accepted
- .Times(Exactly(10));
-
- // No expectation for getError(), so calling that would make our test fail.
-
- for (int i = 0; i < 10; i++) {
- context.synthesizeGLError(i);
- EXPECT_EQ(512, context.width());
- EXPECT_EQ(384, context.height());
-
- // It's OK to call methods GMock doesn't know about.
- EXPECT_FALSE(context.makeContextCurrent());
- }
-}