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

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

Issue 187553003: Clean up SkCanvas::clip* API (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « include/core/SkCanvas.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 /* 2 /*
3 * Copyright 2008 The Android Open Source Project 3 * Copyright 2008 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 // will see its action 1158 // will see its action
1159 void SkCanvas::resetMatrix() { 1159 void SkCanvas::resetMatrix() {
1160 SkMatrix matrix; 1160 SkMatrix matrix;
1161 1161
1162 matrix.reset(); 1162 matrix.reset();
1163 this->setMatrix(matrix); 1163 this->setMatrix(matrix);
1164 } 1164 }
1165 1165
1166 ////////////////////////////////////////////////////////////////////////////// 1166 //////////////////////////////////////////////////////////////////////////////
1167 1167
1168 bool SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { 1168 void SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
1169 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; 1169 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle;
1170 this->onClipRect(rect, op, edgeStyle); 1170 this->onClipRect(rect, op, edgeStyle);
1171 return !this->isClipEmpty();
1172 } 1171 }
1173 1172
1174 void SkCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edg eStyle) { 1173 void SkCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edg eStyle) {
1175 #ifdef SK_ENABLE_CLIP_QUICKREJECT 1174 #ifdef SK_ENABLE_CLIP_QUICKREJECT
1176 if (SkRegion::kIntersect_Op == op) { 1175 if (SkRegion::kIntersect_Op == op) {
1177 if (fMCRec->fRasterClip->isEmpty()) { 1176 if (fMCRec->fRasterClip->isEmpty()) {
1178 return false; 1177 return false;
1179 } 1178 }
1180 1179
1181 if (this->quickReject(rect)) { 1180 if (this->quickReject(rect)) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 if (SkRegion::kReplace_Op == op) { 1250 if (SkRegion::kReplace_Op == op) {
1252 currClip->setPath(devPath, base, doAA); 1251 currClip->setPath(devPath, base, doAA);
1253 } else { 1252 } else {
1254 SkRasterClip clip; 1253 SkRasterClip clip;
1255 clip.setPath(devPath, base, doAA); 1254 clip.setPath(devPath, base, doAA);
1256 currClip->op(clip, op); 1255 currClip->op(clip, op);
1257 } 1256 }
1258 } 1257 }
1259 } 1258 }
1260 1259
1261 bool SkCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { 1260 void SkCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
1262 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; 1261 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle;
1263 if (rrect.isRect()) { 1262 if (rrect.isRect()) {
1264 this->onClipRect(rrect.getBounds(), op, edgeStyle); 1263 this->onClipRect(rrect.getBounds(), op, edgeStyle);
1265 } else { 1264 } else {
1266 this->onClipRRect(rrect, op, edgeStyle); 1265 this->onClipRRect(rrect, op, edgeStyle);
1267 } 1266 }
1268 return !this->isClipEmpty();
1269 } 1267 }
1270 1268
1271 void SkCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { 1269 void SkCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
1272 SkRRect transformedRRect; 1270 SkRRect transformedRRect;
1273 if (rrect.transform(*fMCRec->fMatrix, &transformedRRect)) { 1271 if (rrect.transform(*fMCRec->fMatrix, &transformedRRect)) {
1274 AutoValidateClip avc(this); 1272 AutoValidateClip avc(this);
1275 1273
1276 fDeviceCMDirty = true; 1274 fDeviceCMDirty = true;
1277 fCachedLocalClipBoundsDirty = true; 1275 fCachedLocalClipBoundsDirty = true;
1278 if (!fAllowSoftClip) { 1276 if (!fAllowSoftClip) {
1279 edgeStyle = kHard_ClipEdgeStyle; 1277 edgeStyle = kHard_ClipEdgeStyle;
1280 } 1278 }
1281 1279
1282 fClipStack.clipDevRRect(transformedRRect, op, kSoft_ClipEdgeStyle == edg eStyle); 1280 fClipStack.clipDevRRect(transformedRRect, op, kSoft_ClipEdgeStyle == edg eStyle);
1283 1281
1284 SkPath devPath; 1282 SkPath devPath;
1285 devPath.addRRect(transformedRRect); 1283 devPath.addRRect(transformedRRect);
1286 1284
1287 clip_path_helper(this, fMCRec->fRasterClip, devPath, op, kSoft_ClipEdgeS tyle == edgeStyle); 1285 clip_path_helper(this, fMCRec->fRasterClip, devPath, op, kSoft_ClipEdgeS tyle == edgeStyle);
1288 return; 1286 return;
1289 } 1287 }
1290 1288
1291 SkPath path; 1289 SkPath path;
1292 path.addRRect(rrect); 1290 path.addRRect(rrect);
1293 // call the non-virtual version 1291 // call the non-virtual version
1294 this->SkCanvas::onClipPath(path, op, edgeStyle); 1292 this->SkCanvas::onClipPath(path, op, edgeStyle);
1295 } 1293 }
1296 1294
1297 bool SkCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { 1295 void SkCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
1298 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; 1296 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle;
1299 SkRect r; 1297 SkRect r;
1300 if (!path.isInverseFillType() && path.isRect(&r)) { 1298 if (!path.isInverseFillType() && path.isRect(&r)) {
1301 this->onClipRect(r, op, edgeStyle); 1299 this->onClipRect(r, op, edgeStyle);
1302 } else { 1300 } else {
1303 this->onClipPath(path, op, edgeStyle); 1301 this->onClipPath(path, op, edgeStyle);
1304 } 1302 }
1305
1306 return !this->isClipEmpty();
1307 } 1303 }
1308 1304
1309 void SkCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edg eStyle) { 1305 void SkCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edg eStyle) {
1310 #ifdef SK_ENABLE_CLIP_QUICKREJECT 1306 #ifdef SK_ENABLE_CLIP_QUICKREJECT
1311 if (SkRegion::kIntersect_Op == op && !path.isInverseFillType()) { 1307 if (SkRegion::kIntersect_Op == op && !path.isInverseFillType()) {
1312 if (fMCRec->fRasterClip->isEmpty()) { 1308 if (fMCRec->fRasterClip->isEmpty()) {
1313 return false; 1309 return false;
1314 } 1310 }
1315 1311
1316 if (this->quickReject(path.getBounds())) { 1312 if (this->quickReject(path.getBounds())) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 if (element->isAA()) { 1368 if (element->isAA()) {
1373 edgeStyle = kSoft_ClipEdgeStyle; 1369 edgeStyle = kSoft_ClipEdgeStyle;
1374 } 1370 }
1375 } 1371 }
1376 op = SkRegion::kReplace_Op; 1372 op = SkRegion::kReplace_Op;
1377 } 1373 }
1378 1374
1379 clip_path_helper(this, fMCRec->fRasterClip, devPath, op, edgeStyle); 1375 clip_path_helper(this, fMCRec->fRasterClip, devPath, op, edgeStyle);
1380 } 1376 }
1381 1377
1382 bool SkCanvas::updateClipConservativelyUsingBounds(const SkRect& bounds, SkRegio n::Op op, 1378 void SkCanvas::updateClipConservativelyUsingBounds(const SkRect& bounds, SkRegio n::Op op,
1383 bool inverseFilled) { 1379 bool inverseFilled) {
1384 // This is for updating the clip conservatively using only bounds 1380 // This is for updating the clip conservatively using only bounds
1385 // information. 1381 // information.
1386 // Contract: 1382 // Contract:
1387 // The current clip must contain the true clip. The true 1383 // The current clip must contain the true clip. The true
1388 // clip is the clip that would have normally been computed 1384 // clip is the clip that would have normally been computed
1389 // by calls to clipPath and clipRRect 1385 // by calls to clipPath and clipRRect
1390 // Objective: 1386 // Objective:
1391 // Keep the current clip as small as possible without 1387 // Keep the current clip as small as possible without
1392 // breaking the contract, using only clip bounding rectangles 1388 // breaking the contract, using only clip bounding rectangles
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 break; 1441 break;
1446 case SkRegion::kXOR_Op: 1442 case SkRegion::kXOR_Op:
1447 // Be conservative, based on (A XOR B) always included in (A uni on B), 1443 // Be conservative, based on (A XOR B) always included in (A uni on B),
1448 // which is always included in (bounds(A) union bounds(B)) 1444 // which is always included in (bounds(A) union bounds(B))
1449 this->SkCanvas::onClipRect(bounds, SkRegion::kUnion_Op, kHard_Cl ipEdgeStyle); 1445 this->SkCanvas::onClipRect(bounds, SkRegion::kUnion_Op, kHard_Cl ipEdgeStyle);
1450 break; 1446 break;
1451 default: 1447 default:
1452 SkASSERT(0); // unhandled op? 1448 SkASSERT(0); // unhandled op?
1453 } 1449 }
1454 } 1450 }
1455
1456 return !this->isClipEmpty();
1457 } 1451 }
1458 1452
1459 bool SkCanvas::clipRegion(const SkRegion& rgn, SkRegion::Op op) { 1453 void SkCanvas::clipRegion(const SkRegion& rgn, SkRegion::Op op) {
1460 this->onClipRegion(rgn, op); 1454 this->onClipRegion(rgn, op);
1461 return !this->isClipEmpty();
1462 } 1455 }
1463 1456
1464 void SkCanvas::onClipRegion(const SkRegion& rgn, SkRegion::Op op) { 1457 void SkCanvas::onClipRegion(const SkRegion& rgn, SkRegion::Op op) {
1465 AutoValidateClip avc(this); 1458 AutoValidateClip avc(this);
1466 1459
1467 fDeviceCMDirty = true; 1460 fDeviceCMDirty = true;
1468 fCachedLocalClipBoundsDirty = true; 1461 fCachedLocalClipBoundsDirty = true;
1469 1462
1470 // todo: signal fClipStack that we have a region, and therefore (I guess) 1463 // todo: signal fClipStack that we have a region, and therefore (I guess)
1471 // we have to ignore it, and use the region directly? 1464 // we have to ignore it, and use the region directly?
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 if (!bitmap.allocPixels(info)) { 2381 if (!bitmap.allocPixels(info)) {
2389 return NULL; 2382 return NULL;
2390 } 2383 }
2391 2384
2392 // should this functionality be moved into allocPixels()? 2385 // should this functionality be moved into allocPixels()?
2393 if (!bitmap.info().isOpaque()) { 2386 if (!bitmap.info().isOpaque()) {
2394 bitmap.eraseColor(0); 2387 bitmap.eraseColor(0);
2395 } 2388 }
2396 return SkNEW_ARGS(SkCanvas, (bitmap)); 2389 return SkNEW_ARGS(SkCanvas, (bitmap));
2397 } 2390 }
OLDNEW
« no previous file with comments | « include/core/SkCanvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698