| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 } | 27 } |
| 28 | 28 |
| 29 CompositorFrameSink::CompositorFrameSink( | 29 CompositorFrameSink::CompositorFrameSink( |
| 30 scoped_refptr<VulkanContextProvider> vulkan_context_provider) | 30 scoped_refptr<VulkanContextProvider> vulkan_context_provider) |
| 31 : vulkan_context_provider_(vulkan_context_provider) { | 31 : vulkan_context_provider_(vulkan_context_provider) { |
| 32 client_thread_checker_.DetachFromThread(); | 32 client_thread_checker_.DetachFromThread(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 CompositorFrameSink::~CompositorFrameSink() { | 35 CompositorFrameSink::~CompositorFrameSink() { |
| 36 if (client_) | 36 if (client_) |
| 37 DetachFromClientInternal(); | 37 DetachFromClient(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool CompositorFrameSink::BindToClient(CompositorFrameSinkClient* client) { | 40 bool CompositorFrameSink::BindToClient(CompositorFrameSinkClient* client) { |
| 41 DCHECK(client_thread_checker_.CalledOnValidThread()); | 41 DCHECK(client_thread_checker_.CalledOnValidThread()); |
| 42 DCHECK(client); | 42 DCHECK(client); |
| 43 DCHECK(!client_); | 43 DCHECK(!client_); |
| 44 client_ = client; | 44 client_ = client; |
| 45 bool success = true; | 45 bool success = true; |
| 46 | 46 |
| 47 if (context_provider_.get()) { | 47 if (context_provider_.get()) { |
| 48 success = context_provider_->BindToCurrentThread(); | 48 success = context_provider_->BindToCurrentThread(); |
| 49 if (success) { | 49 if (success) { |
| 50 context_provider_->SetLostContextCallback( | 50 context_provider_->SetLostContextCallback( |
| 51 base::Bind(&CompositorFrameSink::DidLoseCompositorFrameSink, | 51 base::Bind(&CompositorFrameSink::DidLoseCompositorFrameSink, |
| 52 base::Unretained(this))); | 52 base::Unretained(this))); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 if (!success) | 56 if (!success) { |
| 57 DetachFromClient(); | 57 // Destroy the ContextProvider on the thread attempted to be bound. |
| 58 context_provider_ = nullptr; |
| 59 client_ = nullptr; |
| 60 } |
| 61 |
| 58 return success; | 62 return success; |
| 59 } | 63 } |
| 60 | 64 |
| 61 void CompositorFrameSink::DetachFromClient() { | 65 void CompositorFrameSink::DetachFromClient() { |
| 62 DetachFromClientInternal(); | |
| 63 } | |
| 64 | |
| 65 // We don't post tasks bound to the client directly since they might run | |
| 66 // after the CompositorFrameSink has been destroyed. | |
| 67 void CompositorFrameSink::OnSwapBuffersComplete() { | |
| 68 client_->DidSwapBuffersComplete(); | |
| 69 } | |
| 70 | |
| 71 void CompositorFrameSink::DetachFromClientInternal() { | |
| 72 DCHECK(client_thread_checker_.CalledOnValidThread()); | 66 DCHECK(client_thread_checker_.CalledOnValidThread()); |
| 73 DCHECK(client_); | 67 DCHECK(client_); |
| 74 | 68 |
| 75 if (context_provider_.get()) { | 69 if (context_provider_.get()) { |
| 76 context_provider_->SetLostContextCallback( | 70 context_provider_->SetLostContextCallback( |
| 77 ContextProvider::LostContextCallback()); | 71 ContextProvider::LostContextCallback()); |
| 78 } | 72 } |
| 73 // Destroy the ContextProvider on the bound thread. |
| 79 context_provider_ = nullptr; | 74 context_provider_ = nullptr; |
| 80 client_ = nullptr; | 75 client_ = nullptr; |
| 81 } | 76 } |
| 82 | 77 |
| 78 // We don't post tasks bound to the client directly since they might run |
| 79 // after the CompositorFrameSink has been destroyed. |
| 80 void CompositorFrameSink::OnSwapBuffersComplete() { |
| 81 client_->DidSwapBuffersComplete(); |
| 82 } |
| 83 |
| 83 void CompositorFrameSink::DidLoseCompositorFrameSink() { | 84 void CompositorFrameSink::DidLoseCompositorFrameSink() { |
| 84 TRACE_EVENT0("cc", "CompositorFrameSink::DidLoseCompositorFrameSink"); | 85 TRACE_EVENT0("cc", "CompositorFrameSink::DidLoseCompositorFrameSink"); |
| 85 client_->DidLoseCompositorFrameSink(); | 86 client_->DidLoseCompositorFrameSink(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace cc | 89 } // namespace cc |
| OLD | NEW |