| 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/managed_memory_policy.h" | 13 #include "cc/output/managed_memory_policy.h" |
| 14 #include "gpu/command_buffer/client/gl_in_process_context.h" | 14 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 15 #include "gpu/command_buffer/client/gles2_implementation.h" | 15 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 16 #include "gpu/command_buffer/client/gles2_lib.h" | 16 #include "gpu/command_buffer/client/gles2_lib.h" |
| 17 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h" | 17 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h" |
| 18 #include "third_party/skia/include/gpu/GrContext.h" | 18 #include "third_party/skia/include/gpu/GrContext.h" |
| 19 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 19 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 20 | 20 |
| 21 namespace ui { | 21 namespace ui { |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 scoped_refptr<InProcessContextProvider> InProcessContextProvider::Create( | 24 scoped_refptr<InProcessContextProvider> InProcessContextProvider::Create( |
| 25 const gpu::gles2::ContextCreationAttribHelper& attribs, | 25 const gpu::gles2::ContextCreationAttribHelper& attribs, |
| 26 InProcessContextProvider* shared_context, | 26 InProcessContextProvider* shared_context, |
| 27 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 27 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 image_factory_(image_factory), | 68 image_factory_(image_factory), |
| 69 window_(window), | 69 window_(window), |
| 70 debug_name_(debug_name) { | 70 debug_name_(debug_name) { |
| 71 DCHECK(main_thread_checker_.CalledOnValidThread()); | 71 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 72 context_thread_checker_.DetachFromThread(); | 72 context_thread_checker_.DetachFromThread(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 InProcessContextProvider::~InProcessContextProvider() { | 75 InProcessContextProvider::~InProcessContextProvider() { |
| 76 DCHECK(main_thread_checker_.CalledOnValidThread() || | 76 DCHECK(main_thread_checker_.CalledOnValidThread() || |
| 77 context_thread_checker_.CalledOnValidThread()); | 77 context_thread_checker_.CalledOnValidThread()); |
| 78 if (gr_context_) | |
| 79 gr_context_->releaseResourcesAndAbandonContext(); | |
| 80 } | 78 } |
| 81 | 79 |
| 82 bool InProcessContextProvider::BindToCurrentThread() { | 80 bool InProcessContextProvider::BindToCurrentThread() { |
| 83 // This is called on the thread the context will be used. | 81 // This is called on the thread the context will be used. |
| 84 DCHECK(context_thread_checker_.CalledOnValidThread()); | 82 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 85 | 83 |
| 86 if (!context_) { | 84 if (!context_) { |
| 87 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 85 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| 88 context_.reset(gpu::GLInProcessContext::Create( | 86 context_.reset(gpu::GLInProcessContext::Create( |
| 89 nullptr, /* service */ | 87 nullptr, /* service */ |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 gpu::ContextSupport* InProcessContextProvider::ContextSupport() { | 125 gpu::ContextSupport* InProcessContextProvider::ContextSupport() { |
| 128 DCHECK(context_thread_checker_.CalledOnValidThread()); | 126 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 129 | 127 |
| 130 return context_->GetImplementation(); | 128 return context_->GetImplementation(); |
| 131 } | 129 } |
| 132 | 130 |
| 133 class GrContext* InProcessContextProvider::GrContext() { | 131 class GrContext* InProcessContextProvider::GrContext() { |
| 134 DCHECK(context_thread_checker_.CalledOnValidThread()); | 132 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 135 | 133 |
| 136 if (gr_context_) | 134 if (gr_context_) |
| 137 return gr_context_.get(); | 135 return gr_context_->get(); |
| 138 | 136 |
| 139 sk_sp<GrGLInterface> interface( | 137 gr_context_.reset(new skia_bindings::GrContextForGLES2Interface(ContextGL())); |
| 140 skia_bindings::CreateGLES2InterfaceBindings(ContextGL())); | 138 |
| 141 gr_context_ = skia::AdoptRef(GrContext::Create( | 139 return gr_context_->get(); |
| 142 // GrContext takes ownership of |interface|. | |
| 143 kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get()))); | |
| 144 return gr_context_.get(); | |
| 145 } | 140 } |
| 146 | 141 |
| 147 void InProcessContextProvider::InvalidateGrContext(uint32_t state) { | 142 void InProcessContextProvider::InvalidateGrContext(uint32_t state) { |
| 148 DCHECK(context_thread_checker_.CalledOnValidThread()); | 143 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 149 | 144 |
| 150 if (gr_context_) | 145 if (gr_context_) |
| 151 gr_context_.get()->resetContext(state); | 146 gr_context_->ResetContext(state); |
| 152 } | 147 } |
| 153 | 148 |
| 154 void InProcessContextProvider::SetupLock() { | 149 void InProcessContextProvider::SetupLock() { |
| 155 } | 150 } |
| 156 | 151 |
| 157 base::Lock* InProcessContextProvider::GetLock() { | 152 base::Lock* InProcessContextProvider::GetLock() { |
| 158 return &context_lock_; | 153 return &context_lock_; |
| 159 } | 154 } |
| 160 | 155 |
| 161 void InProcessContextProvider::DeleteCachedResources() { | 156 void InProcessContextProvider::DeleteCachedResources() { |
| 162 DCHECK(context_thread_checker_.CalledOnValidThread()); | 157 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 163 | 158 |
| 164 if (gr_context_) { | 159 if (gr_context_) |
| 165 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", | 160 gr_context_->FreeGpuResources(); |
| 166 TRACE_EVENT_SCOPE_THREAD); | |
| 167 gr_context_->freeGpuResources(); | |
| 168 } | |
| 169 } | 161 } |
| 170 | 162 |
| 171 void InProcessContextProvider::SetLostContextCallback( | 163 void InProcessContextProvider::SetLostContextCallback( |
| 172 const LostContextCallback& lost_context_callback) { | 164 const LostContextCallback& lost_context_callback) { |
| 173 // Pixel tests do not test lost context. | 165 // Pixel tests do not test lost context. |
| 174 } | 166 } |
| 175 | 167 |
| 176 } // namespace ui | 168 } // namespace ui |
| OLD | NEW |