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

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

Issue 2278283003: Refactor client visibility handling (Closed)
Patch Set: fix compositor_unittests Created 4 years, 3 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "blimp/client/feature/compositor/blimp_context_provider.h" 5 #include "blimp/client/feature/compositor/blimp_context_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "cc/output/context_cache_controller.h"
10 #include "gpu/command_buffer/client/gl_in_process_context.h" 11 #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_implementation.h"
12 #include "gpu/command_buffer/client/gles2_lib.h" 13 #include "gpu/command_buffer/client/gles2_lib.h"
13 #include "gpu/command_buffer/client/shared_memory_limits.h" 14 #include "gpu/command_buffer/client/shared_memory_limits.h"
14 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h" 15 #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/GrContext.h"
16 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" 17 #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
17 18
18 namespace blimp { 19 namespace blimp {
19 namespace client { 20 namespace client {
(...skipping 21 matching lines...) Expand all
41 attribs_for_gles2.context_type = gpu::gles2::CONTEXT_TYPE_OPENGLES2; 42 attribs_for_gles2.context_type = gpu::gles2::CONTEXT_TYPE_OPENGLES2;
42 attribs_for_gles2.lose_context_when_out_of_memory = true; 43 attribs_for_gles2.lose_context_when_out_of_memory = true;
43 44
44 context_.reset(gpu::GLInProcessContext::Create( 45 context_.reset(gpu::GLInProcessContext::Create(
45 nullptr /* service */, nullptr /* surface */, 46 nullptr /* service */, nullptr /* surface */,
46 widget == gfx::kNullAcceleratedWidget /* is_offscreen */, widget, 47 widget == gfx::kNullAcceleratedWidget /* is_offscreen */, widget,
47 nullptr /* share_context */, attribs_for_gles2, gpu::SharedMemoryLimits(), 48 nullptr /* share_context */, attribs_for_gles2, gpu::SharedMemoryLimits(),
48 gpu_memory_buffer_manager, nullptr /* memory_limits */)); 49 gpu_memory_buffer_manager, nullptr /* memory_limits */));
49 context_->GetImplementation()->SetLostContextCallback( 50 context_->GetImplementation()->SetLostContextCallback(
50 base::Bind(&BlimpContextProvider::OnLostContext, base::Unretained(this))); 51 base::Bind(&BlimpContextProvider::OnLostContext, base::Unretained(this)));
52
53 cache_controller_.reset(
54 new cc::ContextCacheController(context_->GetImplementation()));
51 } 55 }
52 56
53 BlimpContextProvider::~BlimpContextProvider() { 57 BlimpContextProvider::~BlimpContextProvider() {
54 DCHECK(main_thread_checker_.CalledOnValidThread() || 58 DCHECK(main_thread_checker_.CalledOnValidThread() ||
55 context_thread_checker_.CalledOnValidThread()); 59 context_thread_checker_.CalledOnValidThread());
56 } 60 }
57 61
58 bool BlimpContextProvider::BindToCurrentThread() { 62 bool BlimpContextProvider::BindToCurrentThread() {
59 DCHECK(context_thread_checker_.CalledOnValidThread()); 63 DCHECK(context_thread_checker_.CalledOnValidThread());
60 return true; 64 return true;
(...skipping 19 matching lines...) Expand all
80 } 84 }
81 85
82 class GrContext* BlimpContextProvider::GrContext() { 86 class GrContext* BlimpContextProvider::GrContext() {
83 DCHECK(context_thread_checker_.CalledOnValidThread()); 87 DCHECK(context_thread_checker_.CalledOnValidThread());
84 88
85 if (gr_context_) 89 if (gr_context_)
86 return gr_context_->get(); 90 return gr_context_->get();
87 91
88 gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(ContextGL())); 92 gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(ContextGL()));
89 93
94 cache_controller_->SetGrContext(gr_context_->get());
danakj 2016/08/26 23:49:08 nit: prefer this grouped with the gr_context_reset
ericrk 2016/08/29 22:43:22 Done.
90 return gr_context_->get(); 95 return gr_context_->get();
91 } 96 }
92 97
98 cc::ContextCacheController* BlimpContextProvider::CacheController() {
99 DCHECK(context_thread_checker_.CalledOnValidThread());
100 return cache_controller_.get();
101 }
102
93 void BlimpContextProvider::InvalidateGrContext(uint32_t state) { 103 void BlimpContextProvider::InvalidateGrContext(uint32_t state) {
94 DCHECK(context_thread_checker_.CalledOnValidThread()); 104 DCHECK(context_thread_checker_.CalledOnValidThread());
95 105
96 if (gr_context_) 106 if (gr_context_)
97 gr_context_->ResetContext(state); 107 gr_context_->ResetContext(state);
98 } 108 }
99 109
100 base::Lock* BlimpContextProvider::GetLock() { 110 base::Lock* BlimpContextProvider::GetLock() {
101 // This context provider is not used on multiple threads. 111 // This context provider is not used on multiple threads.
102 NOTREACHED(); 112 NOTREACHED();
103 return nullptr; 113 return nullptr;
104 } 114 }
105 115
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( 116 void BlimpContextProvider::SetLostContextCallback(
114 const LostContextCallback& lost_context_callback) { 117 const LostContextCallback& lost_context_callback) {
115 DCHECK(context_thread_checker_.CalledOnValidThread()); 118 DCHECK(context_thread_checker_.CalledOnValidThread());
116 lost_context_callback_ = lost_context_callback; 119 lost_context_callback_ = lost_context_callback;
117 } 120 }
118 121
119 void BlimpContextProvider::OnLostContext() { 122 void BlimpContextProvider::OnLostContext() {
120 DCHECK(context_thread_checker_.CalledOnValidThread()); 123 DCHECK(context_thread_checker_.CalledOnValidThread());
121 if (!lost_context_callback_.is_null()) 124 if (!lost_context_callback_.is_null())
122 lost_context_callback_.Run(); 125 lost_context_callback_.Run();
123 if (gr_context_) 126 if (gr_context_)
124 gr_context_->OnLostContext(); 127 gr_context_->OnLostContext();
125 } 128 }
126 129
127 uint32_t BlimpContextProvider::GetCopyTextureInternalFormat() { 130 uint32_t BlimpContextProvider::GetCopyTextureInternalFormat() {
128 // The attributes used to create the context in the constructor specify 131 // The attributes used to create the context in the constructor specify
129 // an alpha channel. 132 // an alpha channel.
130 return GL_RGBA; 133 return GL_RGBA;
131 } 134 }
132 135
133 } // namespace client 136 } // namespace client
134 } // namespace blimp 137 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698