| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/compositor/test/in_process_context_provider.h" | 5 #include "ui/compositor/test/in_process_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 "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "cc/output/context_cache_controller.h" |
| 13 #include "cc/output/managed_memory_policy.h" | 14 #include "cc/output/managed_memory_policy.h" |
| 14 #include "gpu/command_buffer/client/gl_in_process_context.h" | 15 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 15 #include "gpu/command_buffer/client/gles2_implementation.h" | 16 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 16 #include "gpu/command_buffer/client/gles2_lib.h" | 17 #include "gpu/command_buffer/client/gles2_lib.h" |
| 17 #include "gpu/command_buffer/client/shared_memory_limits.h" | 18 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 18 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h" | 19 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h" |
| 19 #include "third_party/skia/include/gpu/GrContext.h" | 20 #include "third_party/skia/include/gpu/GrContext.h" |
| 20 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 21 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 21 | 22 |
| 22 namespace ui { | 23 namespace ui { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 context_.reset(gpu::GLInProcessContext::Create( | 87 context_.reset(gpu::GLInProcessContext::Create( |
| 87 nullptr, /* service */ | 88 nullptr, /* service */ |
| 88 nullptr, /* surface */ | 89 nullptr, /* surface */ |
| 89 !window_, /* is_offscreen */ | 90 !window_, /* is_offscreen */ |
| 90 window_, (shared_context_ ? shared_context_->context_.get() : nullptr), | 91 window_, (shared_context_ ? shared_context_->context_.get() : nullptr), |
| 91 attribs_, gpu::SharedMemoryLimits(), gpu_memory_buffer_manager_, | 92 attribs_, gpu::SharedMemoryLimits(), gpu_memory_buffer_manager_, |
| 92 image_factory_)); | 93 image_factory_)); |
| 93 | 94 |
| 94 if (!context_) | 95 if (!context_) |
| 95 return false; | 96 return false; |
| 97 |
| 98 cache_controller_.reset( |
| 99 new cc::ContextCacheController(context_->GetImplementation())); |
| 96 } | 100 } |
| 97 | 101 |
| 98 std::string unique_context_name = | 102 std::string unique_context_name = |
| 99 base::StringPrintf("%s-%p", debug_name_.c_str(), context_.get()); | 103 base::StringPrintf("%s-%p", debug_name_.c_str(), context_.get()); |
| 100 context_->GetImplementation()->TraceBeginCHROMIUM( | 104 context_->GetImplementation()->TraceBeginCHROMIUM( |
| 101 "gpu_toplevel", unique_context_name.c_str()); | 105 "gpu_toplevel", unique_context_name.c_str()); |
| 102 | 106 |
| 103 return true; | 107 return true; |
| 104 } | 108 } |
| 105 | 109 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 124 return context_->GetImplementation(); | 128 return context_->GetImplementation(); |
| 125 } | 129 } |
| 126 | 130 |
| 127 class GrContext* InProcessContextProvider::GrContext() { | 131 class GrContext* InProcessContextProvider::GrContext() { |
| 128 DCHECK(context_thread_checker_.CalledOnValidThread()); | 132 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 129 | 133 |
| 130 if (gr_context_) | 134 if (gr_context_) |
| 131 return gr_context_->get(); | 135 return gr_context_->get(); |
| 132 | 136 |
| 133 gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(ContextGL())); | 137 gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(ContextGL())); |
| 138 cache_controller_->SetGrContext(gr_context_->get()); |
| 134 | 139 |
| 135 return gr_context_->get(); | 140 return gr_context_->get(); |
| 136 } | 141 } |
| 137 | 142 |
| 143 cc::ContextCacheController* InProcessContextProvider::CacheController() { |
| 144 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 145 return cache_controller_.get(); |
| 146 } |
| 147 |
| 138 void InProcessContextProvider::InvalidateGrContext(uint32_t state) { | 148 void InProcessContextProvider::InvalidateGrContext(uint32_t state) { |
| 139 DCHECK(context_thread_checker_.CalledOnValidThread()); | 149 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 140 | 150 |
| 141 if (gr_context_) | 151 if (gr_context_) |
| 142 gr_context_->ResetContext(state); | 152 gr_context_->ResetContext(state); |
| 143 } | 153 } |
| 144 | 154 |
| 145 base::Lock* InProcessContextProvider::GetLock() { | 155 base::Lock* InProcessContextProvider::GetLock() { |
| 146 return &context_lock_; | 156 return &context_lock_; |
| 147 } | 157 } |
| 148 | 158 |
| 149 void InProcessContextProvider::DeleteCachedResources() { | |
| 150 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 151 | |
| 152 if (gr_context_) | |
| 153 gr_context_->FreeGpuResources(); | |
| 154 } | |
| 155 | |
| 156 void InProcessContextProvider::SetLostContextCallback( | 159 void InProcessContextProvider::SetLostContextCallback( |
| 157 const LostContextCallback& lost_context_callback) { | 160 const LostContextCallback& lost_context_callback) { |
| 158 // Pixel tests do not test lost context. | 161 // Pixel tests do not test lost context. |
| 159 } | 162 } |
| 160 | 163 |
| 161 uint32_t InProcessContextProvider::GetCopyTextureInternalFormat() { | 164 uint32_t InProcessContextProvider::GetCopyTextureInternalFormat() { |
| 162 if (attribs_.alpha_size > 0) | 165 if (attribs_.alpha_size > 0) |
| 163 return GL_RGBA; | 166 return GL_RGBA; |
| 164 DCHECK_NE(attribs_.red_size, 0); | 167 DCHECK_NE(attribs_.red_size, 0); |
| 165 DCHECK_NE(attribs_.green_size, 0); | 168 DCHECK_NE(attribs_.green_size, 0); |
| 166 DCHECK_NE(attribs_.blue_size, 0); | 169 DCHECK_NE(attribs_.blue_size, 0); |
| 167 return GL_RGB; | 170 return GL_RGB; |
| 168 } | 171 } |
| 169 | 172 |
| 170 } // namespace ui | 173 } // namespace ui |
| OLD | NEW |