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

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

Issue 246753008: cc: Unify use of DidSwapBuffers() and did_request_swap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Introduce HasSentDrawRequestThisFrame() Created 6 years, 7 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 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 1088
1089 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { 1089 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
1090 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation"); 1090 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation");
1091 DCHECK(IsImplThread()); 1091 DCHECK(IsImplThread());
1092 Proxy::MainThreadTaskRunner()->PostTask( 1092 Proxy::MainThreadTaskRunner()->PostTask(
1093 FROM_HERE, 1093 FROM_HERE,
1094 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, 1094 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface,
1095 main_thread_weak_ptr_)); 1095 main_thread_weak_ptr_));
1096 } 1096 }
1097 1097
1098 DrawSwapReadbackResult ThreadProxy::DrawSwapReadbackInternal( 1098 DrawResult ThreadProxy::DrawSwapReadbackInternal(
1099 bool forced_draw, 1099 bool forced_draw,
1100 bool swap_requested, 1100 bool swap_requested,
1101 bool readback_requested) { 1101 bool readback_requested) {
1102 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); 1102 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap");
1103 DrawSwapReadbackResult result; 1103 DrawResult result;
1104 1104
1105 DCHECK(IsImplThread()); 1105 DCHECK(IsImplThread());
1106 DCHECK(impl().layer_tree_host_impl.get()); 1106 DCHECK(impl().layer_tree_host_impl.get());
1107 1107
1108 impl().timing_history.DidStartDrawing(); 1108 impl().timing_history.DidStartDrawing();
1109 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); 1109 base::TimeDelta draw_duration_estimate = DrawDurationEstimate();
1110 base::AutoReset<bool> mark_inside(&impl().inside_draw, true); 1110 base::AutoReset<bool> mark_inside(&impl().inside_draw, true);
1111 1111
1112 // Advance our animations. 1112 // Advance our animations.
1113 base::TimeTicks monotonic_time; 1113 base::TimeTicks monotonic_time;
(...skipping 25 matching lines...) Expand all
1139 LayerTreeHostImpl::FrameData frame; 1139 LayerTreeHostImpl::FrameData frame;
1140 bool draw_frame = false; 1140 bool draw_frame = false;
1141 1141
1142 if (impl().layer_tree_host_impl->CanDraw()) { 1142 if (impl().layer_tree_host_impl->CanDraw()) {
1143 if (!drawing_for_readback || can_do_readback) { 1143 if (!drawing_for_readback || can_do_readback) {
1144 // If it is for a readback, make sure we draw the portion being read back. 1144 // If it is for a readback, make sure we draw the portion being read back.
1145 gfx::Rect readback_rect; 1145 gfx::Rect readback_rect;
1146 if (drawing_for_readback) 1146 if (drawing_for_readback)
1147 readback_rect = impl().readback_request->rect; 1147 readback_rect = impl().readback_request->rect;
1148 1148
1149 result.draw_result = 1149 result =
1150 impl().layer_tree_host_impl->PrepareToDraw(&frame, readback_rect); 1150 impl().layer_tree_host_impl->PrepareToDraw(&frame, readback_rect);
1151 draw_frame = forced_draw || 1151 draw_frame = forced_draw || result == DRAW_SUCCESS;
1152 result.draw_result == DrawSwapReadbackResult::DRAW_SUCCESS;
1153 } else { 1152 } else {
1154 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CANT_READBACK; 1153 result = DRAW_ABORTED_CANT_READBACK;
1155 } 1154 }
1156 } else { 1155 } else {
1157 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CANT_DRAW; 1156 result = DRAW_ABORTED_CANT_DRAW;
1158 } 1157 }
1159 1158
1160 if (draw_frame) { 1159 if (draw_frame) {
1161 impl().layer_tree_host_impl->DrawLayers( 1160 impl().layer_tree_host_impl->DrawLayers(
1162 &frame, impl().scheduler->LastBeginImplFrameTime()); 1161 &frame, impl().scheduler->LastBeginImplFrameTime());
1163 result.draw_result = DrawSwapReadbackResult::DRAW_SUCCESS; 1162 result = DRAW_SUCCESS;
1164 impl().animations_frozen_until_next_draw = false; 1163 impl().animations_frozen_until_next_draw = false;
1165 } else if (result.draw_result == 1164 } else if (result == DRAW_ABORTED_CHECKERBOARD_ANIMATIONS &&
1166 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS &&
1167 !impl().layer_tree_host_impl->settings().impl_side_painting) { 1165 !impl().layer_tree_host_impl->settings().impl_side_painting) {
1168 // Without impl-side painting, the animated layer that is checkerboarding 1166 // Without impl-side painting, the animated layer that is checkerboarding
1169 // will continue to checkerboard until the next commit. If this layer 1167 // will continue to checkerboard until the next commit. If this layer
1170 // continues to move during the commit, it may continue to checkerboard 1168 // continues to move during the commit, it may continue to checkerboard
1171 // after the commit since the region rasterized during the commit will not 1169 // after the commit since the region rasterized during the commit will not
1172 // match the region that is currently visible; eventually this 1170 // match the region that is currently visible; eventually this
1173 // checkerboarding will be displayed when we force a draw. To avoid this, 1171 // checkerboarding will be displayed when we force a draw. To avoid this,
1174 // we freeze animations until we successfully draw. 1172 // we freeze animations until we successfully draw.
1175 impl().animations_frozen_until_next_draw = true; 1173 impl().animations_frozen_until_next_draw = true;
1176 impl().animation_freeze_time = monotonic_time; 1174 impl().animation_freeze_time = monotonic_time;
1177 } else { 1175 } else {
1178 DCHECK_NE(DrawSwapReadbackResult::DRAW_SUCCESS, result.draw_result); 1176 DCHECK_NE(DRAW_SUCCESS, result);
1179 } 1177 }
1180 impl().layer_tree_host_impl->DidDrawAllLayers(frame); 1178 impl().layer_tree_host_impl->DidDrawAllLayers(frame);
1181 1179
1182 bool start_ready_animations = draw_frame; 1180 bool start_ready_animations = draw_frame;
1183 impl().layer_tree_host_impl->UpdateAnimationState(start_ready_animations); 1181 impl().layer_tree_host_impl->UpdateAnimationState(start_ready_animations);
1184 1182
1185 // Check for a pending CompositeAndReadback. 1183 // Check for a pending CompositeAndReadback.
1186 if (drawing_for_readback) { 1184 if (drawing_for_readback) {
1187 DCHECK(!swap_requested); 1185 DCHECK(!swap_requested);
1188 result.did_readback = false; 1186 bool did_readback = false;
1189 if (draw_frame) { 1187 if (draw_frame) {
1190 if (!impl().layer_tree_host_impl->IsContextLost()) { 1188 if (!impl().layer_tree_host_impl->IsContextLost()) {
1191 impl().layer_tree_host_impl->Readback(impl().readback_request->pixels, 1189 impl().layer_tree_host_impl->Readback(impl().readback_request->pixels,
1192 impl().readback_request->rect); 1190 impl().readback_request->rect);
1193 result.did_readback = true; 1191 did_readback = true;
1194 } else { 1192 } else {
1195 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CONTEXT_LOST; 1193 result = DRAW_ABORTED_CONTEXT_LOST;
1196 } 1194 }
1197 } 1195 }
1198 impl().readback_request->success = result.did_readback; 1196 impl().readback_request->success = did_readback;
1199 impl().readback_request->completion.Signal(); 1197 impl().readback_request->completion.Signal();
1200 impl().readback_request = NULL; 1198 impl().readback_request = NULL;
1201 } else if (draw_frame) { 1199 } else if (draw_frame) {
1202 DCHECK(swap_requested); 1200 DCHECK(swap_requested);
1203 result.did_request_swap = impl().layer_tree_host_impl->SwapBuffers(frame); 1201 bool did_request_swap = impl().layer_tree_host_impl->SwapBuffers(frame);
1204 1202
1205 // We don't know if we have incomplete tiles if we didn't actually swap. 1203 // We don't know if we have incomplete tiles if we didn't actually swap.
1206 if (result.did_request_swap) { 1204 if (did_request_swap) {
1207 DCHECK(!frame.has_no_damage); 1205 DCHECK(!frame.has_no_damage);
1208 SetSwapUsedIncompleteTileOnImplThread(frame.contains_incomplete_tile); 1206 SetSwapUsedIncompleteTileOnImplThread(frame.contains_incomplete_tile);
1209 } 1207 }
1210 } 1208 }
1211 1209
1212 // Tell the main thread that the the newly-commited frame was drawn. 1210 // Tell the main thread that the the newly-commited frame was drawn.
1213 if (impl().next_frame_is_newly_committed_frame) { 1211 if (impl().next_frame_is_newly_committed_frame) {
1214 impl().next_frame_is_newly_committed_frame = false; 1212 impl().next_frame_is_newly_committed_frame = false;
1215 Proxy::MainThreadTaskRunner()->PostTask( 1213 Proxy::MainThreadTaskRunner()->PostTask(
1216 FROM_HERE, 1214 FROM_HERE,
1217 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); 1215 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_));
1218 } 1216 }
1219 1217
1220 if (draw_frame) 1218 if (draw_frame)
1221 CheckOutputSurfaceStatusOnImplThread(); 1219 CheckOutputSurfaceStatusOnImplThread();
1222 1220
1223 if (result.draw_result == DrawSwapReadbackResult::DRAW_SUCCESS) { 1221 if (result == DRAW_SUCCESS) {
1224 base::TimeDelta draw_duration = impl().timing_history.DidFinishDrawing(); 1222 base::TimeDelta draw_duration = impl().timing_history.DidFinishDrawing();
1225 1223
1226 base::TimeDelta draw_duration_overestimate; 1224 base::TimeDelta draw_duration_overestimate;
1227 base::TimeDelta draw_duration_underestimate; 1225 base::TimeDelta draw_duration_underestimate;
1228 if (draw_duration > draw_duration_estimate) 1226 if (draw_duration > draw_duration_estimate)
1229 draw_duration_underestimate = draw_duration - draw_duration_estimate; 1227 draw_duration_underestimate = draw_duration - draw_duration_estimate;
1230 else 1228 else
1231 draw_duration_overestimate = draw_duration_estimate - draw_duration; 1229 draw_duration_overestimate = draw_duration_estimate - draw_duration;
1232 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", 1230 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration",
1233 draw_duration, 1231 draw_duration,
1234 base::TimeDelta::FromMilliseconds(1), 1232 base::TimeDelta::FromMilliseconds(1),
1235 base::TimeDelta::FromMilliseconds(100), 1233 base::TimeDelta::FromMilliseconds(100),
1236 50); 1234 50);
1237 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate", 1235 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate",
1238 draw_duration_underestimate, 1236 draw_duration_underestimate,
1239 base::TimeDelta::FromMilliseconds(1), 1237 base::TimeDelta::FromMilliseconds(1),
1240 base::TimeDelta::FromMilliseconds(100), 1238 base::TimeDelta::FromMilliseconds(100),
1241 50); 1239 50);
1242 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate", 1240 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate",
1243 draw_duration_overestimate, 1241 draw_duration_overestimate,
1244 base::TimeDelta::FromMilliseconds(1), 1242 base::TimeDelta::FromMilliseconds(1),
1245 base::TimeDelta::FromMilliseconds(100), 1243 base::TimeDelta::FromMilliseconds(100),
1246 50); 1244 50);
1247 } 1245 }
1248 1246
1249 DCHECK_NE(DrawSwapReadbackResult::INVALID_RESULT, result.draw_result); 1247 DCHECK_NE(INVALID_RESULT, result);
1250 return result; 1248 return result;
1251 } 1249 }
1252 1250
1253 void ThreadProxy::ScheduledActionManageTiles() { 1251 void ThreadProxy::ScheduledActionManageTiles() {
1254 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionManageTiles"); 1252 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionManageTiles");
1255 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting); 1253 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting);
1256 impl().layer_tree_host_impl->ManageTiles(); 1254 impl().layer_tree_host_impl->ManageTiles();
1257 } 1255 }
1258 1256
1259 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() { 1257 DrawResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
1260 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); 1258 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap");
1261 1259
1262 // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to 1260 // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to
1263 // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should 1261 // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should
1264 // never generate this call when it can't draw. 1262 // never generate this call when it can't draw.
1265 DCHECK(impl().layer_tree_host_impl->CanDraw()); 1263 DCHECK(impl().layer_tree_host_impl->CanDraw());
1266 1264
1267 bool forced_draw = false; 1265 bool forced_draw = false;
1268 bool swap_requested = true; 1266 bool swap_requested = true;
1269 bool readback_requested = false; 1267 bool readback_requested = false;
1270 return DrawSwapReadbackInternal( 1268 return DrawSwapReadbackInternal(
1271 forced_draw, swap_requested, readback_requested); 1269 forced_draw, swap_requested, readback_requested);
1272 } 1270 }
1273 1271
1274 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapForced() { 1272 DrawResult ThreadProxy::ScheduledActionDrawAndSwapForced() {
1275 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced"); 1273 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced");
1276 bool forced_draw = true; 1274 bool forced_draw = true;
1277 bool swap_requested = true; 1275 bool swap_requested = true;
1278 bool readback_requested = false; 1276 bool readback_requested = false;
1279 return DrawSwapReadbackInternal( 1277 return DrawSwapReadbackInternal(
1280 forced_draw, swap_requested, readback_requested); 1278 forced_draw, swap_requested, readback_requested);
1281 } 1279 }
1282 1280
1283 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndReadback() { 1281 DrawResult ThreadProxy::ScheduledActionDrawAndReadback() {
1284 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndReadback"); 1282 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndReadback");
1285 bool forced_draw = true; 1283 bool forced_draw = true;
1286 bool swap_requested = false; 1284 bool swap_requested = false;
1287 bool readback_requested = true; 1285 bool readback_requested = true;
1288 return DrawSwapReadbackInternal( 1286 return DrawSwapReadbackInternal(
1289 forced_draw, swap_requested, readback_requested); 1287 forced_draw, swap_requested, readback_requested);
1290 } 1288 }
1291 1289
1292 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { 1290 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) {
1293 if (impl().current_resource_update_controller) 1291 if (impl().current_resource_update_controller)
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 1642
1645 impl().timing_history.DidActivatePendingTree(); 1643 impl().timing_history.DidActivatePendingTree();
1646 } 1644 }
1647 1645
1648 void ThreadProxy::DidManageTiles() { 1646 void ThreadProxy::DidManageTiles() {
1649 DCHECK(IsImplThread()); 1647 DCHECK(IsImplThread());
1650 impl().scheduler->DidManageTiles(); 1648 impl().scheduler->DidManageTiles();
1651 } 1649 }
1652 1650
1653 } // namespace cc 1651 } // namespace cc
OLDNEW
« cc/scheduler/scheduler_state_machine.cc ('K') | « cc/trees/thread_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698