| 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 "cc/output/compositor_frame_sink.h" | 5 #include "cc/output/compositor_frame_sink.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "cc/output/compositor_frame_sink_client.h" | 14 #include "cc/output/compositor_frame_sink_client.h" |
| 15 #include "gpu/GLES2/gl2extchromium.h" | 15 #include "gpu/GLES2/gl2extchromium.h" |
| 16 #include "gpu/command_buffer/client/context_support.h" | 16 #include "gpu/command_buffer/client/context_support.h" |
| 17 #include "gpu/command_buffer/client/gles2_interface.h" | 17 #include "gpu/command_buffer/client/gles2_interface.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 CompositorFrameSink::CompositorFrameSink( | 21 CompositorFrameSink::CompositorFrameSink( |
| 22 scoped_refptr<ContextProvider> context_provider, | 22 scoped_refptr<ContextProvider> context_provider, |
| 23 scoped_refptr<ContextProvider> worker_context_provider, | 23 scoped_refptr<ContextProvider> worker_context_provider, |
| 24 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 24 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 25 SharedBitmapManager* shared_bitmap_manager) | 25 SharedBitmapManager* shared_bitmap_manager) |
| 26 : context_provider_(std::move(context_provider)), | 26 : context_provider_(std::move(context_provider)), |
| 27 worker_context_provider_(std::move(worker_context_provider)), | 27 worker_context_provider_(std::move(worker_context_provider)), |
| 28 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 28 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
| 29 shared_bitmap_manager_(shared_bitmap_manager) { | 29 shared_bitmap_manager_(shared_bitmap_manager) { |
| 30 client_thread_checker_.DetachFromThread(); | |
| 31 } | 30 } |
| 32 | 31 |
| 33 CompositorFrameSink::CompositorFrameSink( | 32 CompositorFrameSink::CompositorFrameSink( |
| 34 scoped_refptr<VulkanContextProvider> vulkan_context_provider) | 33 scoped_refptr<VulkanContextProvider> vulkan_context_provider) |
| 35 : vulkan_context_provider_(vulkan_context_provider), | 34 : vulkan_context_provider_(vulkan_context_provider), |
| 36 gpu_memory_buffer_manager_(nullptr), | 35 gpu_memory_buffer_manager_(nullptr), |
| 37 shared_bitmap_manager_(nullptr) { | 36 shared_bitmap_manager_(nullptr) { |
| 38 client_thread_checker_.DetachFromThread(); | |
| 39 } | 37 } |
| 40 | 38 |
| 41 CompositorFrameSink::~CompositorFrameSink() { | 39 CompositorFrameSink::~CompositorFrameSink() { |
| 42 if (client_) | 40 if (client_) |
| 43 DetachFromClient(); | 41 DetachFromClient(); |
| 44 } | 42 } |
| 45 | 43 |
| 46 bool CompositorFrameSink::BindToClient(CompositorFrameSinkClient* client) { | 44 bool CompositorFrameSink::BindToClient(CompositorFrameSinkClient* client) { |
| 47 DCHECK(client_thread_checker_.CalledOnValidThread()); | |
| 48 DCHECK(client); | 45 DCHECK(client); |
| 49 DCHECK(!client_); | 46 DCHECK(!client_); |
| 50 client_ = client; | 47 client_ = client; |
| 51 bool success = true; | 48 bool success = true; |
| 52 | 49 |
| 53 if (context_provider_.get()) { | 50 if (context_provider_.get()) { |
| 54 success = context_provider_->BindToCurrentThread(); | 51 success = context_provider_->BindToCurrentThread(); |
| 55 if (success) { | 52 if (success) { |
| 56 context_provider_->SetLostContextCallback( | 53 context_provider_->SetLostContextCallback( |
| 57 base::Bind(&CompositorFrameSink::DidLoseCompositorFrameSink, | 54 base::Bind(&CompositorFrameSink::DidLoseCompositorFrameSink, |
| 58 base::Unretained(this))); | 55 base::Unretained(this))); |
| 59 } | 56 } |
| 60 } | 57 } |
| 61 | 58 |
| 62 if (!success) { | 59 if (!success) { |
| 63 // Destroy the ContextProvider on the thread attempted to be bound. | 60 // Destroy the ContextProvider on the thread attempted to be bound. |
| 64 context_provider_ = nullptr; | 61 context_provider_ = nullptr; |
| 65 client_ = nullptr; | 62 client_ = nullptr; |
| 66 } | 63 } |
| 67 | 64 |
| 68 return success; | 65 return success; |
| 69 } | 66 } |
| 70 | 67 |
| 71 void CompositorFrameSink::DetachFromClient() { | 68 void CompositorFrameSink::DetachFromClient() { |
| 72 DCHECK(client_thread_checker_.CalledOnValidThread()); | |
| 73 DCHECK(client_); | 69 DCHECK(client_); |
| 74 | 70 |
| 75 if (context_provider_.get()) { | 71 if (context_provider_.get()) { |
| 76 context_provider_->SetLostContextCallback( | 72 context_provider_->SetLostContextCallback( |
| 77 ContextProvider::LostContextCallback()); | 73 ContextProvider::LostContextCallback()); |
| 78 } | 74 } |
| 79 // Destroy the ContextProvider on the bound thread. | 75 // Destroy the ContextProvider on the bound thread. |
| 80 context_provider_ = nullptr; | 76 context_provider_ = nullptr; |
| 81 client_ = nullptr; | 77 client_ = nullptr; |
| 82 } | 78 } |
| 83 | 79 |
| 84 void CompositorFrameSink::DidLoseCompositorFrameSink() { | 80 void CompositorFrameSink::DidLoseCompositorFrameSink() { |
| 85 TRACE_EVENT0("cc", "CompositorFrameSink::DidLoseCompositorFrameSink"); | 81 TRACE_EVENT0("cc", "CompositorFrameSink::DidLoseCompositorFrameSink"); |
| 86 client_->DidLoseCompositorFrameSink(); | 82 client_->DidLoseCompositorFrameSink(); |
| 87 } | 83 } |
| 88 | 84 |
| 89 } // namespace cc | 85 } // namespace cc |
| OLD | NEW |