| 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 std::vector<ui::LatencyInfo>* latency_info_ptr = | 205 std::vector<ui::LatencyInfo>* latency_info_ptr = |
| 206 new std::vector<ui::LatencyInfo>(); | 206 new std::vector<ui::LatencyInfo>(); |
| 207 latency_info_ptr->swap(latency_info_); | 207 latency_info_ptr->swap(latency_info_); |
| 208 return gfx::GLSurfaceAdapter::SwapBuffersAsync(base::Bind( | 208 return gfx::GLSurfaceAdapter::SwapBuffersAsync(base::Bind( |
| 209 &PassThroughImageTransportSurface::SwapBuffersCallBack, | 209 &PassThroughImageTransportSurface::SwapBuffersCallBack, |
| 210 weak_ptr_factory_.GetWeakPtr(), base::Owned(latency_info_ptr))); | 210 weak_ptr_factory_.GetWeakPtr(), base::Owned(latency_info_ptr))) |
| 211 ? gfx::SwapResult::SWAP_ACK |
| 212 : gfx::SwapResult::SWAP_FAILED; |
| 211 } | 213 } |
| 212 | 214 |
| 213 bool PassThroughImageTransportSurface::PostSubBuffer( | 215 gfx::SwapResult PassThroughImageTransportSurface::PostSubBuffer(int x, |
| 214 int x, int y, int width, int height) { | 216 int y, |
| 217 int width, |
| 218 int height) { |
| 215 SendVSyncUpdateIfAvailable(); | 219 SendVSyncUpdateIfAvailable(); |
| 216 | 220 |
| 217 base::TimeTicks swap_time = base::TimeTicks::Now(); | 221 base::TimeTicks swap_time = base::TimeTicks::Now(); |
| 218 for (auto& latency : latency_info_) { | 222 for (auto& latency : latency_info_) { |
| 219 latency.AddLatencyNumberWithTimestamp( | 223 latency.AddLatencyNumberWithTimestamp( |
| 220 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); | 224 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); |
| 221 } | 225 } |
| 222 | 226 |
| 223 // We use WeakPtr here to avoid manual management of life time of an instance | 227 // We use WeakPtr here to avoid manual management of life time of an instance |
| 224 // of this class. Callback will not be called once the instance of this class | 228 // of this class. Callback will not be called once the instance of this class |
| 225 // is destroyed. However, this also means that the callback can be run on | 229 // is destroyed. However, this also means that the callback can be run on |
| 226 // the calling thread only. | 230 // the calling thread only. |
| 227 std::vector<ui::LatencyInfo>* latency_info_ptr = | 231 std::vector<ui::LatencyInfo>* latency_info_ptr = |
| 228 new std::vector<ui::LatencyInfo>(); | 232 new std::vector<ui::LatencyInfo>(); |
| 229 latency_info_ptr->swap(latency_info_); | 233 latency_info_ptr->swap(latency_info_); |
| 230 return gfx::GLSurfaceAdapter::PostSubBufferAsync( | 234 return gfx::GLSurfaceAdapter::PostSubBufferAsync( |
| 231 x, y, width, height, | 235 x, y, width, height, |
| 232 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, | 236 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, |
| 233 weak_ptr_factory_.GetWeakPtr(), | 237 weak_ptr_factory_.GetWeakPtr(), |
| 234 base::Owned(latency_info_ptr))); | 238 base::Owned(latency_info_ptr))) |
| 239 ? gfx::SwapResult::SWAP_ACK |
| 240 : gfx::SwapResult::SWAP_FAILED; |
| 235 } | 241 } |
| 236 | 242 |
| 237 void PassThroughImageTransportSurface::SwapBuffersCallBack( | 243 void PassThroughImageTransportSurface::SwapBuffersCallBack( |
| 238 std::vector<ui::LatencyInfo>* latency_info_ptr) { | 244 std::vector<ui::LatencyInfo>* latency_info_ptr, |
| 245 gfx::SwapResult result) { |
| 239 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); | 246 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); |
| 240 for (auto& latency : *latency_info_ptr) { | 247 for (auto& latency : *latency_info_ptr) { |
| 241 latency.AddLatencyNumberWithTimestamp( | 248 latency.AddLatencyNumberWithTimestamp( |
| 242 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, | 249 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, |
| 243 swap_ack_time, 1); | 250 swap_ack_time, 1); |
| 244 } | 251 } |
| 245 | 252 |
| 246 helper_->stub()->SendSwapBuffersCompleted(*latency_info_ptr); | 253 helper_->stub()->SendSwapBuffersCompleted(*latency_info_ptr, result); |
| 247 } | 254 } |
| 248 | 255 |
| 249 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 256 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
| 250 if (!did_set_swap_interval_) { | 257 if (!did_set_swap_interval_) { |
| 251 ImageTransportHelper::SetSwapInterval(context); | 258 ImageTransportHelper::SetSwapInterval(context); |
| 252 did_set_swap_interval_ = true; | 259 did_set_swap_interval_ = true; |
| 253 } | 260 } |
| 254 return true; | 261 return true; |
| 255 } | 262 } |
| 256 | 263 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 279 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 286 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
| 280 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 287 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
| 281 if (vsync_provider) { | 288 if (vsync_provider) { |
| 282 vsync_provider->GetVSyncParameters( | 289 vsync_provider->GetVSyncParameters( |
| 283 base::Bind(&GpuCommandBufferStub::SendUpdateVSyncParameters, | 290 base::Bind(&GpuCommandBufferStub::SendUpdateVSyncParameters, |
| 284 helper_->stub()->AsWeakPtr())); | 291 helper_->stub()->AsWeakPtr())); |
| 285 } | 292 } |
| 286 } | 293 } |
| 287 | 294 |
| 288 } // namespace content | 295 } // namespace content |
| OLD | NEW |