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

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
« no previous file with comments | « Source/platform/graphics/GraphicsContext.h ('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 /* 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)
69 , m_savedMatrix(matrix) 71 , m_savedMatrix(matrix)
70 { } 72 { }
71 73
72 SkPictureRecorder m_recorder; 74 SkPictureRecorder m_recorder;
73 SkCanvas* m_savedCanvas; 75 SkCanvas* m_savedCanvas;
74 const SkMatrix m_savedMatrix; 76 const SkMatrix m_savedMatrix;
75 }; 77 };
76 78
77 GraphicsContext::GraphicsContext(DisplayItemList* displayItemList, DisabledMode disableContextOrPainting) 79 GraphicsContext::GraphicsContext(DisplayItemList* displayItemList, DisabledMode disableContextOrPainting)
78 : GraphicsContext(nullptr, displayItemList, disableContextOrPainting) 80 : GraphicsContext(nullptr, displayItemList, disableContextOrPainting)
79 { } 81 {
82 // TODO(chrishtr): switch the type of the parameter to DisplayItemList&.
83 ASSERT(displayItemList);
84 }
80 85
81 PassOwnPtr<GraphicsContext> GraphicsContext::deprecatedCreateWithCanvas(SkCanvas * canvas, DisabledMode disableContextOrPainting) 86 PassOwnPtr<GraphicsContext> GraphicsContext::deprecatedCreateWithCanvas(SkCanvas * canvas, DisabledMode disableContextOrPainting)
82 { 87 {
83 return adoptPtr(new GraphicsContext(canvas, nullptr, disableContextOrPaintin g)); 88 return adoptPtr(new GraphicsContext(canvas, nullptr, disableContextOrPaintin g));
84 } 89 }
85 90
86 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisplayItemList* displayItemL ist, DisabledMode disableContextOrPainting) 91 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisplayItemList* displayItemL ist, DisabledMode disableContextOrPainting)
87 : m_canvas(canvas) 92 : m_canvas(canvas)
93 , m_originalCanvas(canvas)
88 , m_displayItemList(displayItemList) 94 , m_displayItemList(displayItemList)
89 , m_clipRecorderStack(0) 95 , m_clipRecorderStack(0)
90 , m_paintStateStack() 96 , m_paintStateStack()
91 , m_paintStateIndex(0) 97 , m_paintStateIndex(0)
92 , m_annotationMode(0) 98 , m_annotationMode(0)
93 #if ENABLE(ASSERT) 99 #if ENABLE(ASSERT)
94 , m_layerCount(0) 100 , m_layerCount(0)
95 , m_annotationCount(0) 101 , m_annotationCount(0)
96 , m_disableDestructionChecks(false) 102 , m_disableDestructionChecks(false)
97 , m_inDrawingRecorder(false) 103 , m_inDrawingRecorder(false)
(...skipping 367 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.endRecordin gAsPicture());
498 m_canvas = m_originalCanvas;
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 != m_originalCanvas;
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
« no previous file with comments | « Source/platform/graphics/GraphicsContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698