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

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: 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(PassRefPtr<DisplayList> displayList, uint32 _t recordFlags)
496 { 499 {
497 RefPtr<DisplayList> displayList = adoptRef(new DisplayList(bounds)); 500 RefPtr<DisplayList> pDisplayList = displayList;
501
502 pDisplayList->clearPicture();
chrishtr 2014/09/02 22:05:58 What's the use case of beginning a recording of a
Stephen Chennney 2014/09/03 14:19:37 If the display list is invalidated we should be ab
chrishtr 2014/09/03 16:56:11 What's the performance advantage of this though? T
503 SkPictureRecorder* recorder = 0;
498 504
499 SkCanvas* savedCanvas = m_canvas; 505 SkCanvas* savedCanvas = m_canvas;
500 SkMatrix savedMatrix = getTotalMatrix(); 506 SkMatrix savedMatrix = getTotalMatrix();
501 507
502 if (!contextDisabled()) { 508 if (!contextDisabled()) {
503 IntRect recordingRect = enclosingIntRect(bounds); 509 FloatRect bounds = pDisplayList->bounds();
504 m_canvas = displayList->beginRecording(recordingRect.size()); 510 IntSize recordingSize = enclosingIntRect(bounds).size();
511 recorder = new SkPictureRecorder;
512 m_canvas = recorder->beginRecording(recordingSize.width(), recordingSize .height(), 0, recordFlags);
505 513
506 // We want the bounds offset mapped to (0, 0), such that the display lis t content 514 // 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. 515 // is fully contained within the SkPictureRecord's bounds.
508 if (!toFloatSize(bounds.location()).isZero()) { 516 if (!toFloatSize(bounds.location()).isZero()) {
509 m_canvas->translate(-bounds.x(), -bounds.y()); 517 m_canvas->translate(-bounds.x(), -bounds.y());
510 // To avoid applying the offset repeatedly in getTotalMatrix(), we p re-apply it here. 518 // To avoid applying the offset repeatedly in getTotalMatrix(), we p re-apply it here.
511 savedMatrix.preTranslate(bounds.x(), bounds.y()); 519 savedMatrix.preTranslate(bounds.x(), bounds.y());
512 } 520 }
513 } 521 }
514 522
515 m_recordingStateStack.append(RecordingState(savedCanvas, savedMatrix, displa yList)); 523 m_recordingStateStack.append(RecordingState(recorder, savedCanvas, savedMatr ix, pDisplayList));
516 } 524 }
517 525
518 PassRefPtr<DisplayList> GraphicsContext::endRecording() 526 void GraphicsContext::endRecording()
519 { 527 {
520 ASSERT(!m_recordingStateStack.isEmpty()); 528 ASSERT(!m_recordingStateStack.isEmpty());
521 529
522 RecordingState recording = m_recordingStateStack.last(); 530 RecordingState recording = m_recordingStateStack.last();
523 if (!contextDisabled()) { 531 if (!contextDisabled())
524 ASSERT(recording.m_displayList->isRecording()); 532 recording.m_displayList->setPicture(recording.m_recorder->endRecording() );
525 recording.m_displayList->endRecording();
526 }
527 533
534 m_canvas = recording.m_savedCanvas;
535 delete recording.m_recorder;
528 m_recordingStateStack.removeLast(); 536 m_recordingStateStack.removeLast();
529 m_canvas = recording.m_savedCanvas;
530
531 return recording.m_displayList.release();
532 } 537 }
533 538
534 bool GraphicsContext::isRecording() const 539 bool GraphicsContext::isRecording() const
535 { 540 {
536 return !m_recordingStateStack.isEmpty(); 541 return !m_recordingStateStack.isEmpty();
537 } 542 }
538 543
539 void GraphicsContext::drawDisplayList(DisplayList* displayList) 544 void GraphicsContext::drawDisplayList(DisplayList* displayList)
540 { 545 {
541 ASSERT(displayList); 546 ASSERT(displayList);
542 ASSERT(!displayList->isRecording());
543 547
544 if (contextDisabled() || displayList->bounds().isEmpty()) 548 if (contextDisabled() || displayList->bounds().isEmpty())
545 return; 549 return;
546 550
551 bool performClip = !displayList->clip().isEmpty();
552 bool performTransform = !displayList->transform().isIdentity();
553 if (performClip || performTransform) {
554 save();
555 if (performTransform)
556 concat(displayList->transform());
557 if (performClip)
558 clipRect(displayList->clip());
559 }
560
547 realizeCanvasSave(); 561 realizeCanvasSave();
548 562
549 const FloatRect& bounds = displayList->bounds(); 563 const FloatPoint& location = displayList->bounds().location();
550 if (bounds.x() || bounds.y()) { 564 if (location.x() || location.y()) {
551 SkMatrix m; 565 SkMatrix m;
552 m.setTranslate(bounds.x(), bounds.y()); 566 m.setTranslate(location.x(), location.y());
553 m_canvas->drawPicture(displayList->picture(), &m, 0); 567 m_canvas->drawPicture(displayList->picture(), &m, 0);
554 } else { 568 } else {
555 m_canvas->drawPicture(displayList->picture()); 569 m_canvas->drawPicture(displayList->picture());
556 } 570 }
571
572 if (performClip || performTransform)
573 restore();
557 } 574 }
558 575
559 void GraphicsContext::drawConvexPolygon(size_t numPoints, const FloatPoint* poin ts, bool shouldAntialias) 576 void GraphicsContext::drawConvexPolygon(size_t numPoints, const FloatPoint* poin ts, bool shouldAntialias)
560 { 577 {
561 if (contextDisabled()) 578 if (contextDisabled())
562 return; 579 return;
563 580
564 if (numPoints <= 1) 581 if (numPoints <= 1)
565 return; 582 return;
566 583
(...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 1978 // 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 1979 // being set to true). We need to decide if we respect InterpolationNone
1963 // being returned from computeInterpolationQuality. 1980 // being returned from computeInterpolationQuality.
1964 resampling = InterpolationLow; 1981 resampling = InterpolationLow;
1965 } 1982 }
1966 resampling = limitInterpolationQuality(this, resampling); 1983 resampling = limitInterpolationQuality(this, resampling);
1967 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); 1984 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling));
1968 } 1985 }
1969 1986
1970 } // namespace blink 1987 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698