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

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: Rebased 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
« no previous file with comments | « cc/trees/thread_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 1108
1109 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() { 1109 void ThreadProxy::ScheduledActionBeginOutputSurfaceCreation() {
1110 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation"); 1110 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionBeginOutputSurfaceCreation");
1111 DCHECK(IsImplThread()); 1111 DCHECK(IsImplThread());
1112 Proxy::MainThreadTaskRunner()->PostTask( 1112 Proxy::MainThreadTaskRunner()->PostTask(
1113 FROM_HERE, 1113 FROM_HERE,
1114 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface, 1114 base::Bind(&ThreadProxy::CreateAndInitializeOutputSurface,
1115 main_thread_weak_ptr_)); 1115 main_thread_weak_ptr_));
1116 } 1116 }
1117 1117
1118 DrawSwapReadbackResult ThreadProxy::DrawSwapReadbackInternal( 1118 DrawResult ThreadProxy::DrawSwapReadbackInternal(
1119 bool forced_draw, 1119 bool forced_draw,
1120 bool swap_requested, 1120 bool swap_requested,
1121 bool readback_requested) { 1121 bool readback_requested) {
1122 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap"); 1122 TRACE_EVENT_SYNTHETIC_DELAY("cc.DrawAndSwap");
1123 DrawSwapReadbackResult result; 1123 DrawResult result;
1124 1124
1125 DCHECK(IsImplThread()); 1125 DCHECK(IsImplThread());
1126 DCHECK(impl().layer_tree_host_impl.get()); 1126 DCHECK(impl().layer_tree_host_impl.get());
1127 1127
1128 impl().timing_history.DidStartDrawing(); 1128 impl().timing_history.DidStartDrawing();
1129 base::TimeDelta draw_duration_estimate = DrawDurationEstimate(); 1129 base::TimeDelta draw_duration_estimate = DrawDurationEstimate();
1130 base::AutoReset<bool> mark_inside(&impl().inside_draw, true); 1130 base::AutoReset<bool> mark_inside(&impl().inside_draw, true);
1131 1131
1132 if (impl().did_commit_after_animating) { 1132 if (impl().did_commit_after_animating) {
1133 impl().layer_tree_host_impl->Animate(impl().animation_time); 1133 impl().layer_tree_host_impl->Animate(impl().animation_time);
(...skipping 21 matching lines...) Expand all
1155 LayerTreeHostImpl::FrameData frame; 1155 LayerTreeHostImpl::FrameData frame;
1156 bool draw_frame = false; 1156 bool draw_frame = false;
1157 1157
1158 if (impl().layer_tree_host_impl->CanDraw()) { 1158 if (impl().layer_tree_host_impl->CanDraw()) {
1159 if (!drawing_for_readback || can_do_readback) { 1159 if (!drawing_for_readback || can_do_readback) {
1160 // If it is for a readback, make sure we draw the portion being read back. 1160 // If it is for a readback, make sure we draw the portion being read back.
1161 gfx::Rect readback_rect; 1161 gfx::Rect readback_rect;
1162 if (drawing_for_readback) 1162 if (drawing_for_readback)
1163 readback_rect = impl().readback_request->rect; 1163 readback_rect = impl().readback_request->rect;
1164 1164
1165 result.draw_result = 1165 result =
1166 impl().layer_tree_host_impl->PrepareToDraw(&frame, readback_rect); 1166 impl().layer_tree_host_impl->PrepareToDraw(&frame, readback_rect);
1167 draw_frame = forced_draw || 1167 draw_frame = forced_draw || result == DRAW_SUCCESS;
1168 result.draw_result == DrawSwapReadbackResult::DRAW_SUCCESS;
1169 } else { 1168 } else {
1170 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CANT_READBACK; 1169 result = DRAW_ABORTED_CANT_READBACK;
1171 } 1170 }
1172 } else { 1171 } else {
1173 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CANT_DRAW; 1172 result = DRAW_ABORTED_CANT_DRAW;
1174 } 1173 }
1175 1174
1176 if (draw_frame) { 1175 if (draw_frame) {
1177 impl().layer_tree_host_impl->DrawLayers( 1176 impl().layer_tree_host_impl->DrawLayers(
1178 &frame, impl().scheduler->LastBeginImplFrameTime()); 1177 &frame, impl().scheduler->LastBeginImplFrameTime());
1179 result.draw_result = DrawSwapReadbackResult::DRAW_SUCCESS; 1178 result = DRAW_SUCCESS;
1180 impl().animations_frozen_until_next_draw = false; 1179 impl().animations_frozen_until_next_draw = false;
1181 } else if (result.draw_result == 1180 } else if (result == DRAW_ABORTED_CHECKERBOARD_ANIMATIONS &&
1182 DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS &&
1183 !impl().layer_tree_host_impl->settings().impl_side_painting) { 1181 !impl().layer_tree_host_impl->settings().impl_side_painting) {
1184 // Without impl-side painting, the animated layer that is checkerboarding 1182 // Without impl-side painting, the animated layer that is checkerboarding
1185 // will continue to checkerboard until the next commit. If this layer 1183 // will continue to checkerboard until the next commit. If this layer
1186 // continues to move during the commit, it may continue to checkerboard 1184 // continues to move during the commit, it may continue to checkerboard
1187 // after the commit since the region rasterized during the commit will not 1185 // after the commit since the region rasterized during the commit will not
1188 // match the region that is currently visible; eventually this 1186 // match the region that is currently visible; eventually this
1189 // checkerboarding will be displayed when we force a draw. To avoid this, 1187 // checkerboarding will be displayed when we force a draw. To avoid this,
1190 // we freeze animations until we successfully draw. 1188 // we freeze animations until we successfully draw.
1191 impl().animations_frozen_until_next_draw = true; 1189 impl().animations_frozen_until_next_draw = true;
1192 } else { 1190 } else {
1193 DCHECK_NE(DrawSwapReadbackResult::DRAW_SUCCESS, result.draw_result); 1191 DCHECK_NE(DRAW_SUCCESS, result);
1194 } 1192 }
1195 impl().layer_tree_host_impl->DidDrawAllLayers(frame); 1193 impl().layer_tree_host_impl->DidDrawAllLayers(frame);
1196 1194
1197 bool start_ready_animations = draw_frame; 1195 bool start_ready_animations = draw_frame;
1198 impl().layer_tree_host_impl->UpdateAnimationState(start_ready_animations); 1196 impl().layer_tree_host_impl->UpdateAnimationState(start_ready_animations);
1199 1197
1200 // Check for a pending CompositeAndReadback. 1198 // Check for a pending CompositeAndReadback.
1201 if (drawing_for_readback) { 1199 if (drawing_for_readback) {
1202 DCHECK(!swap_requested); 1200 DCHECK(!swap_requested);
1203 result.did_readback = false; 1201 bool did_readback = false;
1204 if (draw_frame) { 1202 if (draw_frame) {
1205 if (!impl().layer_tree_host_impl->IsContextLost()) { 1203 if (!impl().layer_tree_host_impl->IsContextLost()) {
1206 impl().layer_tree_host_impl->Readback(impl().readback_request->pixels, 1204 impl().layer_tree_host_impl->Readback(impl().readback_request->pixels,
1207 impl().readback_request->rect); 1205 impl().readback_request->rect);
1208 result.did_readback = true; 1206 did_readback = true;
1209 } else { 1207 } else {
1210 result.draw_result = DrawSwapReadbackResult::DRAW_ABORTED_CONTEXT_LOST; 1208 result = DRAW_ABORTED_CONTEXT_LOST;
1211 } 1209 }
1212 } 1210 }
1213 impl().readback_request->success = result.did_readback; 1211 impl().readback_request->success = did_readback;
1214 impl().readback_request->completion.Signal(); 1212 impl().readback_request->completion.Signal();
1215 impl().readback_request = NULL; 1213 impl().readback_request = NULL;
1216 } else if (draw_frame) { 1214 } else if (draw_frame) {
1217 DCHECK(swap_requested); 1215 DCHECK(swap_requested);
1218 result.did_request_swap = impl().layer_tree_host_impl->SwapBuffers(frame); 1216 bool did_request_swap = impl().layer_tree_host_impl->SwapBuffers(frame);
1219 1217
1220 // We don't know if we have incomplete tiles if we didn't actually swap. 1218 // We don't know if we have incomplete tiles if we didn't actually swap.
1221 if (result.did_request_swap) { 1219 if (did_request_swap) {
1222 DCHECK(!frame.has_no_damage); 1220 DCHECK(!frame.has_no_damage);
1223 SetSwapUsedIncompleteTileOnImplThread(frame.contains_incomplete_tile); 1221 SetSwapUsedIncompleteTileOnImplThread(frame.contains_incomplete_tile);
1224 } 1222 }
1225 } 1223 }
1226 1224
1227 // Tell the main thread that the the newly-commited frame was drawn. 1225 // Tell the main thread that the the newly-commited frame was drawn.
1228 if (impl().next_frame_is_newly_committed_frame) { 1226 if (impl().next_frame_is_newly_committed_frame) {
1229 impl().next_frame_is_newly_committed_frame = false; 1227 impl().next_frame_is_newly_committed_frame = false;
1230 Proxy::MainThreadTaskRunner()->PostTask( 1228 Proxy::MainThreadTaskRunner()->PostTask(
1231 FROM_HERE, 1229 FROM_HERE,
1232 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_)); 1230 base::Bind(&ThreadProxy::DidCommitAndDrawFrame, main_thread_weak_ptr_));
1233 } 1231 }
1234 1232
1235 if (draw_frame) 1233 if (draw_frame)
1236 CheckOutputSurfaceStatusOnImplThread(); 1234 CheckOutputSurfaceStatusOnImplThread();
1237 1235
1238 if (result.draw_result == DrawSwapReadbackResult::DRAW_SUCCESS) { 1236 if (result == DRAW_SUCCESS) {
1239 base::TimeDelta draw_duration = impl().timing_history.DidFinishDrawing(); 1237 base::TimeDelta draw_duration = impl().timing_history.DidFinishDrawing();
1240 1238
1241 base::TimeDelta draw_duration_overestimate; 1239 base::TimeDelta draw_duration_overestimate;
1242 base::TimeDelta draw_duration_underestimate; 1240 base::TimeDelta draw_duration_underestimate;
1243 if (draw_duration > draw_duration_estimate) 1241 if (draw_duration > draw_duration_estimate)
1244 draw_duration_underestimate = draw_duration - draw_duration_estimate; 1242 draw_duration_underestimate = draw_duration - draw_duration_estimate;
1245 else 1243 else
1246 draw_duration_overestimate = draw_duration_estimate - draw_duration; 1244 draw_duration_overestimate = draw_duration_estimate - draw_duration;
1247 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration", 1245 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDuration",
1248 draw_duration, 1246 draw_duration,
1249 base::TimeDelta::FromMilliseconds(1), 1247 base::TimeDelta::FromMilliseconds(1),
1250 base::TimeDelta::FromMilliseconds(100), 1248 base::TimeDelta::FromMilliseconds(100),
1251 50); 1249 50);
1252 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate", 1250 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationUnderestimate",
1253 draw_duration_underestimate, 1251 draw_duration_underestimate,
1254 base::TimeDelta::FromMilliseconds(1), 1252 base::TimeDelta::FromMilliseconds(1),
1255 base::TimeDelta::FromMilliseconds(100), 1253 base::TimeDelta::FromMilliseconds(100),
1256 50); 1254 50);
1257 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate", 1255 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer.DrawDurationOverestimate",
1258 draw_duration_overestimate, 1256 draw_duration_overestimate,
1259 base::TimeDelta::FromMilliseconds(1), 1257 base::TimeDelta::FromMilliseconds(1),
1260 base::TimeDelta::FromMilliseconds(100), 1258 base::TimeDelta::FromMilliseconds(100),
1261 50); 1259 50);
1262 } 1260 }
1263 1261
1264 DCHECK_NE(DrawSwapReadbackResult::INVALID_RESULT, result.draw_result); 1262 DCHECK_NE(INVALID_RESULT, result);
1265 return result; 1263 return result;
1266 } 1264 }
1267 1265
1268 void ThreadProxy::ScheduledActionManageTiles() { 1266 void ThreadProxy::ScheduledActionManageTiles() {
1269 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionManageTiles"); 1267 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionManageTiles");
1270 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting); 1268 DCHECK(impl().layer_tree_host_impl->settings().impl_side_painting);
1271 impl().layer_tree_host_impl->ManageTiles(); 1269 impl().layer_tree_host_impl->ManageTiles();
1272 } 1270 }
1273 1271
1274 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() { 1272 DrawResult ThreadProxy::ScheduledActionDrawAndSwapIfPossible() {
1275 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap"); 1273 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwap");
1276 1274
1277 // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to 1275 // SchedulerStateMachine::DidDrawIfPossibleCompleted isn't set up to
1278 // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should 1276 // handle DRAW_ABORTED_CANT_DRAW. Moreover, the scheduler should
1279 // never generate this call when it can't draw. 1277 // never generate this call when it can't draw.
1280 DCHECK(impl().layer_tree_host_impl->CanDraw()); 1278 DCHECK(impl().layer_tree_host_impl->CanDraw());
1281 1279
1282 bool forced_draw = false; 1280 bool forced_draw = false;
1283 bool swap_requested = true; 1281 bool swap_requested = true;
1284 bool readback_requested = false; 1282 bool readback_requested = false;
1285 return DrawSwapReadbackInternal( 1283 return DrawSwapReadbackInternal(
1286 forced_draw, swap_requested, readback_requested); 1284 forced_draw, swap_requested, readback_requested);
1287 } 1285 }
1288 1286
1289 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndSwapForced() { 1287 DrawResult ThreadProxy::ScheduledActionDrawAndSwapForced() {
1290 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced"); 1288 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndSwapForced");
1291 bool forced_draw = true; 1289 bool forced_draw = true;
1292 bool swap_requested = true; 1290 bool swap_requested = true;
1293 bool readback_requested = false; 1291 bool readback_requested = false;
1294 return DrawSwapReadbackInternal( 1292 return DrawSwapReadbackInternal(
1295 forced_draw, swap_requested, readback_requested); 1293 forced_draw, swap_requested, readback_requested);
1296 } 1294 }
1297 1295
1298 DrawSwapReadbackResult ThreadProxy::ScheduledActionDrawAndReadback() { 1296 DrawResult ThreadProxy::ScheduledActionDrawAndReadback() {
1299 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndReadback"); 1297 TRACE_EVENT0("cc", "ThreadProxy::ScheduledActionDrawAndReadback");
1300 bool forced_draw = true; 1298 bool forced_draw = true;
1301 bool swap_requested = false; 1299 bool swap_requested = false;
1302 bool readback_requested = true; 1300 bool readback_requested = true;
1303 return DrawSwapReadbackInternal( 1301 return DrawSwapReadbackInternal(
1304 forced_draw, swap_requested, readback_requested); 1302 forced_draw, swap_requested, readback_requested);
1305 } 1303 }
1306 1304
1307 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) { 1305 void ThreadProxy::DidAnticipatedDrawTimeChange(base::TimeTicks time) {
1308 if (impl().current_resource_update_controller) 1306 if (impl().current_resource_update_controller)
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 1651
1654 impl().timing_history.DidActivatePendingTree(); 1652 impl().timing_history.DidActivatePendingTree();
1655 } 1653 }
1656 1654
1657 void ThreadProxy::DidManageTiles() { 1655 void ThreadProxy::DidManageTiles() {
1658 DCHECK(IsImplThread()); 1656 DCHECK(IsImplThread());
1659 impl().scheduler->DidManageTiles(); 1657 impl().scheduler->DidManageTiles();
1660 } 1658 }
1661 1659
1662 } // namespace cc 1660 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/thread_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698