OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "cc/test/test_in_process_context_provider.h" | |
6 | |
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/command_buffer/common/gles2_cmd_utils.h" | |
13 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | |
14 #include "third_party/khronos/GLES2/gl2.h" | |
15 #include "third_party/khronos/GLES2/gl2ext.h" | |
16 #include "third_party/skia/include/gpu/GrContext.h" | |
17 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | |
18 #include "ui/gfx/native_widget_types.h" | |
19 | |
20 namespace cc { | |
21 | |
22 // static | |
23 scoped_ptr<gpu::GLInProcessContext> CreateTestInProcessContext( | |
24 TestGpuMemoryBufferManager* gpu_memory_buffer_manager, | |
25 TestImageFactory* image_factory) { | |
26 const bool is_offscreen = true; | |
27 const bool share_resources = true; | |
28 gpu::gles2::ContextCreationAttribHelper attribs; | |
29 attribs.alpha_size = 8; | |
30 attribs.blue_size = 8; | |
31 attribs.green_size = 8; | |
32 attribs.red_size = 8; | |
33 attribs.depth_size = 24; | |
34 attribs.stencil_size = 8; | |
35 attribs.samples = 0; | |
36 attribs.sample_buffers = 0; | |
37 attribs.fail_if_major_perf_caveat = false; | |
38 attribs.bind_generates_resource = false; | |
39 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | |
40 | |
41 scoped_ptr<gpu::GLInProcessContext> context = | |
42 make_scoped_ptr(gpu::GLInProcessContext::Create( | |
43 NULL, | |
44 NULL, | |
45 is_offscreen, | |
46 gfx::kNullAcceleratedWidget, | |
47 gfx::Size(1, 1), | |
48 NULL, | |
49 share_resources, | |
50 attribs, | |
51 gpu_preference, | |
52 gpu::GLInProcessContextSharedMemoryLimits(), | |
53 gpu_memory_buffer_manager, | |
54 image_factory)); | |
55 | |
56 DCHECK(context); | |
57 return context.Pass(); | |
58 } | |
59 | |
60 scoped_ptr<gpu::GLInProcessContext> CreateTestInProcessContext() { | |
61 return CreateTestInProcessContext(nullptr, nullptr); | |
62 } | |
63 | |
64 TestInProcessContextProvider::TestInProcessContextProvider() | |
65 : context_(CreateTestInProcessContext(&gpu_memory_buffer_manager_, | |
66 &image_factory_)) { | |
67 } | |
68 | |
69 TestInProcessContextProvider::~TestInProcessContextProvider() { | |
70 } | |
71 | |
72 bool TestInProcessContextProvider::BindToCurrentThread() { return true; } | |
73 | |
74 gpu::gles2::GLES2Interface* TestInProcessContextProvider::ContextGL() { | |
75 return context_->GetImplementation(); | |
76 } | |
77 | |
78 gpu::ContextSupport* TestInProcessContextProvider::ContextSupport() { | |
79 return context_->GetImplementation(); | |
80 } | |
81 | |
82 namespace { | |
83 | |
84 // Singleton used to initialize and terminate the gles2 library. | |
85 class GLES2Initializer { | |
86 public: | |
87 GLES2Initializer() { ::gles2::Initialize(); } | |
88 | |
89 ~GLES2Initializer() { ::gles2::Terminate(); } | |
90 | |
91 private: | |
92 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer); | |
93 }; | |
94 | |
95 static base::LazyInstance<GLES2Initializer> g_gles2_initializer = | |
96 LAZY_INSTANCE_INITIALIZER; | |
97 | |
98 } // namespace | |
99 | |
100 static void BindGrContextCallback(const GrGLInterface* interface) { | |
101 TestInProcessContextProvider* context_provider = | |
102 reinterpret_cast<TestInProcessContextProvider*>(interface->fCallbackData); | |
103 | |
104 gles2::SetGLContext(context_provider->ContextGL()); | |
105 } | |
106 | |
107 class GrContext* TestInProcessContextProvider::GrContext() { | |
108 if (gr_context_) | |
109 return gr_context_.get(); | |
110 | |
111 // The GrGLInterface factory will make GL calls using the C GLES2 interface. | |
112 // Make sure the gles2 library is initialized first on exactly one thread. | |
113 g_gles2_initializer.Get(); | |
114 gles2::SetGLContext(ContextGL()); | |
115 | |
116 skia::RefPtr<GrGLInterface> interface = | |
117 skia::AdoptRef(skia_bindings::CreateCommandBufferSkiaGLBinding()); | |
118 interface->fCallback = BindGrContextCallback; | |
119 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this); | |
120 | |
121 gr_context_ = skia::AdoptRef(GrContext::Create( | |
122 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); | |
123 | |
124 return gr_context_.get(); | |
125 } | |
126 | |
127 void TestInProcessContextProvider::SetupLock() { | |
128 } | |
129 | |
130 base::Lock* TestInProcessContextProvider::GetLock() { | |
131 return &context_lock_; | |
132 } | |
133 | |
134 ContextProvider::Capabilities | |
135 TestInProcessContextProvider::ContextCapabilities() { | |
136 ContextProvider::Capabilities capabilities; | |
137 capabilities.gpu.image = true; | |
138 capabilities.gpu.texture_rectangle = true; | |
139 | |
140 return capabilities; | |
141 } | |
142 | |
143 bool TestInProcessContextProvider::IsContextLost() { return false; } | |
144 | |
145 void TestInProcessContextProvider::VerifyContexts() {} | |
146 | |
147 void TestInProcessContextProvider::DeleteCachedResources() { | |
148 if (gr_context_) | |
149 gr_context_->freeGpuResources(); | |
150 } | |
151 | |
152 bool TestInProcessContextProvider::DestroyedOnMainThread() { return false; } | |
153 | |
154 void TestInProcessContextProvider::SetLostContextCallback( | |
155 const LostContextCallback& lost_context_callback) {} | |
156 | |
157 void TestInProcessContextProvider::SetMemoryPolicyChangedCallback( | |
158 const MemoryPolicyChangedCallback& memory_policy_changed_callback) {} | |
159 | |
160 } // namespace cc | |
OLD | NEW |