Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: cc/trees/thread_proxy.cc

Issue 162473003: cc: Add more DrawSwapReadbackResult enums (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More checks Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 } 1313 }
1303 1314
1304 void ThreadProxy::ScheduledActionManageTiles() { 1315 void ThreadProxy::ScheduledActionManageTiles() {
1305 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionManageTiles"); 1316 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionManageTiles");
1306 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting); 1317 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting);
1307 impl().layer_tree_host_impl->ManageTiles(); 1318 impl().layer_tree_host_impl->ManageTiles();
1308 } 1319 }
1309 1320
1310 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() { 1321 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
1311 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); 1322 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap");
1323
1324 // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to
1325 // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should
1326 // never generate this call when it can't draw.
1327 DCHECK(impl().layer_tree_host_impl->CanDraw());
1328
1312 bool forced_draw = false; 1329 bool forced_draw = false;
1313 bool swap_requested = true; 1330 bool swap_requested = true;
1314 bool readback_requested = false; 1331 bool readback_requested = false;
1315 return DrawSwapReadbackInternal( 1332 return DrawSwapReadbackInternal(
1316 forced_draw, swap_requested, readback_requested); 1333 forced_draw, swap_requested, readback_requested);
1317 } 1334 }
1318 1335
1319 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapForced() { 1336 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapForced() {
1320 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced"); 1337 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced");
1321 bool forced_draw = true; 1338 bool forced_draw = true;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1695 1712
1696 impl().timing_history.DidActivatePendingTree(); 1713 impl().timing_history.DidActivatePendingTree();
1697 } 1714 }
1698 1715
1699 void ThreadProxy::DidManageTiles() { 1716 void ThreadProxy::DidManageTiles() {
1700 DCHECK(IsImplThread()); 1717 DCHECK(IsImplThread());
1701 impl().scheduler->DidManageTiles(); 1718 impl().scheduler->DidManageTiles();
1702 } 1719 }
1703 1720
1704 } // namespace cc 1721 } // namespace cc
OLDNEW
« cc/scheduler/scheduler_state_machine.cc ('K') | « cc/scheduler/scheduler_state_machine_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698