cleanup: Use EventRouter and some cleanups.
[chromium-blink-merge.git] / cc / test / test_in_process_context_provider.cc
blobfbd333553ff6752f83c529b19378d3578c45c620
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/test/test_in_process_context_provider.h"
7 #include "base/lazy_instance.h"
8 #include "gpu/GLES2/gl2extchromium.h"
9 #include "gpu/command_buffer/client/gl_in_process_context.h"
10 #include "gpu/command_buffer/client/gles2_implementation.h"
11 #include "gpu/command_buffer/client/gles2_lib.h"
12 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
13 #include "third_party/khronos/GLES2/gl2.h"
14 #include "third_party/khronos/GLES2/gl2ext.h"
15 #include "third_party/skia/include/gpu/GrContext.h"
16 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
17 #include "ui/gfx/native_widget_types.h"
19 namespace cc {
21 // static
22 scoped_ptr<gpu::GLInProcessContext> CreateTestInProcessContext() {
23 const bool is_offscreen = true;
24 const bool share_resources = true;
25 gpu::GLInProcessContextAttribs attribs;
26 attribs.alpha_size = 8;
27 attribs.blue_size = 8;
28 attribs.green_size = 8;
29 attribs.red_size = 8;
30 attribs.depth_size = 24;
31 attribs.stencil_size = 8;
32 attribs.samples = 0;
33 attribs.sample_buffers = 0;
34 attribs.fail_if_major_perf_caveat = false;
35 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
37 scoped_ptr<gpu::GLInProcessContext> context = make_scoped_ptr(
38 gpu::GLInProcessContext::CreateContext(is_offscreen,
39 gfx::AcceleratedWidget(),
40 gfx::Size(1, 1),
41 share_resources,
42 attribs,
43 gpu_preference));
44 DCHECK(context);
45 return context.Pass();
48 TestInProcessContextProvider::TestInProcessContextProvider()
49 : context_(CreateTestInProcessContext()) {}
51 TestInProcessContextProvider::~TestInProcessContextProvider() {
54 bool TestInProcessContextProvider::BindToCurrentThread() { return true; }
56 gpu::gles2::GLES2Interface* TestInProcessContextProvider::ContextGL() {
57 return context_->GetImplementation();
60 gpu::ContextSupport* TestInProcessContextProvider::ContextSupport() {
61 return context_->GetImplementation();
64 namespace {
66 // Singleton used to initialize and terminate the gles2 library.
67 class GLES2Initializer {
68 public:
69 GLES2Initializer() { ::gles2::Initialize(); }
71 ~GLES2Initializer() { ::gles2::Terminate(); }
73 private:
74 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
77 static base::LazyInstance<GLES2Initializer> g_gles2_initializer =
78 LAZY_INSTANCE_INITIALIZER;
80 } // namespace
82 static void BindGrContextCallback(const GrGLInterface* interface) {
83 TestInProcessContextProvider* context_provider =
84 reinterpret_cast<TestInProcessContextProvider*>(interface->fCallbackData);
86 gles2::SetGLContext(context_provider->ContextGL());
89 class GrContext* TestInProcessContextProvider::GrContext() {
90 if (gr_context_)
91 return gr_context_.get();
93 // The GrGLInterface factory will make GL calls using the C GLES2 interface.
94 // Make sure the gles2 library is initialized first on exactly one thread.
95 g_gles2_initializer.Get();
96 gles2::SetGLContext(ContextGL());
98 skia::RefPtr<GrGLInterface> interface =
99 skia::AdoptRef(skia_bindings::CreateCommandBufferSkiaGLBinding());
100 interface->fCallback = BindGrContextCallback;
101 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this);
103 gr_context_ = skia::AdoptRef(GrContext::Create(
104 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get())));
106 return gr_context_.get();
109 ContextProvider::Capabilities
110 TestInProcessContextProvider::ContextCapabilities() {
111 return ContextProvider::Capabilities();
114 bool TestInProcessContextProvider::IsContextLost() { return false; }
116 void TestInProcessContextProvider::VerifyContexts() {}
118 bool TestInProcessContextProvider::DestroyedOnMainThread() { return false; }
120 void TestInProcessContextProvider::SetLostContextCallback(
121 const LostContextCallback& lost_context_callback) {}
123 void TestInProcessContextProvider::SetMemoryPolicyChangedCallback(
124 const MemoryPolicyChangedCallback& memory_policy_changed_callback) {}
126 } // namespace cc