| 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/gl_bindings_skia_cmd_buffer.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 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 27 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 27 gpu::ImageFactory* image_factory, | 28 gpu::ImageFactory* image_factory, |
| 28 gfx::AcceleratedWidget window, | 29 gfx::AcceleratedWidget window, |
| 29 const std::string& debug_name) { | 30 const std::string& debug_name) { |
| 30 return new InProcessContextProvider( | 31 return new InProcessContextProvider(attribs, shared_context, |
| 31 attribs, gpu_memory_buffer_manager, image_factory, window, debug_name); | 32 gpu_memory_buffer_manager, image_factory, |
| 33 window, debug_name); |
| 32 } | 34 } |
| 33 | 35 |
| 34 // static | 36 // static |
| 35 scoped_refptr<InProcessContextProvider> | 37 scoped_refptr<InProcessContextProvider> |
| 36 InProcessContextProvider::CreateOffscreen( | 38 InProcessContextProvider::CreateOffscreen( |
| 37 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 39 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 38 gpu::ImageFactory* image_factory) { | 40 gpu::ImageFactory* image_factory, |
| 41 InProcessContextProvider* shared_context) { |
| 39 gpu::gles2::ContextCreationAttribHelper attribs; | 42 gpu::gles2::ContextCreationAttribHelper attribs; |
| 40 attribs.alpha_size = 8; | 43 attribs.alpha_size = 8; |
| 41 attribs.blue_size = 8; | 44 attribs.blue_size = 8; |
| 42 attribs.green_size = 8; | 45 attribs.green_size = 8; |
| 43 attribs.red_size = 8; | 46 attribs.red_size = 8; |
| 44 attribs.depth_size = 0; | 47 attribs.depth_size = 0; |
| 45 attribs.stencil_size = 8; | 48 attribs.stencil_size = 8; |
| 46 attribs.samples = 0; | 49 attribs.samples = 0; |
| 47 attribs.sample_buffers = 0; | 50 attribs.sample_buffers = 0; |
| 48 attribs.fail_if_major_perf_caveat = false; | 51 attribs.fail_if_major_perf_caveat = false; |
| 49 attribs.bind_generates_resource = false; | 52 attribs.bind_generates_resource = false; |
| 50 return new InProcessContextProvider(attribs, gpu_memory_buffer_manager, | 53 return new InProcessContextProvider(attribs, shared_context, |
| 51 image_factory, | 54 gpu_memory_buffer_manager, image_factory, |
| 52 gfx::kNullAcceleratedWidget, "Offscreen"); | 55 gfx::kNullAcceleratedWidget, "Offscreen"); |
| 53 } | 56 } |
| 54 | 57 |
| 55 InProcessContextProvider::InProcessContextProvider( | 58 InProcessContextProvider::InProcessContextProvider( |
| 56 const gpu::gles2::ContextCreationAttribHelper& attribs, | 59 const gpu::gles2::ContextCreationAttribHelper& attribs, |
| 60 InProcessContextProvider* shared_context, |
| 57 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 61 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 58 gpu::ImageFactory* image_factory, | 62 gpu::ImageFactory* image_factory, |
| 59 gfx::AcceleratedWidget window, | 63 gfx::AcceleratedWidget window, |
| 60 const std::string& debug_name) | 64 const std::string& debug_name) |
| 61 : attribs_(attribs), | 65 : attribs_(attribs), |
| 66 shared_context_(shared_context), |
| 62 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 67 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
| 63 image_factory_(image_factory), | 68 image_factory_(image_factory), |
| 64 window_(window), | 69 window_(window), |
| 65 debug_name_(debug_name) { | 70 debug_name_(debug_name) { |
| 66 DCHECK(main_thread_checker_.CalledOnValidThread()); | 71 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 67 context_thread_checker_.DetachFromThread(); | 72 context_thread_checker_.DetachFromThread(); |
| 68 } | 73 } |
| 69 | 74 |
| 70 InProcessContextProvider::~InProcessContextProvider() { | 75 InProcessContextProvider::~InProcessContextProvider() { |
| 71 DCHECK(main_thread_checker_.CalledOnValidThread() || | 76 DCHECK(main_thread_checker_.CalledOnValidThread() || |
| 72 context_thread_checker_.CalledOnValidThread()); | 77 context_thread_checker_.CalledOnValidThread()); |
| 73 if (gr_context_) | 78 if (gr_context_) |
| 74 gr_context_->releaseResourcesAndAbandonContext(); | 79 gr_context_->releaseResourcesAndAbandonContext(); |
| 75 } | 80 } |
| 76 | 81 |
| 77 bool InProcessContextProvider::BindToCurrentThread() { | 82 bool InProcessContextProvider::BindToCurrentThread() { |
| 78 // This is called on the thread the context will be used. | 83 // This is called on the thread the context will be used. |
| 79 DCHECK(context_thread_checker_.CalledOnValidThread()); | 84 DCHECK(context_thread_checker_.CalledOnValidThread()); |
| 80 | 85 |
| 81 if (!context_) { | 86 if (!context_) { |
| 82 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 87 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| 83 context_.reset(gpu::GLInProcessContext::Create( | 88 context_.reset(gpu::GLInProcessContext::Create( |
| 84 nullptr, /* service */ | 89 nullptr, /* service */ |
| 85 nullptr, /* surface */ | 90 nullptr, /* surface */ |
| 86 !window_, /* is_offscreen */ | 91 !window_, /* is_offscreen */ |
| 87 window_, gfx::Size(1, 1), nullptr, /* share_context */ | 92 window_, gfx::Size(1, 1), |
| 88 true, /* share_resources */ | 93 (shared_context_ ? shared_context_->context_.get() : nullptr), attribs_, |
| 89 attribs_, gpu_preference, gpu::GLInProcessContextSharedMemoryLimits(), | 94 gpu_preference, gpu::GLInProcessContextSharedMemoryLimits(), |
| 90 gpu_memory_buffer_manager_, image_factory_)); | 95 gpu_memory_buffer_manager_, image_factory_)); |
| 91 | 96 |
| 92 if (!context_) | 97 if (!context_) |
| 93 return false; | 98 return false; |
| 94 | |
| 95 context_->SetContextLostCallback(base::Bind( | |
| 96 &InProcessContextProvider::OnLostContext, base::Unretained(this))); | |
| 97 } | 99 } |
| 98 | 100 |
| 99 capabilities_.gpu = context_->GetImplementation()->capabilities(); | 101 capabilities_.gpu = context_->GetImplementation()->capabilities(); |
| 100 | 102 |
| 101 std::string unique_context_name = | 103 std::string unique_context_name = |
| 102 base::StringPrintf("%s-%p", debug_name_.c_str(), context_.get()); | 104 base::StringPrintf("%s-%p", debug_name_.c_str(), context_.get()); |
| 103 context_->GetImplementation()->TraceBeginCHROMIUM( | 105 context_->GetImplementation()->TraceBeginCHROMIUM( |
| 104 "gpu_toplevel", unique_context_name.c_str()); | 106 "gpu_toplevel", unique_context_name.c_str()); |
| 105 | 107 |
| 106 return true; | 108 return true; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 163 |
| 162 if (gr_context_) { | 164 if (gr_context_) { |
| 163 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", | 165 TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", |
| 164 TRACE_EVENT_SCOPE_THREAD); | 166 TRACE_EVENT_SCOPE_THREAD); |
| 165 gr_context_->freeGpuResources(); | 167 gr_context_->freeGpuResources(); |
| 166 } | 168 } |
| 167 } | 169 } |
| 168 | 170 |
| 169 void InProcessContextProvider::SetLostContextCallback( | 171 void InProcessContextProvider::SetLostContextCallback( |
| 170 const LostContextCallback& lost_context_callback) { | 172 const LostContextCallback& lost_context_callback) { |
| 171 lost_context_callback_ = lost_context_callback; | 173 // Pixel tests do not test lost context. |
| 172 } | |
| 173 | |
| 174 void InProcessContextProvider::OnLostContext() { | |
| 175 DCHECK(context_thread_checker_.CalledOnValidThread()); | |
| 176 if (!lost_context_callback_.is_null()) | |
| 177 base::ResetAndReturn(&lost_context_callback_).Run(); | |
| 178 if (gr_context_) | |
| 179 gr_context_->abandonContext(); | |
| 180 } | 174 } |
| 181 | 175 |
| 182 } // namespace ui | 176 } // namespace ui |
| OLD | NEW |