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

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

Issue 1087633002: [SP] Allocate an SkPictureRecorder only once per GraphicsContext instantiation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "wtf/MathExtras.h" 49 #include "wtf/MathExtras.h"
50 50
51 namespace blink { 51 namespace blink {
52 52
53 class GraphicsContext::RecordingState { 53 class GraphicsContext::RecordingState {
54 WTF_MAKE_FAST_ALLOCATED(GraphicsContext::RecordingState); 54 WTF_MAKE_FAST_ALLOCATED(GraphicsContext::RecordingState);
55 WTF_MAKE_NONCOPYABLE(RecordingState); 55 WTF_MAKE_NONCOPYABLE(RecordingState);
56 public: 56 public:
57 static PassOwnPtr<RecordingState> Create(SkCanvas* canvas, const SkMatrix& m atrix) 57 static PassOwnPtr<RecordingState> Create(SkCanvas* canvas, const SkMatrix& m atrix)
58 { 58 {
59 // Slimmming Paint uses m_pictureRecorder on GraphicsContext instead.
60 ASSERT(!RuntimeEnabledFeatures::slimmingPaintEnabled());
59 return adoptPtr(new RecordingState(canvas, matrix)); 61 return adoptPtr(new RecordingState(canvas, matrix));
60 } 62 }
61 63
62 SkPictureRecorder& recorder() { return m_recorder; } 64 SkPictureRecorder& recorder() { return m_recorder; }
63 SkCanvas* canvas() const { return m_savedCanvas; } 65 SkCanvas* canvas() const { return m_savedCanvas; }
64 const SkMatrix& matrix() const { return m_savedMatrix; } 66 const SkMatrix& matrix() const { return m_savedMatrix; }
65 67
66 private: 68 private:
67 explicit RecordingState(SkCanvas* canvas, const SkMatrix& matrix) 69 explicit RecordingState(SkCanvas* canvas, const SkMatrix& matrix)
68 : m_savedCanvas(canvas) 70 : m_savedCanvas(canvas)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 { 106 {
105 // FIXME: Do some tests to determine how many states are typically used, and allocate 107 // FIXME: Do some tests to determine how many states are typically used, and allocate
106 // several here. 108 // several here.
107 m_paintStateStack.append(GraphicsContextState::create()); 109 m_paintStateStack.append(GraphicsContextState::create());
108 m_paintState = m_paintStateStack.last().get(); 110 m_paintState = m_paintStateStack.last().get();
109 111
110 if (contextDisabled()) { 112 if (contextDisabled()) {
111 DEFINE_STATIC_LOCAL(RefPtr<SkCanvas>, nullCanvas, (adoptRef(SkCreateNull Canvas()))); 113 DEFINE_STATIC_LOCAL(RefPtr<SkCanvas>, nullCanvas, (adoptRef(SkCreateNull Canvas())));
112 m_canvas = nullCanvas.get(); 114 m_canvas = nullCanvas.get();
113 } 115 }
116
117 // TODO(chrishtr): switch the type of the parameter to DisplayItemList&
118 ASSERT(displayItemList);
119 m_pictureRecorder = adoptPtr(new SkPictureRecorder);
114 } 120 }
115 121
116 GraphicsContext::~GraphicsContext() 122 GraphicsContext::~GraphicsContext()
117 { 123 {
118 #if ENABLE(ASSERT) 124 #if ENABLE(ASSERT)
119 if (!m_disableDestructionChecks) { 125 if (!m_disableDestructionChecks) {
120 ASSERT(!m_paintStateIndex); 126 ASSERT(!m_paintStateIndex);
121 ASSERT(!m_paintState->saveCount()); 127 ASSERT(!m_paintState->saveCount());
122 ASSERT(!m_annotationCount); 128 ASSERT(!m_annotationCount);
123 ASSERT(!m_layerCount); 129 ASSERT(!m_layerCount);
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 restoreLayer(); 471 restoreLayer();
466 472
467 ASSERT(m_layerCount-- > 0); 473 ASSERT(m_layerCount-- > 0);
468 } 474 }
469 475
470 void GraphicsContext::beginRecording(const FloatRect& bounds, uint32_t recordFla gs) 476 void GraphicsContext::beginRecording(const FloatRect& bounds, uint32_t recordFla gs)
471 { 477 {
472 if (contextDisabled()) 478 if (contextDisabled())
473 return; 479 return;
474 480
481 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) {
482 m_canvas = m_pictureRecorder->beginRecording(bounds, 0, recordFlags);
483 return;
484 }
485
475 m_recordingStateStack.append( 486 m_recordingStateStack.append(
476 RecordingState::Create(m_canvas, getTotalMatrix())); 487 RecordingState::Create(m_canvas, getTotalMatrix()));
477 m_canvas = m_recordingStateStack.last()->recorder().beginRecording(bounds, 0 , recordFlags); 488 m_canvas = m_recordingStateStack.last()->recorder().beginRecording(bounds, 0 , recordFlags);
478 } 489 }
479 490
480 PassRefPtr<const SkPicture> GraphicsContext::endRecording() 491 PassRefPtr<const SkPicture> GraphicsContext::endRecording()
481 { 492 {
482 if (contextDisabled()) 493 if (contextDisabled())
483 return nullptr; 494 return nullptr;
484 495
496 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) {
497 RefPtr<const SkPicture> picture = adoptRef(m_pictureRecorder->endRecordi ngAsPicture());
498 m_canvas = nullptr;
499 ASSERT(picture);
500 return picture.release();
501 }
502
485 ASSERT(!m_recordingStateStack.isEmpty()); 503 ASSERT(!m_recordingStateStack.isEmpty());
486 RecordingState* recording = m_recordingStateStack.last().get(); 504 RecordingState* recording = m_recordingStateStack.last().get();
487 RefPtr<const SkPicture> picture = adoptRef(recording->recorder().endRecordin gAsPicture()); 505 RefPtr<const SkPicture> picture = adoptRef(recording->recorder().endRecordin gAsPicture());
488 m_canvas = recording->canvas(); 506 m_canvas = recording->canvas();
489 507
490 m_recordingStateStack.removeLast(); 508 m_recordingStateStack.removeLast();
491 509
492 ASSERT(picture); 510 ASSERT(picture);
493 return picture.release(); 511 return picture.release();
494 } 512 }
495 513
496 bool GraphicsContext::isRecording() const 514 bool GraphicsContext::isRecording() const
497 { 515 {
516 if (RuntimeEnabledFeatures::slimmingPaintEnabled())
517 return m_canvas;
518
498 return !m_recordingStateStack.isEmpty(); 519 return !m_recordingStateStack.isEmpty();
499 } 520 }
500 521
501 void GraphicsContext::drawPicture(const SkPicture* picture) 522 void GraphicsContext::drawPicture(const SkPicture* picture)
502 { 523 {
503 // FIXME: SP currently builds empty-bounds pictures in some cases. This is a temp 524 // FIXME: SP currently builds empty-bounds pictures in some cases. This is a temp
504 // workaround, but the problem should be fixed: empty-bounds pictures are go ing to be culled 525 // workaround, but the problem should be fixed: empty-bounds pictures are go ing to be culled
505 // on playback anyway. 526 // on playback anyway.
506 bool cullEmptyPictures = !RuntimeEnabledFeatures::slimmingPaintEnabled(); 527 bool cullEmptyPictures = !RuntimeEnabledFeatures::slimmingPaintEnabled();
507 if (contextDisabled() || !picture || (picture->cullRect().isEmpty() && cullE mptyPictures)) 528 if (contextDisabled() || !picture || (picture->cullRect().isEmpty() && cullE mptyPictures))
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 // being returned from computeInterpolationQuality. 1771 // being returned from computeInterpolationQuality.
1751 resampling = InterpolationLow; 1772 resampling = InterpolationLow;
1752 } 1773 }
1753 resampling = limitInterpolationQuality(this, resampling); 1774 resampling = limitInterpolationQuality(this, resampling);
1754 paint->setFilterQuality(static_cast<SkFilterQuality>(resampling)); 1775 paint->setFilterQuality(static_cast<SkFilterQuality>(resampling));
1755 1776
1756 return initialSaveCount; 1777 return initialSaveCount;
1757 } 1778 }
1758 1779
1759 } // namespace blink 1780 } // namespace blink
OLDNEW
« Source/platform/graphics/GraphicsContext.h ('K') | « Source/platform/graphics/GraphicsContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698