Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: blimp/client/feature/compositor/blimp_context_provider.cc

Issue 2241623002: blimp: Move compositing, input and render widget feature to client/core. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments from #7 Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 "blimp/client/feature/compositor/blimp_context_provider.h"
6
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "base/lazy_instance.h"
10 #include "gpu/command_buffer/client/gl_in_process_context.h"
11 #include "gpu/command_buffer/client/gles2_implementation.h"
12 #include "gpu/command_buffer/client/gles2_lib.h"
13 #include "gpu/command_buffer/client/shared_memory_limits.h"
14 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
15 #include "third_party/skia/include/gpu/GrContext.h"
16 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
17
18 namespace blimp {
19 namespace client {
20
21 // static
22 scoped_refptr<BlimpContextProvider> BlimpContextProvider::Create(
23 gfx::AcceleratedWidget widget,
24 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) {
25 return new BlimpContextProvider(widget, gpu_memory_buffer_manager);
26 }
27
28 BlimpContextProvider::BlimpContextProvider(
29 gfx::AcceleratedWidget widget,
30 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) {
31 context_thread_checker_.DetachFromThread();
32
33 gpu::gles2::ContextCreationAttribHelper attribs_for_gles2;
34 attribs_for_gles2.alpha_size = 8;
35 attribs_for_gles2.depth_size = 0;
36 attribs_for_gles2.stencil_size = 0;
37 attribs_for_gles2.samples = 0;
38 attribs_for_gles2.sample_buffers = 0;
39 attribs_for_gles2.fail_if_major_perf_caveat = false;
40 attribs_for_gles2.bind_generates_resource = false;
41 attribs_for_gles2.context_type = gpu::gles2::CONTEXT_TYPE_OPENGLES2;
42 attribs_for_gles2.lose_context_when_out_of_memory = true;
43
44 context_.reset(gpu::GLInProcessContext::Create(
45 nullptr /* service */, nullptr /* surface */,
46 widget == gfx::kNullAcceleratedWidget /* is_offscreen */, widget,
47 nullptr /* share_context */, attribs_for_gles2, gpu::SharedMemoryLimits(),
48 gpu_memory_buffer_manager, nullptr /* memory_limits */));
49 context_->GetImplementation()->SetLostContextCallback(
50 base::Bind(&BlimpContextProvider::OnLostContext, base::Unretained(this)));
51 }
52
53 BlimpContextProvider::~BlimpContextProvider() {
54 DCHECK(main_thread_checker_.CalledOnValidThread() ||
55 context_thread_checker_.CalledOnValidThread());
56 }
57
58 bool BlimpContextProvider::BindToCurrentThread() {
59 DCHECK(context_thread_checker_.CalledOnValidThread());
60 return true;
61 }
62
63 void BlimpContextProvider::DetachFromThread() {
64 context_thread_checker_.DetachFromThread();
65 }
66
67 gpu::Capabilities BlimpContextProvider::ContextCapabilities() {
68 DCHECK(context_thread_checker_.CalledOnValidThread());
69 return context_->GetImplementation()->capabilities();
70 }
71
72 gpu::gles2::GLES2Interface* BlimpContextProvider::ContextGL() {
73 DCHECK(context_thread_checker_.CalledOnValidThread());
74 return context_->GetImplementation();
75 }
76
77 gpu::ContextSupport* BlimpContextProvider::ContextSupport() {
78 DCHECK(context_thread_checker_.CalledOnValidThread());
79 return context_->GetImplementation();
80 }
81
82 class GrContext* BlimpContextProvider::GrContext() {
83 DCHECK(context_thread_checker_.CalledOnValidThread());
84
85 if (gr_context_)
86 return gr_context_->get();
87
88 gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(ContextGL()));
89
90 return gr_context_->get();
91 }
92
93 void BlimpContextProvider::InvalidateGrContext(uint32_t state) {
94 DCHECK(context_thread_checker_.CalledOnValidThread());
95
96 if (gr_context_)
97 gr_context_->ResetContext(state);
98 }
99
100 base::Lock* BlimpContextProvider::GetLock() {
101 // This context provider is not used on multiple threads.
102 NOTREACHED();
103 return nullptr;
104 }
105
106 void BlimpContextProvider::DeleteCachedResources() {
107 DCHECK(context_thread_checker_.CalledOnValidThread());
108
109 if (gr_context_)
110 gr_context_->FreeGpuResources();
111 }
112
113 void BlimpContextProvider::SetLostContextCallback(
114 const LostContextCallback& lost_context_callback) {
115 DCHECK(context_thread_checker_.CalledOnValidThread());
116 lost_context_callback_ = lost_context_callback;
117 }
118
119 void BlimpContextProvider::OnLostContext() {
120 DCHECK(context_thread_checker_.CalledOnValidThread());
121 if (!lost_context_callback_.is_null())
122 lost_context_callback_.Run();
123 if (gr_context_)
124 gr_context_->OnLostContext();
125 }
126
127 uint32_t BlimpContextProvider::GetCopyTextureInternalFormat() {
128 // The attributes used to create the context in the constructor specify
129 // an alpha channel.
130 return GL_RGBA;
131 }
132
133 } // namespace client
134 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698