| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/thread_proxy.h" | 5 #include "cc/trees/thread_proxy.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on | 1153 // DrawLayers() depends on the result of PrepareToDraw(), it is guarded on |
| 1154 // CanDraw() as well. | 1154 // CanDraw() as well. |
| 1155 | 1155 |
| 1156 bool drawing_for_readback = readback_requested && !!impl().readback_request; | 1156 bool drawing_for_readback = readback_requested && !!impl().readback_request; |
| 1157 bool can_do_readback = | 1157 bool can_do_readback = |
| 1158 impl().layer_tree_host_impl->renderer()->CanReadPixels(); | 1158 impl().layer_tree_host_impl->renderer()->CanReadPixels(); |
| 1159 | 1159 |
| 1160 LayerTreeHostImpl::FrameData frame; | 1160 LayerTreeHostImpl::FrameData frame; |
| 1161 bool draw_frame = false; | 1161 bool draw_frame = false; |
| 1162 | 1162 |
| 1163 if (impl().layer_tree_host_impl->CanDraw() && | 1163 if (impl().layer_tree_host_impl->CanDraw()) { |
| 1164 (!drawing_for_readback || can_do_readback)) { | 1164 if (!drawing_for_readback || can_do_readback) { |
| 1165 // If it is for a readback, make sure we draw the portion being read back. | 1165 // If it is for a readback, make sure we draw the portion being read back. |
| 1166 gfx::Rect readback_rect; | 1166 gfx::Rect readback_rect; |
| 1167 if (drawing_for_readback) | 1167 if (drawing_for_readback) |
| 1168 readback_rect = impl().readback_request->rect; | 1168 readback_rect = impl().readback_request->rect; |
| 1169 | 1169 |
| 1170 result.draw_result = | 1170 result.draw_result = |
| 1171 impl().layer_tree_host_impl->PrepareToDraw(&frame, readback_rect); | 1171 impl().layer_tree_host_impl->PrepareToDraw(&frame, readback_rect); |
| 1172 draw_frame = forced_draw || | 1172 draw_frame = forced_draw || |
| 1173 result.draw_result == DrawSwapReadbackResult::DRAW_SUCCESS; | 1173 result.draw_result == DrawSwapReadbackResult::DRAW_SUCCESS; |
| 1174 } else { |
| 1175 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CANT_READBACK; |
| 1176 } |
| 1177 } else { |
| 1178 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CANT_DRAW; |
| 1174 } | 1179 } |
| 1175 | 1180 |
| 1176 if (draw_frame) { | 1181 if (draw_frame) { |
| 1177 impl().layer_tree_host_impl->DrawLayers( | 1182 impl().layer_tree_host_impl->DrawLayers( |
| 1178 &frame, impl().scheduler->LastBeginImplFrameTime()); | 1183 &frame, impl().scheduler->LastBeginImplFrameTime()); |
| 1179 result.draw_result = DrawSwapReadbackResult::DRAW_SUCCESS; | 1184 result.draw_result = DrawSwapReadbackResult::DRAW_SUCCESS; |
| 1180 impl().animations_frozen_until_next_draw = false; | 1185 impl().animations_frozen_until_next_draw = false; |
| 1181 } else if (result.draw_result == | 1186 } else if (result.draw_result == |
| 1182 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS && | 1187 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS && |
| 1183 !impl().layer_tree_host_impl->settings().impl_side_painting) { | 1188 !impl().layer_tree_host_impl->settings().impl_side_painting) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1195 } | 1200 } |
| 1196 impl().layer_tree_host_impl->DidDrawAllLayers(frame); | 1201 impl().layer_tree_host_impl->DidDrawAllLayers(frame); |
| 1197 | 1202 |
| 1198 bool start_ready_animations = draw_frame; | 1203 bool start_ready_animations = draw_frame; |
| 1199 impl().layer_tree_host_impl->UpdateAnimationState(start_ready_animations); | 1204 impl().layer_tree_host_impl->UpdateAnimationState(start_ready_animations); |
| 1200 | 1205 |
| 1201 // Check for a pending CompositeAndReadback. | 1206 // Check for a pending CompositeAndReadback. |
| 1202 if (drawing_for_readback) { | 1207 if (drawing_for_readback) { |
| 1203 DCHECK(!swap_requested); | 1208 DCHECK(!swap_requested); |
| 1204 result.did_readback = false; | 1209 result.did_readback = false; |
| 1205 if (draw_frame && !impl().layer_tree_host_impl->IsContextLost()) { | 1210 if (draw_frame) { |
| 1206 impl().layer_tree_host_impl->Readback(impl().readback_request->pixels, | 1211 if (!impl().layer_tree_host_impl->IsContextLost()) { |
| 1207 impl().readback_request->rect); | 1212 impl().layer_tree_host_impl->Readback(impl().readback_request->pixels, |
| 1208 result.did_readback = true; | 1213 impl().readback_request->rect); |
| 1214 result.did_readback = true; |
| 1215 } else { |
| 1216 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CONTEXT_LOST; |
| 1217 } |
| 1209 } | 1218 } |
| 1210 impl().readback_request->success = result.did_readback; | 1219 impl().readback_request->success = result.did_readback; |
| 1211 impl().readback_request->completion.Signal(); | 1220 impl().readback_request->completion.Signal(); |
| 1212 impl().readback_request = NULL; | 1221 impl().readback_request = NULL; |
| 1213 } else if (draw_frame) { | 1222 } else if (draw_frame) { |
| 1214 DCHECK(swap_requested); | 1223 DCHECK(swap_requested); |
| 1215 result.did_swap = impl().layer_tree_host_impl->SwapBuffers(frame); | 1224 result.did_swap = impl().layer_tree_host_impl->SwapBuffers(frame); |
| 1216 | 1225 |
| 1217 // We don't know if we have incomplete tiles if we didn't actually swap. | 1226 // We don't know if we have incomplete tiles if we didn't actually swap. |
| 1218 if (result.did_swap) { | 1227 if (result.did_swap) { |
| 1219 DCHECK(!frame.has_no_damage); | 1228 DCHECK(!frame.has_no_damage); |
| 1220 SetSwapUsedIncompleteTileOnImplThread(frame.contains_incomplete_tile); | 1229 SetSwapUsedIncompleteTileOnImplThread(frame.contains_incomplete_tile); |
| 1221 } | 1230 } |
| 1222 } | 1231 } |
| 1223 | 1232 |
| 1224 // Tell the main thread that the the newly-commited frame was drawn. | 1233 // Tell the main thread that the the newly-commited frame was drawn. |
| 1225 if (impl().next_frame_is_newly_committed_frame) { | 1234 if (impl().next_frame_is_newly_committed_frame) { |
| 1226 impl().next_frame_is_newly_committed_frame = false; | 1235 impl().next_frame_is_newly_committed_frame = false; |
| 1227 Proxy::MainThreadTaskRunner()->PostTask( | 1236 Proxy::MainThreadTaskRunner()->PostTask( |
| 1228 FROM_HERE, | 1237 FROM_HERE, |
| 1229 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); | 1238 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); |
| 1230 } | 1239 } |
| 1231 | 1240 |
| 1232 if (draw_frame) { | 1241 if (draw_frame) |
| 1233 CheckOutputSurfaceStatusOnImplThread(); | 1242 CheckOutputSurfaceStatusOnImplThread(); |
| 1234 | 1243 |
| 1244 if (result.draw_result == DrawSwapReadbackResult::DRAW_SUCCESS) { |
| 1235 base::TimeDelta draw_duration = impl().timing_history.DidFinishDrawing(); | 1245 base::TimeDelta draw_duration = impl().timing_history.DidFinishDrawing(); |
| 1236 | 1246 |
| 1237 base::TimeDelta draw_duration_overestimate; | 1247 base::TimeDelta draw_duration_overestimate; |
| 1238 base::TimeDelta draw_duration_underestimate; | 1248 base::TimeDelta draw_duration_underestimate; |
| 1239 if (draw_duration > draw_duration_estimate) | 1249 if (draw_duration > draw_duration_estimate) |
| 1240 draw_duration_underestimate = draw_duration - draw_duration_estimate; | 1250 draw_duration_underestimate = draw_duration - draw_duration_estimate; |
| 1241 else | 1251 else |
| 1242 draw_duration_overestimate = draw_duration_estimate - draw_duration; | 1252 draw_duration_overestimate = draw_duration_estimate - draw_duration; |
| 1243 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", | 1253 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", |
| 1244 draw_duration, | 1254 draw_duration, |
| 1245 base::TimeDelta::FromMilliseconds(1), | 1255 base::TimeDelta::FromMilliseconds(1), |
| 1246 base::TimeDelta::FromMilliseconds(100), | 1256 base::TimeDelta::FromMilliseconds(100), |
| 1247 50); | 1257 50); |
| 1248 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate", | 1258 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate", |
| 1249 draw_duration_underestimate, | 1259 draw_duration_underestimate, |
| 1250 base::TimeDelta::FromMilliseconds(1), | 1260 base::TimeDelta::FromMilliseconds(1), |
| 1251 base::TimeDelta::FromMilliseconds(100), | 1261 base::TimeDelta::FromMilliseconds(100), |
| 1252 50); | 1262 50); |
| 1253 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate", | 1263 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate", |
| 1254 draw_duration_overestimate, | 1264 draw_duration_overestimate, |
| 1255 base::TimeDelta::FromMilliseconds(1), | 1265 base::TimeDelta::FromMilliseconds(1), |
| 1256 base::TimeDelta::FromMilliseconds(100), | 1266 base::TimeDelta::FromMilliseconds(100), |
| 1257 50); | 1267 50); |
| 1258 } | 1268 } |
| 1259 | 1269 |
| 1270 DCHECK_NE(DrawSwapReadbackResult::INVALID_RESULT, result.draw_result); |
| 1260 return result; | 1271 return result; |
| 1261 } | 1272 } |
| 1262 | 1273 |
| 1263 void ThreadProxy::AcquireLayerTextures() { | 1274 void ThreadProxy::AcquireLayerTextures() { |
| 1264 // Called when the main thread needs to modify a layer texture that is used | 1275 // Called when the main thread needs to modify a layer texture that is used |
| 1265 // directly by the compositor. | 1276 // directly by the compositor. |
| 1266 // This method will block until the next compositor draw if there is a | 1277 // This method will block until the next compositor draw if there is a |
| 1267 // previously committed frame that is still undrawn. This is necessary to | 1278 // previously committed frame that is still undrawn. This is necessary to |
| 1268 // ensure that the main thread does not monopolize access to the textures. | 1279 // ensure that the main thread does not monopolize access to the textures. |
| 1269 DCHECK(IsMainThread()); | 1280 DCHECK(IsMainThread()); |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 | 1706 |
| 1696 impl().timing_history.DidActivatePendingTree(); | 1707 impl().timing_history.DidActivatePendingTree(); |
| 1697 } | 1708 } |
| 1698 | 1709 |
| 1699 void ThreadProxy::DidManageTiles() { | 1710 void ThreadProxy::DidManageTiles() { |
| 1700 DCHECK(IsImplThread()); | 1711 DCHECK(IsImplThread()); |
| 1701 impl().scheduler->DidManageTiles(); | 1712 impl().scheduler->DidManageTiles(); |
| 1702 } | 1713 } |
| 1703 | 1714 |
| 1704 } // namespace cc | 1715 } // namespace cc |
| OLD | NEW |