OLD | NEW |
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/support/compositor/blimp_context_provider.h" | 5 #include "blimp/client/support/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 Loading... |
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 18 matching lines...) Expand all Loading... |
79 return context_->GetImplementation(); | 83 return context_->GetImplementation(); |
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())); |
| 93 cache_controller_->SetGrContext(gr_context_->get()); |
| 94 return gr_context_->get(); |
| 95 } |
89 | 96 |
90 return gr_context_->get(); | 97 cc::ContextCacheController* BlimpContextProvider::CacheController() { |
| 98 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 99 return cache_controller_.get(); |
91 } | 100 } |
92 | 101 |
93 void BlimpContextProvider::InvalidateGrContext(uint32_t state) { | 102 void BlimpContextProvider::InvalidateGrContext(uint32_t state) { |
94 DCHECK(context_thread_checker_.CalledOnValidThread()); | 103 DCHECK(context_thread_checker_.CalledOnValidThread()); |
95 | 104 |
96 if (gr_context_) | 105 if (gr_context_) |
97 gr_context_->ResetContext(state); | 106 gr_context_->ResetContext(state); |
98 } | 107 } |
99 | 108 |
100 base::Lock* BlimpContextProvider::GetLock() { | 109 base::Lock* BlimpContextProvider::GetLock() { |
101 // This context provider is not used on multiple threads. | 110 // This context provider is not used on multiple threads. |
102 NOTREACHED(); | 111 NOTREACHED(); |
103 return nullptr; | 112 return nullptr; |
104 } | 113 } |
105 | 114 |
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( | 115 void BlimpContextProvider::SetLostContextCallback( |
114 const LostContextCallback& lost_context_callback) { | 116 const LostContextCallback& lost_context_callback) { |
115 DCHECK(context_thread_checker_.CalledOnValidThread()); | 117 DCHECK(context_thread_checker_.CalledOnValidThread()); |
116 lost_context_callback_ = lost_context_callback; | 118 lost_context_callback_ = lost_context_callback; |
117 } | 119 } |
118 | 120 |
119 void BlimpContextProvider::OnLostContext() { | 121 void BlimpContextProvider::OnLostContext() { |
120 DCHECK(context_thread_checker_.CalledOnValidThread()); | 122 DCHECK(context_thread_checker_.CalledOnValidThread()); |
121 if (!lost_context_callback_.is_null()) | 123 if (!lost_context_callback_.is_null()) |
122 lost_context_callback_.Run(); | 124 lost_context_callback_.Run(); |
123 if (gr_context_) | 125 if (gr_context_) |
124 gr_context_->OnLostContext(); | 126 gr_context_->OnLostContext(); |
125 } | 127 } |
126 | 128 |
127 } // namespace client | 129 } // namespace client |
128 } // namespace blimp | 130 } // namespace blimp |
OLD | NEW |