| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "gpu/ipc/service/pass_through_image_transport_surface.h" | 5 #include "gpu/ipc/service/pass_through_image_transport_surface.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "gpu/ipc/common/gpu_messages.h" | |
| 12 #include "gpu/ipc/service/gpu_command_buffer_stub.h" | |
| 13 #include "ui/gfx/vsync_provider.h" | 11 #include "ui/gfx/vsync_provider.h" |
| 14 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
| 15 #include "ui/gl/gl_switches.h" | 13 #include "ui/gl/gl_switches.h" |
| 16 | 14 |
| 17 namespace gpu { | 15 namespace gpu { |
| 18 | 16 |
| 19 PassThroughImageTransportSurface::PassThroughImageTransportSurface( | 17 PassThroughImageTransportSurface::PassThroughImageTransportSurface( |
| 20 GpuCommandBufferStub* stub, | 18 base::WeakPtr<ImageTransportSurfaceDelegate> delegate, |
| 21 gl::GLSurface* surface) | 19 gl::GLSurface* surface) |
| 22 : GLSurfaceAdapter(surface), | 20 : GLSurfaceAdapter(surface), |
| 23 stub_(stub->AsWeakPtr()), | 21 delegate_(delegate), |
| 24 did_set_swap_interval_(false), | 22 did_set_swap_interval_(false), |
| 25 weak_ptr_factory_(this) {} | 23 weak_ptr_factory_(this) {} |
| 26 | 24 |
| 27 bool PassThroughImageTransportSurface::Initialize( | 25 bool PassThroughImageTransportSurface::Initialize( |
| 28 gl::GLSurface::Format format) { | 26 gl::GLSurface::Format format) { |
| 29 // The surface is assumed to have already been initialized. | 27 // The surface is assumed to have already been initialized. |
| 30 if (!stub_.get() || !stub_->decoder()) | 28 delegate_->SetLatencyInfoCallback( |
| 31 return false; | |
| 32 stub_->SetLatencyInfoCallback( | |
| 33 base::Bind(&PassThroughImageTransportSurface::SetLatencyInfo, | 29 base::Bind(&PassThroughImageTransportSurface::SetLatencyInfo, |
| 34 base::Unretained(this))); | 30 base::Unretained(this))); |
| 35 return true; | 31 return true; |
| 36 } | 32 } |
| 37 | 33 |
| 38 void PassThroughImageTransportSurface::Destroy() { | 34 void PassThroughImageTransportSurface::Destroy() { |
| 39 GLSurfaceAdapter::Destroy(); | 35 GLSurfaceAdapter::Destroy(); |
| 40 } | 36 } |
| 41 | 37 |
| 42 gfx::SwapResult PassThroughImageTransportSurface::SwapBuffers() { | 38 gfx::SwapResult PassThroughImageTransportSurface::SwapBuffers() { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 switches::kDisableGpuVsync)) | 120 switches::kDisableGpuVsync)) |
| 125 context->ForceSwapIntervalZero(true); | 121 context->ForceSwapIntervalZero(true); |
| 126 else | 122 else |
| 127 context->SetSwapInterval(1); | 123 context->SetSwapInterval(1); |
| 128 did_set_swap_interval_ = true; | 124 did_set_swap_interval_ = true; |
| 129 } | 125 } |
| 130 return true; | 126 return true; |
| 131 } | 127 } |
| 132 | 128 |
| 133 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() { | 129 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() { |
| 134 if (stub_.get()) { | 130 if (delegate_) { |
| 135 stub_->SetLatencyInfoCallback( | 131 delegate_->SetLatencyInfoCallback( |
| 136 base::Callback<void(const std::vector<ui::LatencyInfo>&)>()); | 132 base::Callback<void(const std::vector<ui::LatencyInfo>&)>()); |
| 137 } | 133 } |
| 138 } | 134 } |
| 139 | 135 |
| 140 void PassThroughImageTransportSurface::SetLatencyInfo( | 136 void PassThroughImageTransportSurface::SetLatencyInfo( |
| 141 const std::vector<ui::LatencyInfo>& latency_info) { | 137 const std::vector<ui::LatencyInfo>& latency_info) { |
| 142 latency_info_.insert(latency_info_.end(), latency_info.begin(), | 138 latency_info_.insert(latency_info_.end(), latency_info.begin(), |
| 143 latency_info.end()); | 139 latency_info.end()); |
| 144 } | 140 } |
| 145 | 141 |
| 146 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 142 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
| 147 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 143 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
| 148 if (vsync_provider) { | 144 if (vsync_provider) { |
| 145 // PassThroughImageTransportSurface owns the VSyncProvider and will |
| 146 // outlive it. Thus, base::Unretained is safe here. |
| 149 vsync_provider->GetVSyncParameters(base::Bind( | 147 vsync_provider->GetVSyncParameters(base::Bind( |
| 150 &GpuCommandBufferStub::SendUpdateVSyncParameters, stub_->AsWeakPtr())); | 148 &ImageTransportSurfaceDelegate::UpdateVSyncParameters, delegate_)); |
| 151 } | 149 } |
| 152 } | 150 } |
| 153 | 151 |
| 154 std::unique_ptr<std::vector<ui::LatencyInfo>> | 152 std::unique_ptr<std::vector<ui::LatencyInfo>> |
| 155 PassThroughImageTransportSurface::StartSwapBuffers() { | 153 PassThroughImageTransportSurface::StartSwapBuffers() { |
| 156 // GetVsyncValues before SwapBuffers to work around Mali driver bug: | 154 // GetVsyncValues before SwapBuffers to work around Mali driver bug: |
| 157 // crbug.com/223558. | 155 // crbug.com/223558. |
| 158 SendVSyncUpdateIfAvailable(); | 156 SendVSyncUpdateIfAvailable(); |
| 159 | 157 |
| 160 base::TimeTicks swap_time = base::TimeTicks::Now(); | 158 base::TimeTicks swap_time = base::TimeTicks::Now(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 173 void PassThroughImageTransportSurface::FinishSwapBuffers( | 171 void PassThroughImageTransportSurface::FinishSwapBuffers( |
| 174 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info, | 172 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info, |
| 175 gfx::SwapResult result) { | 173 gfx::SwapResult result) { |
| 176 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); | 174 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); |
| 177 for (auto& latency : *latency_info) { | 175 for (auto& latency : *latency_info) { |
| 178 latency.AddLatencyNumberWithTimestamp( | 176 latency.AddLatencyNumberWithTimestamp( |
| 179 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, | 177 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, |
| 180 swap_ack_time, 1); | 178 swap_ack_time, 1); |
| 181 } | 179 } |
| 182 | 180 |
| 183 GpuCommandBufferMsg_SwapBuffersCompleted_Params params; | 181 if (delegate_) { |
| 184 params.latency_info = *latency_info; | 182 SwapBuffersCompleteParams params; |
| 185 params.result = result; | 183 params.latency_info = std::move(*latency_info); |
| 186 stub_->SendSwapBuffersCompleted(params); | 184 params.result = result; |
| 185 delegate_->DidSwapBuffersComplete(std::move(params)); |
| 186 } |
| 187 } | 187 } |
| 188 | 188 |
| 189 void PassThroughImageTransportSurface::FinishSwapBuffersAsync( | 189 void PassThroughImageTransportSurface::FinishSwapBuffersAsync( |
| 190 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info, | 190 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info, |
| 191 GLSurface::SwapCompletionCallback callback, | 191 GLSurface::SwapCompletionCallback callback, |
| 192 gfx::SwapResult result) { | 192 gfx::SwapResult result) { |
| 193 FinishSwapBuffers(std::move(latency_info), result); | 193 FinishSwapBuffers(std::move(latency_info), result); |
| 194 callback.Run(result); | 194 callback.Run(result); |
| 195 } | 195 } |
| 196 | 196 |
| 197 } // namespace gpu | 197 } // namespace gpu |
| OLD | NEW |