Chromium Code Reviews| 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" | 11 #include "gpu/ipc/common/gpu_messages.h" |
|
piman
2016/11/09 22:49:36
nit: ditto, still needed?
Fady Samuel
2016/11/09 23:28:11
Nope removed.
| |
| 12 #include "gpu/ipc/service/gpu_command_buffer_stub.h" | |
| 13 #include "ui/gfx/vsync_provider.h" | 12 #include "ui/gfx/vsync_provider.h" |
| 14 #include "ui/gl/gl_context.h" | 13 #include "ui/gl/gl_context.h" |
| 15 #include "ui/gl/gl_switches.h" | 14 #include "ui/gl/gl_switches.h" |
| 16 | 15 |
| 17 namespace gpu { | 16 namespace gpu { |
| 18 | 17 |
| 19 PassThroughImageTransportSurface::PassThroughImageTransportSurface( | 18 PassThroughImageTransportSurface::PassThroughImageTransportSurface( |
| 20 GpuCommandBufferStub* stub, | 19 base::WeakPtr<ImageTransportSurfaceDelegate> delegate, |
| 21 gl::GLSurface* surface) | 20 gl::GLSurface* surface) |
| 22 : GLSurfaceAdapter(surface), | 21 : GLSurfaceAdapter(surface), |
| 23 stub_(stub->AsWeakPtr()), | 22 delegate_(delegate), |
| 24 did_set_swap_interval_(false), | 23 did_set_swap_interval_(false), |
| 25 weak_ptr_factory_(this) {} | 24 weak_ptr_factory_(this) {} |
| 26 | 25 |
| 27 bool PassThroughImageTransportSurface::Initialize( | 26 bool PassThroughImageTransportSurface::Initialize( |
| 28 gl::GLSurface::Format format) { | 27 gl::GLSurface::Format format) { |
| 29 // The surface is assumed to have already been initialized. | 28 // The surface is assumed to have already been initialized. |
| 30 if (!stub_.get() || !stub_->decoder()) | 29 if (!delegate_) |
|
piman
2016/11/09 22:49:36
nit: I think you could DCHECK here, which means we
Fady Samuel
2016/11/09 23:28:10
done. I'll remove the bool in a separate CL.
| |
| 31 return false; | 30 return false; |
| 32 stub_->SetLatencyInfoCallback( | 31 delegate_->SetLatencyInfoCallback( |
| 33 base::Bind(&PassThroughImageTransportSurface::SetLatencyInfo, | 32 base::Bind(&PassThroughImageTransportSurface::SetLatencyInfo, |
| 34 base::Unretained(this))); | 33 base::Unretained(this))); |
| 35 return true; | 34 return true; |
| 36 } | 35 } |
| 37 | 36 |
| 38 void PassThroughImageTransportSurface::Destroy() { | 37 void PassThroughImageTransportSurface::Destroy() { |
| 39 GLSurfaceAdapter::Destroy(); | 38 GLSurfaceAdapter::Destroy(); |
| 40 } | 39 } |
| 41 | 40 |
| 42 gfx::SwapResult PassThroughImageTransportSurface::SwapBuffers() { | 41 gfx::SwapResult PassThroughImageTransportSurface::SwapBuffers() { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 switches::kDisableGpuVsync)) | 123 switches::kDisableGpuVsync)) |
| 125 context->ForceSwapIntervalZero(true); | 124 context->ForceSwapIntervalZero(true); |
| 126 else | 125 else |
| 127 context->SetSwapInterval(1); | 126 context->SetSwapInterval(1); |
| 128 did_set_swap_interval_ = true; | 127 did_set_swap_interval_ = true; |
| 129 } | 128 } |
| 130 return true; | 129 return true; |
| 131 } | 130 } |
| 132 | 131 |
| 133 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() { | 132 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() { |
| 134 if (stub_.get()) { | 133 if (delegate_) { |
| 135 stub_->SetLatencyInfoCallback( | 134 delegate_->SetLatencyInfoCallback( |
| 136 base::Callback<void(const std::vector<ui::LatencyInfo>&)>()); | 135 base::Callback<void(const std::vector<ui::LatencyInfo>&)>()); |
| 137 } | 136 } |
| 138 } | 137 } |
| 139 | 138 |
| 140 void PassThroughImageTransportSurface::SetLatencyInfo( | 139 void PassThroughImageTransportSurface::SetLatencyInfo( |
| 141 const std::vector<ui::LatencyInfo>& latency_info) { | 140 const std::vector<ui::LatencyInfo>& latency_info) { |
| 142 latency_info_.insert(latency_info_.end(), latency_info.begin(), | 141 latency_info_.insert(latency_info_.end(), latency_info.begin(), |
| 143 latency_info.end()); | 142 latency_info.end()); |
| 144 } | 143 } |
| 145 | 144 |
| 146 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 145 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
| 147 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 146 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
| 148 if (vsync_provider) { | 147 if (vsync_provider) { |
| 149 vsync_provider->GetVSyncParameters(base::Bind( | 148 // PassThroughImageTransportSurface owns the VSyncProvider and will |
| 150 &GpuCommandBufferStub::SendUpdateVSyncParameters, stub_->AsWeakPtr())); | 149 // outlive it. Thus, base::Unretained is safe here. |
| 150 vsync_provider->GetVSyncParameters( | |
| 151 base::Bind(&PassThroughImageTransportSurface::UpdateVSyncParameters, | |
| 152 base::Unretained(this))); | |
|
piman
2016/11/09 22:49:36
nit: Any reason for the extra function, as opposed
Fady Samuel
2016/11/09 23:28:10
Done.
| |
| 151 } | 153 } |
| 152 } | 154 } |
| 153 | 155 |
| 154 std::unique_ptr<std::vector<ui::LatencyInfo>> | 156 std::unique_ptr<std::vector<ui::LatencyInfo>> |
| 155 PassThroughImageTransportSurface::StartSwapBuffers() { | 157 PassThroughImageTransportSurface::StartSwapBuffers() { |
| 156 // GetVsyncValues before SwapBuffers to work around Mali driver bug: | 158 // GetVsyncValues before SwapBuffers to work around Mali driver bug: |
| 157 // crbug.com/223558. | 159 // crbug.com/223558. |
| 158 SendVSyncUpdateIfAvailable(); | 160 SendVSyncUpdateIfAvailable(); |
| 159 | 161 |
| 160 base::TimeTicks swap_time = base::TimeTicks::Now(); | 162 base::TimeTicks swap_time = base::TimeTicks::Now(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 173 void PassThroughImageTransportSurface::FinishSwapBuffers( | 175 void PassThroughImageTransportSurface::FinishSwapBuffers( |
| 174 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info, | 176 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info, |
| 175 gfx::SwapResult result) { | 177 gfx::SwapResult result) { |
| 176 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); | 178 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); |
| 177 for (auto& latency : *latency_info) { | 179 for (auto& latency : *latency_info) { |
| 178 latency.AddLatencyNumberWithTimestamp( | 180 latency.AddLatencyNumberWithTimestamp( |
| 179 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, | 181 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, |
| 180 swap_ack_time, 1); | 182 swap_ack_time, 1); |
| 181 } | 183 } |
| 182 | 184 |
| 183 GpuCommandBufferMsg_SwapBuffersCompleted_Params params; | 185 if (delegate_) { |
| 184 params.latency_info = *latency_info; | 186 SwapBuffersCompleteParams params; |
| 185 params.result = result; | 187 params.latency_info = std::move(*latency_info); |
| 186 stub_->SendSwapBuffersCompleted(params); | 188 params.result = result; |
| 189 delegate_->DidSwapBuffersComplete(std::move(params)); | |
| 190 } | |
| 187 } | 191 } |
| 188 | 192 |
| 189 void PassThroughImageTransportSurface::FinishSwapBuffersAsync( | 193 void PassThroughImageTransportSurface::FinishSwapBuffersAsync( |
| 190 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info, | 194 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info, |
| 191 GLSurface::SwapCompletionCallback callback, | 195 GLSurface::SwapCompletionCallback callback, |
| 192 gfx::SwapResult result) { | 196 gfx::SwapResult result) { |
| 193 FinishSwapBuffers(std::move(latency_info), result); | 197 FinishSwapBuffers(std::move(latency_info), result); |
| 194 callback.Run(result); | 198 callback.Run(result); |
| 195 } | 199 } |
| 196 | 200 |
| 201 void PassThroughImageTransportSurface::UpdateVSyncParameters( | |
| 202 base::TimeTicks timebase, | |
| 203 base::TimeDelta interval) { | |
| 204 if (delegate_) | |
| 205 delegate_->UpdateVSyncParameters(timebase, interval); | |
| 206 } | |
| 207 | |
| 197 } // namespace gpu | 208 } // namespace gpu |
| OLD | NEW |