Policy: check MustRemainInstalled in addition to UserMayModifySettings before offerin...
[chromium-blink-merge.git] / cc / test / test_in_process_context_provider.cc
blob34b0493d8120c032b08f5419450a9687fd148526
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/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"
20 namespace cc {
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;
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));
56 DCHECK(context);
57 return context.Pass();
60 scoped_ptr<gpu::GLInProcessContext> CreateTestInProcessContext() {
61 return CreateTestInProcessContext(nullptr, nullptr);
64 TestInProcessContextProvider::TestInProcessContextProvider()
65 : context_(CreateTestInProcessContext(&gpu_memory_buffer_manager_,
66 &image_factory_)) {
69 TestInProcessContextProvider::~TestInProcessContextProvider() {
72 bool TestInProcessContextProvider::BindToCurrentThread() { return true; }
74 gpu::gles2::GLES2Interface* TestInProcessContextProvider::ContextGL() {
75 return context_->GetImplementation();
78 gpu::ContextSupport* TestInProcessContextProvider::ContextSupport() {
79 return context_->GetImplementation();
82 namespace {
84 // Singleton used to initialize and terminate the gles2 library.
85 class GLES2Initializer {
86 public:
87 GLES2Initializer() { ::gles2::Initialize(); }
89 ~GLES2Initializer() { ::gles2::Terminate(); }
91 private:
92 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
95 static base::LazyInstance<GLES2Initializer> g_gles2_initializer =
96 LAZY_INSTANCE_INITIALIZER;
98 } // namespace
100 static void BindGrContextCallback(const GrGLInterface* interface) {
101 TestInProcessContextProvider* context_provider =
102 reinterpret_cast<TestInProcessContextProvider*>(interface->fCallbackData);
104 gles2::SetGLContext(context_provider->ContextGL());
107 class GrContext* TestInProcessContextProvider::GrContext() {
108 if (gr_context_)
109 return gr_context_.get();
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());
116 skia::RefPtr<GrGLInterface> interface =
117 skia::AdoptRef(skia_bindings::CreateCommandBufferSkiaGLBinding());
118 interface->fCallback = BindGrContextCallback;
119 interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this);
121 gr_context_ = skia::AdoptRef(GrContext::Create(
122 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get())));
124 return gr_context_.get();
127 ContextProvider::Capabilities
128 TestInProcessContextProvider::ContextCapabilities() {
129 ContextProvider::Capabilities capabilities;
130 capabilities.gpu.image = true;
131 capabilities.gpu.texture_rectangle = true;
133 return capabilities;
136 bool TestInProcessContextProvider::IsContextLost() { return false; }
138 void TestInProcessContextProvider::VerifyContexts() {}
140 void TestInProcessContextProvider::DeleteCachedResources() {
141 if (gr_context_)
142 gr_context_->freeGpuResources();
145 bool TestInProcessContextProvider::DestroyedOnMainThread() { return false; }
147 void TestInProcessContextProvider::SetLostContextCallback(
148 const LostContextCallback& lost_context_callback) {}
150 void TestInProcessContextProvider::SetMemoryPolicyChangedCallback(
151 const MemoryPolicyChangedCallback& memory_policy_changed_callback) {}
153 } // namespace cc