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

Side by Side Diff: sky/sdk/lib/rendering/object.dart

Issue 1235713002: Support getting baseline from paint as well as layout. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « sky/sdk/lib/rendering/box.dart ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 import 'dart:math' as math; 5 import 'dart:math' as math;
6 import 'dart:sky' as sky; 6 import 'dart:sky' as sky;
7 import 'dart:sky' show Point, Offset, Size, Rect, Color, Paint, Path; 7 import 'dart:sky' show Point, Offset, Size, Rect, Color, Paint, Path;
8 8
9 import '../base/debug.dart';
9 import '../base/hit_test.dart'; 10 import '../base/hit_test.dart';
10 import '../base/node.dart'; 11 import '../base/node.dart';
11 import '../base/scheduler.dart' as scheduler; 12 import '../base/scheduler.dart' as scheduler;
12 13
13 export 'dart:sky' show Point, Offset, Size, Rect, Color, Paint, Path; 14 export 'dart:sky' show Point, Offset, Size, Rect, Color, Paint, Path;
14 export '../base/hit_test.dart' show HitTestTarget, HitTestEntry, HitTestResult; 15 export '../base/hit_test.dart' show HitTestTarget, HitTestEntry, HitTestResult;
15 16
16 17
17 class ParentData { 18 class ParentData {
18 void detach() { 19 void detach() {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 performLayout(); 195 performLayout();
195 assert(() { 196 assert(() {
196 _debugActiveLayout = debugPreviousActiveLayout; 197 _debugActiveLayout = debugPreviousActiveLayout;
197 _debugDoingThisLayout = false; 198 _debugDoingThisLayout = false;
198 _debugCanParentUseSize = null; 199 _debugCanParentUseSize = null;
199 _debugMutationsLocked = false; 200 _debugMutationsLocked = false;
200 return true; 201 return true;
201 }); 202 });
202 } catch (e) { 203 } catch (e) {
203 print('Exception raised during layout:\n${e}\nContext:\n${this}'); 204 print('Exception raised during layout:\n${e}\nContext:\n${this}');
205 if (inDebugBuild)
206 rethrow;
204 return; 207 return;
205 } 208 }
206 _needsLayout = false; 209 _needsLayout = false;
207 markNeedsPaint(); 210 markNeedsPaint();
208 } 211 }
209 void layout(Constraints constraints, { bool parentUsesSize: false }) { 212 void layout(Constraints constraints, { bool parentUsesSize: false }) {
210 final parent = this.parent; // TODO(ianh): Remove this once the analyzer is cleverer 213 final parent = this.parent; // TODO(ianh): Remove this once the analyzer is cleverer
211 RenderObject relayoutSubtreeRoot; 214 RenderObject relayoutSubtreeRoot;
212 if (!parentUsesSize || sizedByParent || constraints.isTight || parent is! Re nderObject) 215 if (!parentUsesSize || sizedByParent || constraints.isTight || parent is! Re nderObject)
213 relayoutSubtreeRoot = this; 216 relayoutSubtreeRoot = this;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 294
292 void rotate({ 295 void rotate({
293 int oldAngle, // 0..3 296 int oldAngle, // 0..3
294 int newAngle, // 0..3 297 int newAngle, // 0..3
295 Duration time 298 Duration time
296 }) { } 299 }) { }
297 300
298 301
299 // PAINTING 302 // PAINTING
300 303
301 static List<RenderObject> _nodesNeedingPaint = new List<RenderObject>();
302 static bool _debugDoingPaint = false; 304 static bool _debugDoingPaint = false;
303 static bool get debugDoingPaint => _debugDoingPaint; 305 static bool get debugDoingPaint => _debugDoingPaint;
304 static void set debugDoingPaint(bool debug) { 306 bool _debugDoingThisPaint = false;
305 _debugDoingPaint = debug; 307 bool get debugDoingThisPaint => _debugDoingThisPaint;
306 } 308 static RenderObject _debugActivePaint = null;
309 static RenderObject get debugActivePaint => _debugActivePaint;
310
311 static List<RenderObject> _nodesNeedingPaint = new List<RenderObject>();
307 312
308 final sky.PaintingNode _paintingNode = new sky.PaintingNode(); 313 final sky.PaintingNode _paintingNode = new sky.PaintingNode();
309 sky.PaintingNode get paintingNode { 314 sky.PaintingNode get paintingNode {
310 assert(createNewDisplayList); 315 assert(createNewDisplayList);
311 return _paintingNode; 316 return _paintingNode;
312 } 317 }
313 bool _needsPaint = true; 318 bool _needsPaint = true;
314 bool get needsPaint => _needsPaint; 319 bool get needsPaint => _needsPaint;
315 bool get createNewDisplayList => false;
316 320
317 void markNeedsPaint() { 321 void markNeedsPaint() {
318 assert(!debugDoingPaint); 322 assert(!debugDoingPaint);
319 if (!attached) return; // Don't try painting things that aren't in the hiera rchy 323 if (!attached) return; // Don't try painting things that aren't in the hiera rchy
320 if (_needsPaint) return; 324 if (_needsPaint) return;
321 if (createNewDisplayList) { 325 if (createNewDisplayList) {
322 _needsPaint = true; 326 _needsPaint = true;
323 _nodesNeedingPaint.add(this); 327 _nodesNeedingPaint.add(this);
324 scheduler.ensureVisualUpdate(); 328 scheduler.ensureVisualUpdate();
325 } else { 329 } else {
326 assert(parent != null); // parent always exists on this path because the r oot node is a RenderView, which sets createNewDisplayList. 330 assert(parent != null); // parent always exists on this path because the r oot node is a RenderView, which sets createNewDisplayList.
327 if (parent is RenderObject) { 331 if (parent is RenderObject) {
328 (parent as RenderObject).markNeedsPaint(); // TODO(ianh): remove the cas t once the analyzer is cleverer 332 (parent as RenderObject).markNeedsPaint(); // TODO(ianh): remove the cas t once the analyzer is cleverer
329 } 333 }
330 } 334 }
331 } 335 }
332 336
333 static void flushPaint() { 337 static void flushPaint() {
334 try { 338 try {
335 _debugDoingPaint = true; 339 _debugDoingPaint = true;
336 List<RenderObject> dirtyNodes = _nodesNeedingPaint; 340 List<RenderObject> dirtyNodes = _nodesNeedingPaint;
337 _nodesNeedingPaint = new List<RenderObject>(); 341 _nodesNeedingPaint = new List<RenderObject>();
338 for (RenderObject node in dirtyNodes..sort((a, b) => a.depth - b.depth)) { 342 for (RenderObject node in dirtyNodes..sort((a, b) => a.depth - b.depth)) {
339 if (node._needsPaint && node.attached) 343 if (node._needsPaint && node.attached)
340 node._updatePaintingCanvas(); 344 node._updatePaintingCanvas();
341 }; 345 };
342 assert(_nodesNeedingPaint.length == 0); 346 assert(_nodesNeedingPaint.length == 0);
343 } catch (e) {
344 print('Exception raised during flushPaint:\n${e}');
345 } finally { 347 } finally {
346 _debugDoingPaint = false; 348 _debugDoingPaint = false;
347 } 349 }
348 } 350 }
349 351
350 void _updatePaintingCanvas() { 352 void _updatePaintingCanvas() {
351 assert(!_needsLayout); 353 assert(!_needsLayout);
352 assert(createNewDisplayList); 354 assert(createNewDisplayList);
353 sky.PictureRecorder recorder = new sky.PictureRecorder(); 355 sky.PictureRecorder recorder = new sky.PictureRecorder();
354 PaintingCanvas canvas = new PaintingCanvas(recorder, paintBounds); 356 PaintingCanvas canvas = new PaintingCanvas(recorder, paintBounds);
355 _needsPaint = false; 357 _needsPaint = false;
356 try { 358 try {
357 _paintOnCanvas(canvas, Offset.zero); 359 _paintOnCanvas(canvas, Offset.zero);
358 } catch (e) { 360 } catch (e) {
359 print('Exception raised during _updatePaintingCanvas:\n${e}\nContext:\n${t his}'); 361 print('Exception raised during _updatePaintingCanvas:\n${e}\nContext:\n${t his}');
362 if (inDebugBuild)
363 rethrow;
360 return; 364 return;
361 } 365 }
362 assert(!_needsLayout); // check that the paint() method didn't mark us dirty again 366 assert(!_needsLayout); // check that the paint() method didn't mark us dirty again
363 assert(!_needsPaint); // check that the paint() method didn't mark us dirty again 367 assert(!_needsPaint); // check that the paint() method didn't mark us dirty again
364 _paintingNode.setBackingDrawable(recorder.endRecordingAsDrawable()); 368 _paintingNode.setBackingDrawable(recorder.endRecordingAsDrawable());
365 369
366 if (canvas._descendentsWithPaintingCanvases != null) { 370 if (canvas._descendentsWithPaintingCanvases != null) {
367 for (RenderObject node in canvas._descendentsWithPaintingCanvases) { 371 for (RenderObject node in canvas._descendentsWithPaintingCanvases) {
368 assert(node.attached == attached); 372 assert(node.attached == attached);
369 if (node._needsPaint) 373 if (node._needsPaint)
370 node._updatePaintingCanvas(); 374 node._updatePaintingCanvas();
371 }; 375 };
372 } 376 }
373 } 377 }
374 378
375 void _paintOnCanvas(PaintingCanvas canvas, Offset offset) { 379 void _paintOnCanvas(PaintingCanvas canvas, Offset offset) {
376 _needsPaint = false; 380 _needsPaint = false;
381 assert(!_debugDoingThisPaint);
382 RenderObject debugLastActivePaint;
383 assert(() {
384 _debugDoingThisPaint = true;
385 debugLastActivePaint = _debugActivePaint;
386 _debugActivePaint = this;
387 return true;
388 });
377 paint(canvas, offset); 389 paint(canvas, offset);
390 assert(() {
391 _debugActivePaint = debugLastActivePaint;
392 _debugDoingThisPaint = false;
393 return true;
394 });
378 assert(!_needsPaint); 395 assert(!_needsPaint);
379 } 396 }
380 397
398 bool get createNewDisplayList => false;
381 Rect get paintBounds; 399 Rect get paintBounds;
382
383 void paint(PaintingCanvas canvas, Offset offset) { } 400 void paint(PaintingCanvas canvas, Offset offset) { }
384 401
385 402
386 // EVENTS 403 // EVENTS
387 404
388 void handleEvent(sky.Event event, HitTestEntry entry) { 405 void handleEvent(sky.Event event, HitTestEntry entry) {
389 // override this if you have a client, to hand it to the client 406 // override this if you have a client, to hand it to the client
390 // override this if you want to do anything with the event 407 // override this if you want to do anything with the event
391 } 408 }
392 409
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 int count = 1; 697 int count = 1;
681 ChildType child = _firstChild; 698 ChildType child = _firstChild;
682 while (child != null) { 699 while (child != null) {
683 result += '${prefix}child ${count}: ${child.toString(prefix)}'; 700 result += '${prefix}child ${count}: ${child.toString(prefix)}';
684 count += 1; 701 count += 1;
685 child = child.parentData.nextSibling; 702 child = child.parentData.nextSibling;
686 } 703 }
687 return result; 704 return result;
688 } 705 }
689 } 706 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/rendering/box.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698