| 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/output_surface.h" | 5 #include "cc/output/output_surface.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/output_surface_client.h" | 14 #include "cc/output/output_surface_client.h" |
| 15 #include "cc/output/output_surface_frame.h" | 15 #include "cc/output/output_surface_frame.h" |
| 16 #include "gpu/GLES2/gl2extchromium.h" | 16 #include "gpu/GLES2/gl2extchromium.h" |
| 17 #include "gpu/command_buffer/client/context_support.h" | 17 #include "gpu/command_buffer/client/context_support.h" |
| 18 #include "gpu/command_buffer/client/gles2_interface.h" | 18 #include "gpu/command_buffer/client/gles2_interface.h" |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 | 21 |
| 22 OutputSurface::OutputSurface(scoped_refptr<ContextProvider> context_provider) | 22 OutputSurface::OutputSurface(scoped_refptr<ContextProvider> context_provider) |
| 23 : context_provider_(std::move(context_provider)), weak_ptr_factory_(this) { | 23 : context_provider_(std::move(context_provider)) { |
| 24 DCHECK(context_provider_); | 24 DCHECK(context_provider_); |
| 25 thread_checker_.DetachFromThread(); | 25 thread_checker_.DetachFromThread(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 OutputSurface::OutputSurface( | 28 OutputSurface::OutputSurface( |
| 29 std::unique_ptr<SoftwareOutputDevice> software_device) | 29 std::unique_ptr<SoftwareOutputDevice> software_device) |
| 30 : software_device_(std::move(software_device)), weak_ptr_factory_(this) { | 30 : software_device_(std::move(software_device)) { |
| 31 DCHECK(software_device_); | 31 DCHECK(software_device_); |
| 32 thread_checker_.DetachFromThread(); | 32 thread_checker_.DetachFromThread(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 OutputSurface::OutputSurface( | 35 OutputSurface::OutputSurface( |
| 36 scoped_refptr<VulkanContextProvider> vulkan_context_provider) | 36 scoped_refptr<VulkanContextProvider> vulkan_context_provider) |
| 37 : vulkan_context_provider_(vulkan_context_provider), | 37 : vulkan_context_provider_(std::move(vulkan_context_provider)) { |
| 38 weak_ptr_factory_(this) { | |
| 39 DCHECK(vulkan_context_provider_); | 38 DCHECK(vulkan_context_provider_); |
| 40 thread_checker_.DetachFromThread(); | 39 thread_checker_.DetachFromThread(); |
| 41 } | 40 } |
| 42 | 41 |
| 43 OutputSurface::~OutputSurface() { | 42 OutputSurface::~OutputSurface() { |
| 44 // Is destroyed on the thread it is bound to. | 43 // Is destroyed on the thread it is bound to. |
| 45 DCHECK(thread_checker_.CalledOnValidThread()); | 44 DCHECK(thread_checker_.CalledOnValidThread()); |
| 46 | 45 |
| 47 if (!client_) | 46 if (!client_) |
| 48 return; | 47 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 61 | 60 |
| 62 if (context_provider_) { | 61 if (context_provider_) { |
| 63 if (!context_provider_->BindToCurrentThread()) | 62 if (!context_provider_->BindToCurrentThread()) |
| 64 return false; | 63 return false; |
| 65 context_provider_->SetLostContextCallback(base::Bind( | 64 context_provider_->SetLostContextCallback(base::Bind( |
| 66 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); | 65 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); |
| 67 } | 66 } |
| 68 return true; | 67 return true; |
| 69 } | 68 } |
| 70 | 69 |
| 71 void OutputSurface::PostSwapBuffersComplete() { | |
| 72 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 73 FROM_HERE, base::Bind(&OutputSurface::OnSwapBuffersComplete, | |
| 74 weak_ptr_factory_.GetWeakPtr())); | |
| 75 } | |
| 76 | |
| 77 // We don't post tasks bound to the client directly since they might run | |
| 78 // after the OutputSurface has been destroyed. | |
| 79 void OutputSurface::OnSwapBuffersComplete() { | |
| 80 client_->DidSwapBuffersComplete(); | |
| 81 } | |
| 82 | |
| 83 void OutputSurface::DidLoseOutputSurface() { | 70 void OutputSurface::DidLoseOutputSurface() { |
| 84 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface"); | 71 TRACE_EVENT0("cc", "OutputSurface::DidLoseOutputSurface"); |
| 85 client_->DidLoseOutputSurface(); | 72 client_->DidLoseOutputSurface(); |
| 86 } | 73 } |
| 87 | 74 |
| 88 } // namespace cc | 75 } // namespace cc |
| OLD | NEW |