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