summaryrefslogtreecommitdiffstats
path: root/cc/test/test_in_process_context_provider.cc
diff options
context:
space:
mode:
authorjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-20 01:16:53 +0000
committerjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-20 01:16:53 +0000
commit3831ae45b1e856e07e760e0a8630c79ef690f8c1 (patch)
tree6701b5e1f78af43872f500c967208b77258c5804 /cc/test/test_in_process_context_provider.cc
parent108949ca10059379fa04f52528ce300efe78ee20 (diff)
downloadchromium_src-3831ae45b1e856e07e760e0a8630c79ef690f8c1.zip
chromium_src-3831ae45b1e856e07e760e0a8630c79ef690f8c1.tar.gz
chromium_src-3831ae45b1e856e07e760e0a8630c79ef690f8c1.tar.bz2
Use the GL in process bindings directly in cc_unittests
This binds cc_unittests to the GL in process command buffer bindings directly instead of relying on the setup in webkit/common/gpu. BUG=181120 Review URL: https://codereview.chromium.org/105303003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/test/test_in_process_context_provider.cc')
-rw-r--r--cc/test/test_in_process_context_provider.cc136
1 files changed, 136 insertions, 0 deletions
diff --git a/cc/test/test_in_process_context_provider.cc b/cc/test/test_in_process_context_provider.cc
new file mode 100644
index 0000000..14c65d1
--- /dev/null
+++ b/cc/test/test_in_process_context_provider.cc
@@ -0,0 +1,136 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/test/test_in_process_context_provider.h"
+
+#include "base/lazy_instance.h"
+#include "gpu/GLES2/gl2extchromium.h"
+#include "gpu/command_buffer/client/gl_in_process_context.h"
+#include "gpu/command_buffer/client/gles2_implementation.h"
+#include "gpu/command_buffer/client/gles2_lib.h"
+#include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
+#include "third_party/khronos/GLES2/gl2.h"
+#include "third_party/khronos/GLES2/gl2ext.h"
+#include "third_party/skia/include/gpu/GrContext.h"
+#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
+#include "ui/gfx/native_widget_types.h"
+
+namespace cc {
+
+// static
+scoped_ptr<gpu::GLInProcessContext> CreateTestInProcessContext() {
+ const bool is_offscreen = true;
+ const bool share_resources = true;
+ gpu::GLInProcessContextAttribs attribs;
+ attribs.alpha_size = 8;
+ attribs.blue_size = 8;
+ attribs.green_size = 8;
+ attribs.red_size = 8;
+ attribs.depth_size = 24;
+ attribs.stencil_size = 8;
+ attribs.samples = 0;
+ attribs.sample_buffers = 0;
+ attribs.fail_if_major_perf_caveat = false;
+ gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
+
+ scoped_ptr<gpu::GLInProcessContext> context = make_scoped_ptr(
+ gpu::GLInProcessContext::CreateContext(is_offscreen,
+ gfx::AcceleratedWidget(),
+ gfx::Size(1, 1),
+ share_resources,
+ attribs,
+ gpu_preference));
+ DCHECK(context);
+ return context.Pass();
+}
+
+TestInProcessContextProvider::TestInProcessContextProvider()
+ : context_(CreateTestInProcessContext()) {}
+
+TestInProcessContextProvider::~TestInProcessContextProvider() {
+ if (gr_context_)
+ gr_context_->contextDestroyed();
+}
+
+bool TestInProcessContextProvider::BindToCurrentThread() { return true; }
+
+blink::WebGraphicsContext3D* TestInProcessContextProvider::Context3d() {
+ return NULL;
+}
+
+gpu::gles2::GLES2Interface* TestInProcessContextProvider::ContextGL() {
+ return context_->GetImplementation();
+}
+
+gpu::ContextSupport* TestInProcessContextProvider::ContextSupport() {
+ return context_->GetImplementation();
+}
+
+static void BindGrContextCallback(const GrGLInterface* interface) {
+#if GR_GL_PER_GL_FUNC_CALLBACK
+ reinterpret_cast<TestInProcessContextProvider*>(interface->fCallbackData)
+ ->MakeGrContextCurrent();
+#endif // GR_GL_PER_GL_FUNC_CALLBACK
+}
+
+class GrContext* TestInProcessContextProvider::GrContext() {
+ if (gr_context_)
+ return gr_context_.get();
+
+ skia::RefPtr<GrGLInterface> interface =
+ skia::AdoptRef(skia_bindings::CreateCommandBufferSkiaGLBinding());
+#if GR_GL_PER_GL_FUNC_CALLBACK
+ interface->fCallback = BindGrContextCallback;
+ interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this);
+#endif // GR_GL_PER_GL_FUNC_CALLBACK
+
+ gr_context_ = skia::AdoptRef(GrContext::Create(
+ kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get())));
+
+ return gr_context_.get();
+}
+
+namespace {
+
+// Singleton used to initialize and terminate the gles2 library.
+class GLES2Initializer {
+ public:
+ GLES2Initializer() { ::gles2::Initialize(); }
+
+ ~GLES2Initializer() { ::gles2::Terminate(); }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
+};
+
+static base::LazyInstance<GLES2Initializer> g_gles2_initializer =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+void TestInProcessContextProvider::MakeGrContextCurrent() {
+ // Make sure the gles2 library is initialized first on exactly one thread.
+ g_gles2_initializer.Get();
+
+ gles2::SetGLContext(context_->GetImplementation());
+}
+
+ContextProvider::Capabilities
+TestInProcessContextProvider::ContextCapabilities() {
+ return ContextProvider::Capabilities();
+}
+
+bool TestInProcessContextProvider::IsContextLost() { return false; }
+
+void TestInProcessContextProvider::VerifyContexts() {}
+
+bool TestInProcessContextProvider::DestroyedOnMainThread() { return false; }
+
+void TestInProcessContextProvider::SetLostContextCallback(
+ const LostContextCallback& lost_context_callback) {}
+
+void TestInProcessContextProvider::SetMemoryPolicyChangedCallback(
+ const MemoryPolicyChangedCallback& memory_policy_changed_callback) {}
+
+} // namespace cc