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

Side by Side Diff: sky/engine/platform/graphics/GraphicsContext.cpp

Issue 1017593005: Add a basic custom painting facility to Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Add missing files Created 5 years, 9 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } // unnamed namespace 91 } // unnamed namespace
92 92
93 struct GraphicsContext::CanvasSaveState { 93 struct GraphicsContext::CanvasSaveState {
94 CanvasSaveState(bool pendingSave, int count) 94 CanvasSaveState(bool pendingSave, int count)
95 : m_pendingSave(pendingSave), m_restoreCount(count) { } 95 : m_pendingSave(pendingSave), m_restoreCount(count) { }
96 96
97 bool m_pendingSave; 97 bool m_pendingSave;
98 int m_restoreCount; 98 int m_restoreCount;
99 }; 99 };
100 100
101 struct GraphicsContext::RecordingState {
102 RecordingState(SkCanvas* currentCanvas, const SkMatrix& currentMatrix, PassR efPtr<DisplayList> displayList)
103 : m_savedCanvas(currentCanvas)
104 , m_displayList(displayList)
105 , m_savedMatrix(currentMatrix)
106 {
107 }
108
109 SkCanvas* m_savedCanvas;
110 RefPtr<DisplayList> m_displayList;
111 const SkMatrix m_savedMatrix;
112 };
113
114 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisabledMode disableContextOr Painting) 101 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisabledMode disableContextOr Painting)
115 : m_canvas(canvas) 102 : m_canvas(canvas)
116 , m_paintStateStack() 103 , m_paintStateStack()
117 , m_paintStateIndex(0) 104 , m_paintStateIndex(0)
118 , m_pendingCanvasSave(false) 105 , m_pendingCanvasSave(false)
119 #if ENABLE(ASSERT) 106 #if ENABLE(ASSERT)
120 , m_layerCount(0) 107 , m_layerCount(0)
121 , m_disableDestructionChecks(false) 108 , m_disableDestructionChecks(false)
122 #endif 109 #endif
123 , m_disabledState(disableContextOrPainting) 110 , m_disabledState(disableContextOrPainting)
(...skipping 13 matching lines...) Expand all
137 m_paintState = m_paintStateStack.last().get(); 124 m_paintState = m_paintStateStack.last().get();
138 } 125 }
139 126
140 GraphicsContext::~GraphicsContext() 127 GraphicsContext::~GraphicsContext()
141 { 128 {
142 #if ENABLE(ASSERT) 129 #if ENABLE(ASSERT)
143 if (!m_disableDestructionChecks) { 130 if (!m_disableDestructionChecks) {
144 ASSERT(!m_paintStateIndex); 131 ASSERT(!m_paintStateIndex);
145 ASSERT(!m_paintState->saveCount()); 132 ASSERT(!m_paintState->saveCount());
146 ASSERT(!m_layerCount); 133 ASSERT(!m_layerCount);
147 ASSERT(m_recordingStateStack.isEmpty());
148 ASSERT(m_canvasStateStack.isEmpty()); 134 ASSERT(m_canvasStateStack.isEmpty());
149 } 135 }
150 #endif 136 #endif
151 } 137 }
152 138
153 void GraphicsContext::resetCanvas(SkCanvas* canvas) 139 void GraphicsContext::resetCanvas(SkCanvas* canvas)
154 { 140 {
155 ASSERT(canvas); 141 ASSERT(canvas);
156 m_canvas = canvas; 142 m_canvas = canvas;
157 m_trackedRegion.reset(); 143 m_trackedRegion.reset();
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 SkRect skBounds = SkRect::Make(skIBounds); 311 SkRect skBounds = SkRect::Make(skIBounds);
326 *bounds = FloatRect(skBounds); 312 *bounds = FloatRect(skBounds);
327 return true; 313 return true;
328 } 314 }
329 315
330 SkMatrix GraphicsContext::getTotalMatrix() const 316 SkMatrix GraphicsContext::getTotalMatrix() const
331 { 317 {
332 if (contextDisabled()) 318 if (contextDisabled())
333 return SkMatrix::I(); 319 return SkMatrix::I();
334 320
335 if (!isRecording()) 321 return m_canvas->getTotalMatrix();
336 return m_canvas->getTotalMatrix();
337
338 const RecordingState& recordingState = m_recordingStateStack.last();
339 SkMatrix totalMatrix = recordingState.m_savedMatrix;
340 totalMatrix.preConcat(m_canvas->getTotalMatrix());
341
342 return totalMatrix;
343 } 322 }
344 323
345 void GraphicsContext::adjustTextRenderMode(SkPaint* paint) 324 void GraphicsContext::adjustTextRenderMode(SkPaint* paint)
346 { 325 {
347 if (contextDisabled()) 326 if (contextDisabled())
348 return; 327 return;
349 328
350 if (!paint->isLCDRenderText()) 329 if (!paint->isLCDRenderText())
351 return; 330 return;
352 331
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 return; 419 return;
441 420
442 restoreLayer(); 421 restoreLayer();
443 422
444 ASSERT(m_layerCount > 0); 423 ASSERT(m_layerCount > 0);
445 #if ENABLE(ASSERT) 424 #if ENABLE(ASSERT)
446 --m_layerCount; 425 --m_layerCount;
447 #endif 426 #endif
448 } 427 }
449 428
450 void GraphicsContext::beginRecording(const FloatRect& bounds) 429 void GraphicsContext::drawDisplayList(DisplayList* displayList, const FloatPoint & point)
451 {
452 RefPtr<DisplayList> displayList = adoptRef(new DisplayList(bounds));
453
454 SkCanvas* savedCanvas = m_canvas;
455 SkMatrix savedMatrix = getTotalMatrix();
456
457 if (!contextDisabled()) {
458 IntRect recordingRect = enclosingIntRect(bounds);
459 m_canvas = displayList->beginRecording(recordingRect.size());
460
461 // We want the bounds offset mapped to (0, 0), such that the display lis t content
462 // is fully contained within the SkPictureRecord's bounds.
463 if (!toFloatSize(bounds.location()).isZero()) {
464 m_canvas->translate(-bounds.x(), -bounds.y());
465 // To avoid applying the offset repeatedly in getTotalMatrix(), we p re-apply it here.
466 savedMatrix.preTranslate(bounds.x(), bounds.y());
467 }
468 }
469
470 m_recordingStateStack.append(RecordingState(savedCanvas, savedMatrix, displa yList));
471 }
472
473 PassRefPtr<DisplayList> GraphicsContext::endRecording()
474 {
475 ASSERT(!m_recordingStateStack.isEmpty());
476
477 RecordingState recording = m_recordingStateStack.last();
478 if (!contextDisabled()) {
479 ASSERT(recording.m_displayList->isRecording());
480 recording.m_displayList->endRecording();
481 }
482
483 m_recordingStateStack.removeLast();
484 m_canvas = recording.m_savedCanvas;
485
486 return recording.m_displayList.release();
487 }
488
489 bool GraphicsContext::isRecording() const
490 {
491 return !m_recordingStateStack.isEmpty();
492 }
493
494 void GraphicsContext::drawDisplayList(DisplayList* displayList)
495 { 430 {
496 ASSERT(displayList); 431 ASSERT(displayList);
497 ASSERT(!displayList->isRecording());
498 432
499 if (contextDisabled() || displayList->bounds().isEmpty()) 433 if (contextDisabled())
500 return; 434 return;
501 435
502 realizeCanvasSave(); 436 realizeCanvasSave();
503 437
504 const FloatRect& bounds = displayList->bounds(); 438 if (point.x() || point.y()) {
505 if (bounds.x() || bounds.y()) {
506 SkMatrix m; 439 SkMatrix m;
507 m.setTranslate(bounds.x(), bounds.y()); 440 m.setTranslate(point.x(), point.y());
508 m_canvas->drawPicture(displayList->picture(), &m, 0); 441 m_canvas->drawPicture(displayList->picture(), &m, 0);
509 } else { 442 } else {
510 m_canvas->drawPicture(displayList->picture()); 443 m_canvas->drawPicture(displayList->picture());
511 } 444 }
512 } 445 }
513 446
514 void GraphicsContext::drawConvexPolygon(size_t numPoints, const FloatPoint* poin ts, bool shouldAntialias) 447 void GraphicsContext::drawConvexPolygon(size_t numPoints, const FloatPoint* poin ts, bool shouldAntialias)
515 { 448 {
516 if (contextDisabled()) 449 if (contextDisabled())
517 return; 450 return;
(...skipping 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 // FIXME: This is to not break tests (it results in the filter bitmap fl ag 1721 // FIXME: This is to not break tests (it results in the filter bitmap fl ag
1789 // being set to true). We need to decide if we respect InterpolationNone 1722 // being set to true). We need to decide if we respect InterpolationNone
1790 // being returned from computeInterpolationQuality. 1723 // being returned from computeInterpolationQuality.
1791 resampling = InterpolationLow; 1724 resampling = InterpolationLow;
1792 } 1725 }
1793 resampling = limitInterpolationQuality(this, resampling); 1726 resampling = limitInterpolationQuality(this, resampling);
1794 paint->setFilterQuality(static_cast<SkFilterQuality>(resampling)); 1727 paint->setFilterQuality(static_cast<SkFilterQuality>(resampling));
1795 } 1728 }
1796 1729
1797 } // namespace blink 1730 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698