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

Side by Side Diff: Source/platform/graphics/GraphicsContext.cpp

Issue 536573002: Modifications to DisplayList for better Slimming Paint (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Return DisplayList from endRecording Created 6 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 26 matching lines...) Expand all
37 #include "platform/graphics/skia/SkiaUtils.h" 37 #include "platform/graphics/skia/SkiaUtils.h"
38 #include "platform/text/BidiResolver.h" 38 #include "platform/text/BidiResolver.h"
39 #include "platform/text/TextRunIterator.h" 39 #include "platform/text/TextRunIterator.h"
40 #include "platform/weborigin/KURL.h" 40 #include "platform/weborigin/KURL.h"
41 #include "third_party/skia/include/core/SkAnnotation.h" 41 #include "third_party/skia/include/core/SkAnnotation.h"
42 #include "third_party/skia/include/core/SkClipStack.h" 42 #include "third_party/skia/include/core/SkClipStack.h"
43 #include "third_party/skia/include/core/SkColorFilter.h" 43 #include "third_party/skia/include/core/SkColorFilter.h"
44 #include "third_party/skia/include/core/SkData.h" 44 #include "third_party/skia/include/core/SkData.h"
45 #include "third_party/skia/include/core/SkDevice.h" 45 #include "third_party/skia/include/core/SkDevice.h"
46 #include "third_party/skia/include/core/SkPicture.h" 46 #include "third_party/skia/include/core/SkPicture.h"
47 #include "third_party/skia/include/core/SkPictureRecorder.h"
47 #include "third_party/skia/include/core/SkRRect.h" 48 #include "third_party/skia/include/core/SkRRect.h"
48 #include "third_party/skia/include/core/SkRefCnt.h" 49 #include "third_party/skia/include/core/SkRefCnt.h"
49 #include "third_party/skia/include/core/SkSurface.h" 50 #include "third_party/skia/include/core/SkSurface.h"
50 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" 51 #include "third_party/skia/include/effects/SkBlurMaskFilter.h"
51 #include "third_party/skia/include/effects/SkCornerPathEffect.h" 52 #include "third_party/skia/include/effects/SkCornerPathEffect.h"
52 #include "third_party/skia/include/effects/SkLumaColorFilter.h" 53 #include "third_party/skia/include/effects/SkLumaColorFilter.h"
53 #include "third_party/skia/include/effects/SkMatrixImageFilter.h" 54 #include "third_party/skia/include/effects/SkMatrixImageFilter.h"
54 #include "third_party/skia/include/effects/SkPictureImageFilter.h" 55 #include "third_party/skia/include/effects/SkPictureImageFilter.h"
55 #include "third_party/skia/include/gpu/GrRenderTarget.h" 56 #include "third_party/skia/include/gpu/GrRenderTarget.h"
56 #include "third_party/skia/include/gpu/GrTexture.h" 57 #include "third_party/skia/include/gpu/GrTexture.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 93
93 struct GraphicsContext::CanvasSaveState { 94 struct GraphicsContext::CanvasSaveState {
94 CanvasSaveState(bool pendingSave, int count) 95 CanvasSaveState(bool pendingSave, int count)
95 : m_pendingSave(pendingSave), m_restoreCount(count) { } 96 : m_pendingSave(pendingSave), m_restoreCount(count) { }
96 97
97 bool m_pendingSave; 98 bool m_pendingSave;
98 int m_restoreCount; 99 int m_restoreCount;
99 }; 100 };
100 101
101 struct GraphicsContext::RecordingState { 102 struct GraphicsContext::RecordingState {
102 RecordingState(SkCanvas* currentCanvas, const SkMatrix& currentMatrix, PassR efPtr<DisplayList> displayList) 103 RecordingState(SkPictureRecorder* recorder, SkCanvas* currentCanvas, const S kMatrix& currentMatrix, PassRefPtr<DisplayList> displayList)
103 : m_savedCanvas(currentCanvas) 104 : m_displayList(displayList)
104 , m_displayList(displayList) 105 , m_recorder(recorder)
105 , m_savedMatrix(currentMatrix) 106 , m_savedCanvas(currentCanvas)
106 { 107 , m_savedMatrix(currentMatrix) { }
107 }
108 108
109 ~RecordingState() { }
110
111 RefPtr<DisplayList> m_displayList;
112 SkPictureRecorder* m_recorder;
109 SkCanvas* m_savedCanvas; 113 SkCanvas* m_savedCanvas;
110 RefPtr<DisplayList> m_displayList;
111 const SkMatrix m_savedMatrix; 114 const SkMatrix m_savedMatrix;
112 }; 115 };
113 116
114 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisabledMode disableContextOr Painting) 117 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisabledMode disableContextOr Painting)
115 : m_canvas(canvas) 118 : m_canvas(canvas)
116 , m_paintStateStack() 119 , m_paintStateStack()
117 , m_paintStateIndex(0) 120 , m_paintStateIndex(0)
118 , m_pendingCanvasSave(false) 121 , m_pendingCanvasSave(false)
119 , m_annotationMode(0) 122 , m_annotationMode(0)
120 #if ENABLE(ASSERT) 123 #if ENABLE(ASSERT)
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 return; 488 return;
486 489
487 restoreLayer(); 490 restoreLayer();
488 491
489 ASSERT(m_layerCount > 0); 492 ASSERT(m_layerCount > 0);
490 #if ENABLE(ASSERT) 493 #if ENABLE(ASSERT)
491 --m_layerCount; 494 --m_layerCount;
492 #endif 495 #endif
493 } 496 }
494 497
495 void GraphicsContext::beginRecording(const FloatRect& bounds) 498 void GraphicsContext::beginRecording(const FloatRect& bounds, uint32_t recordFla gs)
496 { 499 {
497 RefPtr<DisplayList> displayList = adoptRef(new DisplayList(bounds)); 500 RefPtr<DisplayList> displayList = DisplayList::create(bounds);
501
502 SkPictureRecorder* recorder = 0;
498 503
499 SkCanvas* savedCanvas = m_canvas; 504 SkCanvas* savedCanvas = m_canvas;
500 SkMatrix savedMatrix = getTotalMatrix(); 505 SkMatrix savedMatrix = getTotalMatrix();
501 506
502 if (!contextDisabled()) { 507 if (!contextDisabled()) {
503 IntRect recordingRect = enclosingIntRect(bounds); 508 FloatRect bounds = displayList->bounds();
504 m_canvas = displayList->beginRecording(recordingRect.size()); 509 IntSize recordingSize = enclosingIntRect(bounds).size();
510 recorder = new SkPictureRecorder;
511 m_canvas = recorder->beginRecording(recordingSize.width(), recordingSize .height(), 0, recordFlags);
505 512
506 // We want the bounds offset mapped to (0, 0), such that the display lis t content 513 // We want the bounds offset mapped to (0, 0), such that the display lis t content
507 // is fully contained within the SkPictureRecord's bounds. 514 // is fully contained within the SkPictureRecord's bounds.
508 if (!toFloatSize(bounds.location()).isZero()) { 515 if (!toFloatSize(bounds.location()).isZero()) {
509 m_canvas->translate(-bounds.x(), -bounds.y()); 516 m_canvas->translate(-bounds.x(), -bounds.y());
510 // To avoid applying the offset repeatedly in getTotalMatrix(), we p re-apply it here. 517 // To avoid applying the offset repeatedly in getTotalMatrix(), we p re-apply it here.
511 savedMatrix.preTranslate(bounds.x(), bounds.y()); 518 savedMatrix.preTranslate(bounds.x(), bounds.y());
512 } 519 }
513 } 520 }
514 521
515 m_recordingStateStack.append(RecordingState(savedCanvas, savedMatrix, displa yList)); 522 m_recordingStateStack.append(RecordingState(recorder, savedCanvas, savedMatr ix, displayList));
516 } 523 }
517 524
518 PassRefPtr<DisplayList> GraphicsContext::endRecording() 525 PassRefPtr<DisplayList> GraphicsContext::endRecording()
519 { 526 {
520 ASSERT(!m_recordingStateStack.isEmpty()); 527 ASSERT(!m_recordingStateStack.isEmpty());
521 528
522 RecordingState recording = m_recordingStateStack.last(); 529 RecordingState recording = m_recordingStateStack.last();
523 if (!contextDisabled()) { 530 if (!contextDisabled())
524 ASSERT(recording.m_displayList->isRecording()); 531 recording.m_displayList->setPicture(recording.m_recorder->endRecording() );
chrishtr 2014/09/05 18:28:13 Why not create m_displayList here?
chrishtr 2014/09/05 18:28:51 Sorry, that is a stale comment.
525 recording.m_displayList->endRecording();
526 }
527 532
533 m_canvas = recording.m_savedCanvas;
534 delete recording.m_recorder;
chrishtr 2014/09/05 18:28:13 Put m_recorder in an OwnPtr in the recording state
Stephen Chennney 2014/09/05 18:36:19 Tried that. SkPictureRecorder is a Skia type that
528 m_recordingStateStack.removeLast(); 535 m_recordingStateStack.removeLast();
529 m_canvas = recording.m_savedCanvas;
530 536
531 return recording.m_displayList.release(); 537 return recording.m_displayList;
532 } 538 }
533 539
534 bool GraphicsContext::isRecording() const 540 bool GraphicsContext::isRecording() const
535 { 541 {
536 return !m_recordingStateStack.isEmpty(); 542 return !m_recordingStateStack.isEmpty();
537 } 543 }
538 544
539 void GraphicsContext::drawDisplayList(DisplayList* displayList) 545 void GraphicsContext::drawDisplayList(DisplayList* displayList)
540 { 546 {
541 ASSERT(displayList); 547 ASSERT(displayList);
542 ASSERT(!displayList->isRecording());
543 548
544 if (contextDisabled() || displayList->bounds().isEmpty()) 549 if (contextDisabled() || displayList->bounds().isEmpty())
545 return; 550 return;
546 551
552 bool performClip = !displayList->clip().isEmpty();
553 bool performTransform = !displayList->transform().isIdentity();
554 if (performClip || performTransform) {
555 save();
556 if (performTransform)
557 concat(displayList->transform());
558 if (performClip)
559 clipRect(displayList->clip());
560 }
561
547 realizeCanvasSave(); 562 realizeCanvasSave();
548 563
549 const FloatRect& bounds = displayList->bounds(); 564 const FloatPoint& location = displayList->bounds().location();
550 if (bounds.x() || bounds.y()) { 565 if (location.x() || location.y()) {
551 SkMatrix m; 566 SkMatrix m;
552 m.setTranslate(bounds.x(), bounds.y()); 567 m.setTranslate(location.x(), location.y());
553 m_canvas->drawPicture(displayList->picture(), &m, 0); 568 m_canvas->drawPicture(displayList->picture(), &m, 0);
554 } else { 569 } else {
555 m_canvas->drawPicture(displayList->picture()); 570 m_canvas->drawPicture(displayList->picture());
556 } 571 }
572
573 if (performClip || performTransform)
574 restore();
557 } 575 }
558 576
559 void GraphicsContext::drawConvexPolygon(size_t numPoints, const FloatPoint* poin ts, bool shouldAntialias) 577 void GraphicsContext::drawConvexPolygon(size_t numPoints, const FloatPoint* poin ts, bool shouldAntialias)
560 { 578 {
561 if (contextDisabled()) 579 if (contextDisabled())
562 return; 580 return;
563 581
564 if (numPoints <= 1) 582 if (numPoints <= 1)
565 return; 583 return;
566 584
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1961 // FIXME: This is to not break tests (it results in the filter bitmap fl ag 1979 // FIXME: This is to not break tests (it results in the filter bitmap fl ag
1962 // being set to true). We need to decide if we respect InterpolationNone 1980 // being set to true). We need to decide if we respect InterpolationNone
1963 // being returned from computeInterpolationQuality. 1981 // being returned from computeInterpolationQuality.
1964 resampling = InterpolationLow; 1982 resampling = InterpolationLow;
1965 } 1983 }
1966 resampling = limitInterpolationQuality(this, resampling); 1984 resampling = limitInterpolationQuality(this, resampling);
1967 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); 1985 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling));
1968 } 1986 }
1969 1987
1970 } // namespace blink 1988 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698