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

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

Issue 541913002: Create a GraphicsContext from a DisplayList. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@display-list-changes
Patch Set: Rebased 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 , m_regionTrackingMode(RegionTrackingDisabled) 130 , m_regionTrackingMode(RegionTrackingDisabled)
131 , m_trackTextRegion(false) 131 , m_trackTextRegion(false)
132 , m_accelerated(false) 132 , m_accelerated(false)
133 , m_isCertainlyOpaque(true) 133 , m_isCertainlyOpaque(true)
134 , m_printing(false) 134 , m_printing(false)
135 , m_antialiasHairlineImages(false) 135 , m_antialiasHairlineImages(false)
136 , m_shouldSmoothFonts(true) 136 , m_shouldSmoothFonts(true)
137 { 137 {
138 ASSERT(canvas); 138 ASSERT(canvas);
139 139
140 // FIXME: Do some tests to determine how many states are typically used, and allocate 140 initializeStateStack();
141 // several here. 141 }
142 m_paintStateStack.append(GraphicsContextState::create()); 142
143 m_paintState = m_paintStateStack.last().get(); 143 GraphicsContext::GraphicsContext(const FloatRect& bounds, DisabledMode disableCo ntextOrPainting)
144 : m_canvas(0)
145 , m_paintStateStack()
146 , m_paintStateIndex(0)
147 , m_pendingCanvasSave(false)
148 , m_annotationMode(0)
149 #if ENABLE(ASSERT)
150 , m_annotationCount(0)
151 , m_layerCount(0)
152 , m_disableDestructionChecks(false)
153 #endif
154 , m_disabledState(disableContextOrPainting)
155 , m_deviceScaleFactor(1.0f)
156 , m_regionTrackingMode(RegionTrackingDisabled)
157 , m_trackTextRegion(false)
158 , m_accelerated(false)
159 , m_isCertainlyOpaque(true)
160 , m_printing(false)
161 , m_antialiasHairlineImages(false)
162 {
163 initializeStateStack();
164
165 RefPtr<DisplayList> displayList = DisplayList::create(bounds);
166 SkCanvas* savedCanvas = 0;
167 SkMatrix savedMatrix = SkMatrix::I();
168
169 beginRecordingImpl(displayList, 0, savedCanvas, savedMatrix);
144 } 170 }
145 171
146 GraphicsContext::~GraphicsContext() 172 GraphicsContext::~GraphicsContext()
147 { 173 {
148 #if ENABLE(ASSERT) 174 #if ENABLE(ASSERT)
149 if (!m_disableDestructionChecks) { 175 if (!m_disableDestructionChecks) {
150 ASSERT(!m_paintStateIndex); 176 ASSERT(!m_paintStateIndex);
151 ASSERT(!m_paintState->saveCount()); 177 ASSERT(!m_paintState->saveCount());
152 ASSERT(!m_annotationCount); 178 ASSERT(!m_annotationCount);
153 ASSERT(!m_layerCount); 179 ASSERT(!m_layerCount);
154 ASSERT(m_recordingStateStack.isEmpty()); 180 ASSERT(m_recordingStateStack.isEmpty());
155 ASSERT(m_canvasStateStack.isEmpty()); 181 ASSERT(m_canvasStateStack.isEmpty());
156 } 182 }
157 #endif 183 #endif
158 } 184 }
159 185
186 void GraphicsContext::initializeStateStack()
187 {
188 // FIXME: Do some tests to determine how many states are typically used, and allocate
189 // several here.
190 m_paintStateStack.append(GraphicsContextState::create());
191 m_paintState = m_paintStateStack.last().get();
192 }
193
160 void GraphicsContext::resetCanvas(SkCanvas* canvas) 194 void GraphicsContext::resetCanvas(SkCanvas* canvas)
161 { 195 {
162 ASSERT(canvas); 196 ASSERT(canvas);
163 m_canvas = canvas; 197 m_canvas = canvas;
164 m_trackedRegion.reset(); 198 m_trackedRegion.reset();
165 } 199 }
166 200
167 void GraphicsContext::setRegionTrackingMode(RegionTrackingMode mode) 201 void GraphicsContext::setRegionTrackingMode(RegionTrackingMode mode)
168 { 202 {
169 m_regionTrackingMode = mode; 203 m_regionTrackingMode = mode;
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 return; 522 return;
489 523
490 restoreLayer(); 524 restoreLayer();
491 525
492 ASSERT(m_layerCount > 0); 526 ASSERT(m_layerCount > 0);
493 #if ENABLE(ASSERT) 527 #if ENABLE(ASSERT)
494 --m_layerCount; 528 --m_layerCount;
495 #endif 529 #endif
496 } 530 }
497 531
498 void GraphicsContext::beginRecording(const FloatRect& bounds, uint32_t recordFla gs) 532 void GraphicsContext::beginRecordingImpl(PassRefPtr<DisplayList> displayList, ui nt32_t recordFlags,
533 SkCanvas* savedCanvas, SkMatrix& savedMatrix)
499 { 534 {
500 RefPtr<DisplayList> displayList = DisplayList::create(bounds); 535 RefPtr<DisplayList> pDisplayList = displayList;
501 536
537 ASSERT(!pDisplayList->picture());
502 SkPictureRecorder* recorder = 0; 538 SkPictureRecorder* recorder = 0;
503 539
504 SkCanvas* savedCanvas = m_canvas;
505 SkMatrix savedMatrix = getTotalMatrix();
506
507 if (!contextDisabled()) { 540 if (!contextDisabled()) {
508 FloatRect bounds = displayList->bounds(); 541 FloatRect bounds = pDisplayList->bounds();
509 IntSize recordingSize = enclosingIntRect(bounds).size(); 542 IntSize recordingSize = enclosingIntRect(bounds).size();
510 recorder = new SkPictureRecorder; 543 recorder = new SkPictureRecorder;
511 m_canvas = recorder->beginRecording(recordingSize.width(), recordingSize .height(), 0, recordFlags); 544 m_canvas = recorder->beginRecording(recordingSize.width(), recordingSize .height(), 0, recordFlags);
512 545
513 // We want the bounds offset mapped to (0, 0), such that the display lis t content 546 // We want the bounds offset mapped to (0, 0), such that the display lis t content
514 // is fully contained within the SkPictureRecord's bounds. 547 // is fully contained within the SkPictureRecord's bounds.
515 if (!toFloatSize(bounds.location()).isZero()) { 548 if (!toFloatSize(bounds.location()).isZero()) {
516 m_canvas->translate(-bounds.x(), -bounds.y()); 549 m_canvas->translate(-bounds.x(), -bounds.y());
517 // To avoid applying the offset repeatedly in getTotalMatrix(), we p re-apply it here. 550 // To avoid applying the offset repeatedly in getTotalMatrix(), we p re-apply it here.
518 savedMatrix.preTranslate(bounds.x(), bounds.y()); 551 savedMatrix.preTranslate(bounds.x(), bounds.y());
519 } 552 }
520 } 553 }
521 554
522 m_recordingStateStack.append(RecordingState(recorder, savedCanvas, savedMatr ix, displayList)); 555 m_recordingStateStack.append(RecordingState(recorder, savedCanvas, savedMatr ix, pDisplayList));
556 }
557
558 void GraphicsContext::beginRecording(const FloatRect& bounds, uint32_t recordFla gs)
559 {
560 RefPtr<DisplayList> displayList = DisplayList::create(bounds);
561
562 SkCanvas* savedCanvas = m_canvas;
563 SkMatrix savedMatrix = getTotalMatrix();
564
565 beginRecordingImpl(displayList, recordFlags, savedCanvas, savedMatrix);
523 } 566 }
524 567
525 PassRefPtr<DisplayList> GraphicsContext::endRecording() 568 PassRefPtr<DisplayList> GraphicsContext::endRecording()
526 { 569 {
527 ASSERT(!m_recordingStateStack.isEmpty()); 570 ASSERT(!m_recordingStateStack.isEmpty());
528 571
529 RecordingState recording = m_recordingStateStack.last(); 572 RecordingState recording = m_recordingStateStack.last();
530 if (!contextDisabled()) 573 if (!contextDisabled())
531 recording.m_displayList->setPicture(recording.m_recorder->endRecording() ); 574 recording.m_displayList->setPicture(recording.m_recorder->endRecording() );
532 575
(...skipping 1446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 // FIXME: This is to not break tests (it results in the filter bitmap fl ag 2022 // FIXME: This is to not break tests (it results in the filter bitmap fl ag
1980 // being set to true). We need to decide if we respect InterpolationNone 2023 // being set to true). We need to decide if we respect InterpolationNone
1981 // being returned from computeInterpolationQuality. 2024 // being returned from computeInterpolationQuality.
1982 resampling = InterpolationLow; 2025 resampling = InterpolationLow;
1983 } 2026 }
1984 resampling = limitInterpolationQuality(this, resampling); 2027 resampling = limitInterpolationQuality(this, resampling);
1985 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); 2028 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling));
1986 } 2029 }
1987 2030
1988 } // namespace blink 2031 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698