| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/gpu/image_transport_surface.h" | 5 #include "content/common/gpu/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 "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 void PassThroughImageTransportSurface::Destroy() { | 180 void PassThroughImageTransportSurface::Destroy() { |
| 181 GLSurfaceAdapter::Destroy(); | 181 GLSurfaceAdapter::Destroy(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void PassThroughImageTransportSurface::SetLatencyInfo( | 184 void PassThroughImageTransportSurface::SetLatencyInfo( |
| 185 const std::vector<ui::LatencyInfo>& latency_info) { | 185 const std::vector<ui::LatencyInfo>& latency_info) { |
| 186 for (size_t i = 0; i < latency_info.size(); i++) | 186 for (size_t i = 0; i < latency_info.size(); i++) |
| 187 latency_info_.push_back(latency_info[i]); | 187 latency_info_.push_back(latency_info[i]); |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool PassThroughImageTransportSurface::SwapBuffers() { | 190 gfx::SwapResult PassThroughImageTransportSurface::SwapBuffers() { |
| 191 // GetVsyncValues before SwapBuffers to work around Mali driver bug: | 191 // GetVsyncValues before SwapBuffers to work around Mali driver bug: |
| 192 // crbug.com/223558. | 192 // crbug.com/223558. |
| 193 SendVSyncUpdateIfAvailable(); | 193 SendVSyncUpdateIfAvailable(); |
| 194 | 194 |
| 195 base::TimeTicks swap_time = base::TimeTicks::Now(); | 195 base::TimeTicks swap_time = base::TimeTicks::Now(); |
| 196 for (auto& latency : latency_info_) { | 196 for (auto& latency : latency_info_) { |
| 197 latency.AddLatencyNumberWithTimestamp( | 197 latency.AddLatencyNumberWithTimestamp( |
| 198 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); | 198 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); |
| 199 } | 199 } |
| 200 | 200 |
| 201 // We use WeakPtr here to avoid manual management of life time of an instance | 201 // We use WeakPtr here to avoid manual management of life time of an instance |
| 202 // of this class. Callback will not be called once the instance of this class | 202 // of this class. Callback will not be called once the instance of this class |
| 203 // is destroyed. However, this also means that the callback can be run on | 203 // is destroyed. However, this also means that the callback can be run on |
| 204 // the calling thread only. | 204 // the calling thread only. |
| 205 return gfx::GLSurfaceAdapter::SwapBuffersAsync( | 205 return gfx::GLSurfaceAdapter::SwapBuffersAsync( |
| 206 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, | 206 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, |
| 207 weak_ptr_factory_.GetWeakPtr())); | 207 weak_ptr_factory_.GetWeakPtr())) |
| 208 ? gfx::SWAP_ACK |
| 209 : gfx::SWAP_FAILED; |
| 208 } | 210 } |
| 209 | 211 |
| 210 bool PassThroughImageTransportSurface::PostSubBuffer( | 212 gfx::SwapResult PassThroughImageTransportSurface::PostSubBuffer(int x, |
| 211 int x, int y, int width, int height) { | 213 int y, |
| 214 int width, |
| 215 int height) { |
| 212 SendVSyncUpdateIfAvailable(); | 216 SendVSyncUpdateIfAvailable(); |
| 213 | 217 |
| 214 base::TimeTicks swap_time = base::TimeTicks::Now(); | 218 base::TimeTicks swap_time = base::TimeTicks::Now(); |
| 215 for (auto& latency : latency_info_) { | 219 for (auto& latency : latency_info_) { |
| 216 latency.AddLatencyNumberWithTimestamp( | 220 latency.AddLatencyNumberWithTimestamp( |
| 217 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); | 221 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); |
| 218 } | 222 } |
| 219 | 223 |
| 220 // We use WeakPtr here to avoid manual management of life time of an instance | 224 // We use WeakPtr here to avoid manual management of life time of an instance |
| 221 // of this class. Callback will not be called once the instance of this class | 225 // of this class. Callback will not be called once the instance of this class |
| 222 // is destroyed. However, this also means that the callback can be run on | 226 // is destroyed. However, this also means that the callback can be run on |
| 223 // the calling thread only. | 227 // the calling thread only. |
| 224 return gfx::GLSurfaceAdapter::PostSubBufferAsync(x, y, width, height, | 228 return gfx::GLSurfaceAdapter::PostSubBufferAsync( |
| 225 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, | 229 x, y, width, height, |
| 226 weak_ptr_factory_.GetWeakPtr())); | 230 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, |
| 231 weak_ptr_factory_.GetWeakPtr())) |
| 232 ? gfx::SWAP_ACK |
| 233 : gfx::SWAP_FAILED; |
| 227 } | 234 } |
| 228 | 235 |
| 229 void PassThroughImageTransportSurface::SwapBuffersCallBack() { | 236 void PassThroughImageTransportSurface::SwapBuffersCallBack( |
| 237 gfx::SwapResult result) { |
| 230 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); | 238 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); |
| 231 for (auto& latency : latency_info_) { | 239 for (auto& latency : latency_info_) { |
| 232 latency.AddLatencyNumberWithTimestamp( | 240 latency.AddLatencyNumberWithTimestamp( |
| 233 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, | 241 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, |
| 234 swap_ack_time, 1); | 242 swap_ack_time, 1); |
| 235 } | 243 } |
| 236 | 244 |
| 237 helper_->stub()->SendSwapBuffersCompleted(latency_info_); | 245 helper_->stub()->SendSwapBuffersCompleted(latency_info_, result); |
| 238 latency_info_.clear(); | 246 latency_info_.clear(); |
| 239 } | 247 } |
| 240 | 248 |
| 241 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 249 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
| 242 if (!did_set_swap_interval_) { | 250 if (!did_set_swap_interval_) { |
| 243 ImageTransportHelper::SetSwapInterval(context); | 251 ImageTransportHelper::SetSwapInterval(context); |
| 244 did_set_swap_interval_ = true; | 252 did_set_swap_interval_ = true; |
| 245 } | 253 } |
| 246 return true; | 254 return true; |
| 247 } | 255 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 271 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 279 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
| 272 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 280 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
| 273 if (vsync_provider) { | 281 if (vsync_provider) { |
| 274 vsync_provider->GetVSyncParameters( | 282 vsync_provider->GetVSyncParameters( |
| 275 base::Bind(&GpuCommandBufferStub::SendUpdateVSyncParameters, | 283 base::Bind(&GpuCommandBufferStub::SendUpdateVSyncParameters, |
| 276 helper_->stub()->AsWeakPtr())); | 284 helper_->stub()->AsWeakPtr())); |
| 277 } | 285 } |
| 278 } | 286 } |
| 279 | 287 |
| 280 } // namespace content | 288 } // namespace content |
| OLD | NEW |