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

Side by Side Diff: src/core/SkCanvas.cpp

Issue 794263002: Cull pushCull and popCull from Skia. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix debugger Created 6 years 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
« no previous file with comments | « include/utils/SkDumpCanvas.h ('k') | src/core/SkPictureFlat.h » ('j') | 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 2008 The Android Open Source Project 2 * Copyright 2008 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkCanvasDrawable.h" 9 #include "SkCanvasDrawable.h"
10 #include "SkCanvasPriv.h" 10 #include "SkCanvasPriv.h"
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 410
411 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { 411 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) {
412 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag) ; 412 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag) ;
413 fCachedLocalClipBounds.setEmpty(); 413 fCachedLocalClipBounds.setEmpty();
414 fCachedLocalClipBoundsDirty = true; 414 fCachedLocalClipBoundsDirty = true;
415 fAllowSoftClip = true; 415 fAllowSoftClip = true;
416 fAllowSimplifyClip = false; 416 fAllowSimplifyClip = false;
417 fDeviceCMDirty = true; 417 fDeviceCMDirty = true;
418 fSaveCount = 1; 418 fSaveCount = 1;
419 fSaveLayerCount = 0; 419 fSaveLayerCount = 0;
420 fCullCount = 0;
421 fMetaData = NULL; 420 fMetaData = NULL;
422 421
423 fMCRec = (MCRec*)fMCStack.push_back(); 422 fMCRec = (MCRec*)fMCStack.push_back();
424 new (fMCRec) MCRec(fConservativeRasterClip); 423 new (fMCRec) MCRec(fConservativeRasterClip);
425 424
426 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative RasterClip)); 425 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative RasterClip));
427 fMCRec->fTopLayer = fMCRec->fLayer; 426 fMCRec->fTopLayer = fMCRec->fLayer;
428 427
429 fSurfaceBase = NULL; 428 fSurfaceBase = NULL;
430 429
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 } 688 }
690 return true; 689 return true;
691 } 690 }
692 691
693 bool SkCanvas::readPixels(const SkImageInfo& dstInfo, void* dstP, size_t rowByte s, int x, int y) { 692 bool SkCanvas::readPixels(const SkImageInfo& dstInfo, void* dstP, size_t rowByte s, int x, int y) {
694 SkBaseDevice* device = this->getDevice(); 693 SkBaseDevice* device = this->getDevice();
695 if (!device) { 694 if (!device) {
696 return false; 695 return false;
697 } 696 }
698 const SkISize size = this->getBaseLayerSize(); 697 const SkISize size = this->getBaseLayerSize();
699 698
700 SkReadPixelsRec rec(dstInfo, dstP, rowBytes, x, y); 699 SkReadPixelsRec rec(dstInfo, dstP, rowBytes, x, y);
701 if (!rec.trim(size.width(), size.height())) { 700 if (!rec.trim(size.width(), size.height())) {
702 return false; 701 return false;
703 } 702 }
704 703
705 // The device can assert that the requested area is always contained in its bounds 704 // The device can assert that the requested area is always contained in its bounds
706 return device->readPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.fX, rec .fY); 705 return device->readPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.fX, rec .fY);
707 } 706 }
708 707
709 bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) { 708 bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 this->didRestore(); 836 this->didRestore();
838 } 837 }
839 } 838 }
840 } 839 }
841 840
842 void SkCanvas::restoreToCount(int count) { 841 void SkCanvas::restoreToCount(int count) {
843 // sanity check 842 // sanity check
844 if (count < 1) { 843 if (count < 1) {
845 count = 1; 844 count = 1;
846 } 845 }
847 846
848 int n = this->getSaveCount() - count; 847 int n = this->getSaveCount() - count;
849 for (int i = 0; i < n; ++i) { 848 for (int i = 0; i < n; ++i) {
850 this->restore(); 849 this->restore();
851 } 850 }
852 } 851 }
853 852
854 void SkCanvas::internalSave() { 853 void SkCanvas::internalSave() {
855 MCRec* newTop = (MCRec*)fMCStack.push_back(); 854 MCRec* newTop = (MCRec*)fMCStack.push_back();
856 new (newTop) MCRec(*fMCRec); // balanced in restore() 855 new (newTop) MCRec(*fMCRec); // balanced in restore()
857 fMCRec = newTop; 856 fMCRec = newTop;
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 1111
1113 bool SkAutoROCanvasPixels::asROBitmap(SkBitmap* bitmap) const { 1112 bool SkAutoROCanvasPixels::asROBitmap(SkBitmap* bitmap) const {
1114 if (fAddr) { 1113 if (fAddr) {
1115 return bitmap->installPixels(fInfo, const_cast<void*>(fAddr), fRowBytes) ; 1114 return bitmap->installPixels(fInfo, const_cast<void*>(fAddr), fRowBytes) ;
1116 } else { 1115 } else {
1117 bitmap->reset(); 1116 bitmap->reset();
1118 return false; 1117 return false;
1119 } 1118 }
1120 } 1119 }
1121 1120
1122 void SkCanvas::onPushCull(const SkRect& cullRect) {
1123 // do nothing. Subclasses may do something
1124 }
1125
1126 void SkCanvas::onPopCull() {
1127 // do nothing. Subclasses may do something
1128 }
1129
1130 /////////////////////////////////////////////////////////////////////////////
1131 #ifdef SK_DEBUG
1132 // Ensure that cull rects are monotonically nested in device space.
1133 void SkCanvas::validateCull(const SkIRect& devCull) {
1134 if (fCullStack.isEmpty()
1135 || devCull.isEmpty()
1136 || fCullStack.top().contains(devCull)) {
1137 return;
1138 }
1139
1140 SkDEBUGF(("Invalid cull: [%d %d %d %d] (previous cull: [%d %d %d %d])\n",
1141 devCull.x(), devCull.y(), devCull.right(), devCull.bottom(),
1142 fCullStack.top().x(), fCullStack.top().y(),
1143 fCullStack.top().right(), fCullStack.top().bottom()));
1144
1145 #ifdef ASSERT_NESTED_CULLING
1146 SkDEBUGFAIL("Invalid cull.");
1147 #endif
1148 }
1149 #endif
1150
1151 void SkCanvas::pushCull(const SkRect& cullRect) {
1152 this->checkForDeferredSave();
1153 ++fCullCount;
1154 this->onPushCull(cullRect);
1155
1156 #ifdef SK_DEBUG
1157 // Map the cull rect into device space.
1158 SkRect mappedCull;
1159 this->getTotalMatrix().mapRect(&mappedCull, cullRect);
1160
1161 // Take clipping into account.
1162 SkIRect devClip, devCull;
1163 mappedCull.roundOut(&devCull);
1164 this->getClipDeviceBounds(&devClip);
1165 if (!devCull.intersect(devClip)) {
1166 devCull.setEmpty();
1167 }
1168
1169 this->validateCull(devCull);
1170 fCullStack.push(devCull); // balanced in popCull
1171 #endif
1172 }
1173
1174 void SkCanvas::popCull() {
1175 SkASSERT(fCullStack.count() == fCullCount);
1176
1177 if (fCullCount > 0) {
1178 --fCullCount;
1179 this->onPopCull();
1180
1181 SkDEBUGCODE(fCullStack.pop());
1182 }
1183 }
1184
1185 ///////////////////////////////////////////////////////////////////////////// 1121 /////////////////////////////////////////////////////////////////////////////
1186
1187 void SkCanvas::internalDrawBitmap(const SkBitmap& bitmap, 1122 void SkCanvas::internalDrawBitmap(const SkBitmap& bitmap,
1188 const SkMatrix& matrix, const SkPaint* paint) { 1123 const SkMatrix& matrix, const SkPaint* paint) {
1189 if (bitmap.drawsNothing()) { 1124 if (bitmap.drawsNothing()) {
1190 return; 1125 return;
1191 } 1126 }
1192 1127
1193 SkLazyPaint lazy; 1128 SkLazyPaint lazy;
1194 if (NULL == paint) { 1129 if (NULL == paint) {
1195 paint = lazy.init(); 1130 paint = lazy.init();
1196 } 1131 }
(...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after
2567 } 2502 }
2568 2503
2569 if (matrix) { 2504 if (matrix) {
2570 canvas->concat(*matrix); 2505 canvas->concat(*matrix);
2571 } 2506 }
2572 } 2507 }
2573 2508
2574 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2509 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2575 fCanvas->restoreToCount(fSaveCount); 2510 fCanvas->restoreToCount(fSaveCount);
2576 } 2511 }
OLDNEW
« no previous file with comments | « include/utils/SkDumpCanvas.h ('k') | src/core/SkPictureFlat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698