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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 base::Bind(&PassThroughImageTransportSurface::SetLatencyInfo, | 33 base::Bind(&PassThroughImageTransportSurface::SetLatencyInfo, |
34 base::Unretained(this))); | 34 base::Unretained(this))); |
35 return true; | 35 return true; |
36 } | 36 } |
37 | 37 |
38 void PassThroughImageTransportSurface::Destroy() { | 38 void PassThroughImageTransportSurface::Destroy() { |
39 GLSurfaceAdapter::Destroy(); | 39 GLSurfaceAdapter::Destroy(); |
40 } | 40 } |
41 | 41 |
42 gfx::SwapResult PassThroughImageTransportSurface::SwapBuffers() { | 42 gfx::SwapResult PassThroughImageTransportSurface::SwapBuffers() { |
43 scoped_ptr<std::vector<ui::LatencyInfo>> latency_info = StartSwapBuffers(); | 43 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info = |
| 44 StartSwapBuffers(); |
44 gfx::SwapResult result = gfx::GLSurfaceAdapter::SwapBuffers(); | 45 gfx::SwapResult result = gfx::GLSurfaceAdapter::SwapBuffers(); |
45 FinishSwapBuffers(std::move(latency_info), result); | 46 FinishSwapBuffers(std::move(latency_info), result); |
46 return result; | 47 return result; |
47 } | 48 } |
48 | 49 |
49 void PassThroughImageTransportSurface::SwapBuffersAsync( | 50 void PassThroughImageTransportSurface::SwapBuffersAsync( |
50 const GLSurface::SwapCompletionCallback& callback) { | 51 const GLSurface::SwapCompletionCallback& callback) { |
51 scoped_ptr<std::vector<ui::LatencyInfo>> latency_info = StartSwapBuffers(); | 52 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info = |
| 53 StartSwapBuffers(); |
52 | 54 |
53 // We use WeakPtr here to avoid manual management of life time of an instance | 55 // We use WeakPtr here to avoid manual management of life time of an instance |
54 // of this class. Callback will not be called once the instance of this class | 56 // of this class. Callback will not be called once the instance of this class |
55 // is destroyed. However, this also means that the callback can be run on | 57 // is destroyed. However, this also means that the callback can be run on |
56 // the calling thread only. | 58 // the calling thread only. |
57 gfx::GLSurfaceAdapter::SwapBuffersAsync(base::Bind( | 59 gfx::GLSurfaceAdapter::SwapBuffersAsync(base::Bind( |
58 &PassThroughImageTransportSurface::FinishSwapBuffersAsync, | 60 &PassThroughImageTransportSurface::FinishSwapBuffersAsync, |
59 weak_ptr_factory_.GetWeakPtr(), base::Passed(&latency_info), callback)); | 61 weak_ptr_factory_.GetWeakPtr(), base::Passed(&latency_info), callback)); |
60 } | 62 } |
61 | 63 |
62 gfx::SwapResult PassThroughImageTransportSurface::PostSubBuffer(int x, | 64 gfx::SwapResult PassThroughImageTransportSurface::PostSubBuffer(int x, |
63 int y, | 65 int y, |
64 int width, | 66 int width, |
65 int height) { | 67 int height) { |
66 scoped_ptr<std::vector<ui::LatencyInfo>> latency_info = StartSwapBuffers(); | 68 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info = |
| 69 StartSwapBuffers(); |
67 gfx::SwapResult result = | 70 gfx::SwapResult result = |
68 gfx::GLSurfaceAdapter::PostSubBuffer(x, y, width, height); | 71 gfx::GLSurfaceAdapter::PostSubBuffer(x, y, width, height); |
69 FinishSwapBuffers(std::move(latency_info), result); | 72 FinishSwapBuffers(std::move(latency_info), result); |
70 return result; | 73 return result; |
71 } | 74 } |
72 | 75 |
73 void PassThroughImageTransportSurface::PostSubBufferAsync( | 76 void PassThroughImageTransportSurface::PostSubBufferAsync( |
74 int x, | 77 int x, |
75 int y, | 78 int y, |
76 int width, | 79 int width, |
77 int height, | 80 int height, |
78 const GLSurface::SwapCompletionCallback& callback) { | 81 const GLSurface::SwapCompletionCallback& callback) { |
79 scoped_ptr<std::vector<ui::LatencyInfo>> latency_info = StartSwapBuffers(); | 82 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info = |
| 83 StartSwapBuffers(); |
80 gfx::GLSurfaceAdapter::PostSubBufferAsync( | 84 gfx::GLSurfaceAdapter::PostSubBufferAsync( |
81 x, y, width, height, | 85 x, y, width, height, |
82 base::Bind(&PassThroughImageTransportSurface::FinishSwapBuffersAsync, | 86 base::Bind(&PassThroughImageTransportSurface::FinishSwapBuffersAsync, |
83 weak_ptr_factory_.GetWeakPtr(), base::Passed(&latency_info), | 87 weak_ptr_factory_.GetWeakPtr(), base::Passed(&latency_info), |
84 callback)); | 88 callback)); |
85 } | 89 } |
86 | 90 |
87 gfx::SwapResult PassThroughImageTransportSurface::CommitOverlayPlanes() { | 91 gfx::SwapResult PassThroughImageTransportSurface::CommitOverlayPlanes() { |
88 scoped_ptr<std::vector<ui::LatencyInfo>> latency_info = StartSwapBuffers(); | 92 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info = |
| 93 StartSwapBuffers(); |
89 gfx::SwapResult result = gfx::GLSurfaceAdapter::CommitOverlayPlanes(); | 94 gfx::SwapResult result = gfx::GLSurfaceAdapter::CommitOverlayPlanes(); |
90 FinishSwapBuffers(std::move(latency_info), result); | 95 FinishSwapBuffers(std::move(latency_info), result); |
91 return result; | 96 return result; |
92 } | 97 } |
93 | 98 |
94 void PassThroughImageTransportSurface::CommitOverlayPlanesAsync( | 99 void PassThroughImageTransportSurface::CommitOverlayPlanesAsync( |
95 const GLSurface::SwapCompletionCallback& callback) { | 100 const GLSurface::SwapCompletionCallback& callback) { |
96 scoped_ptr<std::vector<ui::LatencyInfo>> latency_info = StartSwapBuffers(); | 101 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info = |
| 102 StartSwapBuffers(); |
97 gfx::GLSurfaceAdapter::CommitOverlayPlanesAsync(base::Bind( | 103 gfx::GLSurfaceAdapter::CommitOverlayPlanesAsync(base::Bind( |
98 &PassThroughImageTransportSurface::FinishSwapBuffersAsync, | 104 &PassThroughImageTransportSurface::FinishSwapBuffersAsync, |
99 weak_ptr_factory_.GetWeakPtr(), base::Passed(&latency_info), callback)); | 105 weak_ptr_factory_.GetWeakPtr(), base::Passed(&latency_info), callback)); |
100 } | 106 } |
101 | 107 |
102 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 108 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
103 if (!did_set_swap_interval_) { | 109 if (!did_set_swap_interval_) { |
104 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 110 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
105 switches::kDisableGpuVsync)) | 111 switches::kDisableGpuVsync)) |
106 context->ForceSwapIntervalZero(true); | 112 context->ForceSwapIntervalZero(true); |
(...skipping 18 matching lines...) Expand all Loading... |
125 } | 131 } |
126 | 132 |
127 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 133 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
128 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 134 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
129 if (vsync_provider) { | 135 if (vsync_provider) { |
130 vsync_provider->GetVSyncParameters(base::Bind( | 136 vsync_provider->GetVSyncParameters(base::Bind( |
131 &GpuCommandBufferStub::SendUpdateVSyncParameters, stub_->AsWeakPtr())); | 137 &GpuCommandBufferStub::SendUpdateVSyncParameters, stub_->AsWeakPtr())); |
132 } | 138 } |
133 } | 139 } |
134 | 140 |
135 scoped_ptr<std::vector<ui::LatencyInfo>> | 141 std::unique_ptr<std::vector<ui::LatencyInfo>> |
136 PassThroughImageTransportSurface::StartSwapBuffers() { | 142 PassThroughImageTransportSurface::StartSwapBuffers() { |
137 // GetVsyncValues before SwapBuffers to work around Mali driver bug: | 143 // GetVsyncValues before SwapBuffers to work around Mali driver bug: |
138 // crbug.com/223558. | 144 // crbug.com/223558. |
139 SendVSyncUpdateIfAvailable(); | 145 SendVSyncUpdateIfAvailable(); |
140 | 146 |
141 base::TimeTicks swap_time = base::TimeTicks::Now(); | 147 base::TimeTicks swap_time = base::TimeTicks::Now(); |
142 for (auto& latency : latency_info_) { | 148 for (auto& latency : latency_info_) { |
143 latency.AddLatencyNumberWithTimestamp( | 149 latency.AddLatencyNumberWithTimestamp( |
144 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); | 150 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); |
145 } | 151 } |
146 | 152 |
147 scoped_ptr<std::vector<ui::LatencyInfo>> latency_info( | 153 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info( |
148 new std::vector<ui::LatencyInfo>()); | 154 new std::vector<ui::LatencyInfo>()); |
149 latency_info->swap(latency_info_); | 155 latency_info->swap(latency_info_); |
150 | 156 |
151 return latency_info; | 157 return latency_info; |
152 } | 158 } |
153 | 159 |
154 void PassThroughImageTransportSurface::FinishSwapBuffers( | 160 void PassThroughImageTransportSurface::FinishSwapBuffers( |
155 scoped_ptr<std::vector<ui::LatencyInfo>> latency_info, | 161 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info, |
156 gfx::SwapResult result) { | 162 gfx::SwapResult result) { |
157 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); | 163 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); |
158 for (auto& latency : *latency_info) { | 164 for (auto& latency : *latency_info) { |
159 latency.AddLatencyNumberWithTimestamp( | 165 latency.AddLatencyNumberWithTimestamp( |
160 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, | 166 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, |
161 swap_ack_time, 1); | 167 swap_ack_time, 1); |
162 } | 168 } |
163 | 169 |
164 stub_->SendSwapBuffersCompleted(*latency_info, result); | 170 stub_->SendSwapBuffersCompleted(*latency_info, result); |
165 } | 171 } |
166 | 172 |
167 void PassThroughImageTransportSurface::FinishSwapBuffersAsync( | 173 void PassThroughImageTransportSurface::FinishSwapBuffersAsync( |
168 scoped_ptr<std::vector<ui::LatencyInfo>> latency_info, | 174 std::unique_ptr<std::vector<ui::LatencyInfo>> latency_info, |
169 GLSurface::SwapCompletionCallback callback, | 175 GLSurface::SwapCompletionCallback callback, |
170 gfx::SwapResult result) { | 176 gfx::SwapResult result) { |
171 FinishSwapBuffers(std::move(latency_info), result); | 177 FinishSwapBuffers(std::move(latency_info), result); |
172 callback.Run(result); | 178 callback.Run(result); |
173 } | 179 } |
174 | 180 |
175 } // namespace gpu | 181 } // namespace gpu |
OLD | NEW |