OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 | 8 |
10 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
11 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
12 #include "SkBounder.h" | |
13 #include "SkDeviceImageFilterProxy.h" | 11 #include "SkDeviceImageFilterProxy.h" |
14 #include "SkDraw.h" | 12 #include "SkDraw.h" |
15 #include "SkDrawFilter.h" | 13 #include "SkDrawFilter.h" |
16 #include "SkDrawLooper.h" | 14 #include "SkDrawLooper.h" |
17 #include "SkMetaData.h" | 15 #include "SkMetaData.h" |
18 #include "SkPathOps.h" | 16 #include "SkPathOps.h" |
19 #include "SkPicture.h" | 17 #include "SkPicture.h" |
20 #include "SkRasterClip.h" | 18 #include "SkRasterClip.h" |
21 #include "SkRRect.h" | 19 #include "SkRRect.h" |
22 #include "SkSmallAllocator.h" | 20 #include "SkSmallAllocator.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 }; | 248 }; |
251 | 249 |
252 class SkDrawIter : public SkDraw { | 250 class SkDrawIter : public SkDraw { |
253 public: | 251 public: |
254 SkDrawIter(SkCanvas* canvas, bool skipEmptyClips = true) { | 252 SkDrawIter(SkCanvas* canvas, bool skipEmptyClips = true) { |
255 canvas = canvas->canvasForDrawIter(); | 253 canvas = canvas->canvasForDrawIter(); |
256 fCanvas = canvas; | 254 fCanvas = canvas; |
257 canvas->updateDeviceCMCache(); | 255 canvas->updateDeviceCMCache(); |
258 | 256 |
259 fClipStack = &canvas->fClipStack; | 257 fClipStack = &canvas->fClipStack; |
260 fBounder = canvas->getBounder(); | |
261 fCurrLayer = canvas->fMCRec->fTopLayer; | 258 fCurrLayer = canvas->fMCRec->fTopLayer; |
262 fSkipEmptyClips = skipEmptyClips; | 259 fSkipEmptyClips = skipEmptyClips; |
263 } | 260 } |
264 | 261 |
265 bool next() { | 262 bool next() { |
266 // skip over recs with empty clips | 263 // skip over recs with empty clips |
267 if (fSkipEmptyClips) { | 264 if (fSkipEmptyClips) { |
268 while (fCurrLayer && fCurrLayer->fClip.isEmpty()) { | 265 while (fCurrLayer && fCurrLayer->fClip.isEmpty()) { |
269 fCurrLayer = fCurrLayer->fNext; | 266 fCurrLayer = fCurrLayer->fNext; |
270 } | 267 } |
271 } | 268 } |
272 | 269 |
273 const DeviceCM* rec = fCurrLayer; | 270 const DeviceCM* rec = fCurrLayer; |
274 if (rec && rec->fDevice) { | 271 if (rec && rec->fDevice) { |
275 | 272 |
276 fMatrix = rec->fMatrix; | 273 fMatrix = rec->fMatrix; |
277 fClip = &((SkRasterClip*)&rec->fClip)->forceGetBW(); | 274 fClip = &((SkRasterClip*)&rec->fClip)->forceGetBW(); |
278 fRC = &rec->fClip; | 275 fRC = &rec->fClip; |
279 fDevice = rec->fDevice; | 276 fDevice = rec->fDevice; |
280 fBitmap = &fDevice->accessBitmap(true); | 277 fBitmap = &fDevice->accessBitmap(true); |
281 fPaint = rec->fPaint; | 278 fPaint = rec->fPaint; |
282 SkDEBUGCODE(this->validate();) | 279 SkDEBUGCODE(this->validate();) |
283 | 280 |
284 fCurrLayer = rec->fNext; | 281 fCurrLayer = rec->fNext; |
285 if (fBounder) { | |
286 fBounder->setClip(fClip); | |
287 } | |
288 // fCurrLayer may be NULL now | 282 // fCurrLayer may be NULL now |
289 | 283 |
290 return true; | 284 return true; |
291 } | 285 } |
292 return false; | 286 return false; |
293 } | 287 } |
294 | 288 |
295 SkBaseDevice* getDevice() const { return fDevice; } | 289 SkBaseDevice* getDevice() const { return fDevice; } |
296 int getX() const { return fDevice->getOrigin().x(); } | 290 int getX() const { return fDevice->getOrigin().x(); } |
297 int getY() const { return fDevice->getOrigin().y(); } | 291 int getY() const { return fDevice->getOrigin().y(); } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 411 } |
418 | 412 |
419 // call this after any possible paint modifiers | 413 // call this after any possible paint modifiers |
420 if (fPaint->nothingToDraw()) { | 414 if (fPaint->nothingToDraw()) { |
421 fPaint = NULL; | 415 fPaint = NULL; |
422 return false; | 416 return false; |
423 } | 417 } |
424 return true; | 418 return true; |
425 } | 419 } |
426 | 420 |
427 /* Stack helper for managing a SkBounder. In the destructor, if we were | |
428 given a bounder, we call its commit() method, signifying that we are | |
429 done accumulating bounds for that draw. | |
430 */ | |
431 class SkAutoBounderCommit { | |
432 public: | |
433 SkAutoBounderCommit(SkBounder* bounder) : fBounder(bounder) {} | |
434 ~SkAutoBounderCommit() { | |
435 if (NULL != fBounder) { | |
436 fBounder->commit(); | |
437 } | |
438 } | |
439 private: | |
440 SkBounder* fBounder; | |
441 }; | |
442 #define SkAutoBounderCommit(...) SK_REQUIRE_LOCAL_VAR(SkAutoBounderCommit) | |
443 | |
444 #include "SkColorPriv.h" | 421 #include "SkColorPriv.h" |
445 | 422 |
446 ////////// macros to place around the internal draw calls ////////////////// | 423 ////////// macros to place around the internal draw calls ////////////////// |
447 | 424 |
448 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ | 425 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ |
449 this->predrawNotify(); \ | 426 this->predrawNotify(); \ |
450 AutoDrawLooper looper(this, paint, true); \ | 427 AutoDrawLooper looper(this, paint, true); \ |
451 while (looper.next(type)) { \ | 428 while (looper.next(type)) { \ |
452 SkAutoBounderCommit ac(fBounder); \ | |
453 SkDrawIter iter(this); | 429 SkDrawIter iter(this); |
454 | 430 |
455 #define LOOPER_BEGIN(paint, type, bounds) \ | 431 #define LOOPER_BEGIN(paint, type, bounds) \ |
456 this->predrawNotify(); \ | 432 this->predrawNotify(); \ |
457 AutoDrawLooper looper(this, paint, false, bounds); \ | 433 AutoDrawLooper looper(this, paint, false, bounds); \ |
458 while (looper.next(type)) { \ | 434 while (looper.next(type)) { \ |
459 SkAutoBounderCommit ac(fBounder); \ | |
460 SkDrawIter iter(this); | 435 SkDrawIter iter(this); |
461 | 436 |
462 #define LOOPER_END } | 437 #define LOOPER_END } |
463 | 438 |
464 //////////////////////////////////////////////////////////////////////////// | 439 //////////////////////////////////////////////////////////////////////////// |
465 | 440 |
466 SkBaseDevice* SkCanvas::init(SkBaseDevice* device) { | 441 SkBaseDevice* SkCanvas::init(SkBaseDevice* device) { |
467 fBounder = NULL; | |
468 fCachedLocalClipBounds.setEmpty(); | 442 fCachedLocalClipBounds.setEmpty(); |
469 fCachedLocalClipBoundsDirty = true; | 443 fCachedLocalClipBoundsDirty = true; |
470 fAllowSoftClip = true; | 444 fAllowSoftClip = true; |
471 fAllowSimplifyClip = false; | 445 fAllowSimplifyClip = false; |
472 fDeviceCMDirty = false; | 446 fDeviceCMDirty = false; |
473 fSaveLayerCount = 0; | 447 fSaveLayerCount = 0; |
474 fCullCount = 0; | 448 fCullCount = 0; |
475 fMetaData = NULL; | 449 fMetaData = NULL; |
476 | 450 |
477 fMCRec = (MCRec*)fMCStack.push_back(); | 451 fMCRec = (MCRec*)fMCStack.push_back(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 this->init(SkNEW_ARGS(SkBitmapDevice, (bitmap)))->unref(); | 493 this->init(SkNEW_ARGS(SkBitmapDevice, (bitmap)))->unref(); |
520 } | 494 } |
521 | 495 |
522 SkCanvas::~SkCanvas() { | 496 SkCanvas::~SkCanvas() { |
523 // free up the contents of our deque | 497 // free up the contents of our deque |
524 this->restoreToCount(1); // restore everything but the last | 498 this->restoreToCount(1); // restore everything but the last |
525 SkASSERT(0 == fSaveLayerCount); | 499 SkASSERT(0 == fSaveLayerCount); |
526 | 500 |
527 this->internalRestore(); // restore the last, since we're going away | 501 this->internalRestore(); // restore the last, since we're going away |
528 | 502 |
529 SkSafeUnref(fBounder); | |
530 SkDELETE(fMetaData); | 503 SkDELETE(fMetaData); |
531 | 504 |
532 dec_canvas(); | 505 dec_canvas(); |
533 } | 506 } |
534 | 507 |
535 SkBounder* SkCanvas::setBounder(SkBounder* bounder) { | |
536 SkRefCnt_SafeAssign(fBounder, bounder); | |
537 return bounder; | |
538 } | |
539 | |
540 SkDrawFilter* SkCanvas::getDrawFilter() const { | 508 SkDrawFilter* SkCanvas::getDrawFilter() const { |
541 return fMCRec->fFilter; | 509 return fMCRec->fFilter; |
542 } | 510 } |
543 | 511 |
544 SkDrawFilter* SkCanvas::setDrawFilter(SkDrawFilter* filter) { | 512 SkDrawFilter* SkCanvas::setDrawFilter(SkDrawFilter* filter) { |
545 SkRefCnt_SafeAssign(fMCRec->fFilter, filter); | 513 SkRefCnt_SafeAssign(fMCRec->fFilter, filter); |
546 return filter; | 514 return filter; |
547 } | 515 } |
548 | 516 |
549 SkMetaData& SkCanvas::getMetaData() { | 517 SkMetaData& SkCanvas::getMetaData() { |
(...skipping 2076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2626 if (!supported_for_raster_canvas(info)) { | 2594 if (!supported_for_raster_canvas(info)) { |
2627 return NULL; | 2595 return NULL; |
2628 } | 2596 } |
2629 | 2597 |
2630 SkBitmap bitmap; | 2598 SkBitmap bitmap; |
2631 if (!bitmap.installPixels(info, pixels, rowBytes)) { | 2599 if (!bitmap.installPixels(info, pixels, rowBytes)) { |
2632 return NULL; | 2600 return NULL; |
2633 } | 2601 } |
2634 return SkNEW_ARGS(SkCanvas, (bitmap)); | 2602 return SkNEW_ARGS(SkCanvas, (bitmap)); |
2635 } | 2603 } |
OLD | NEW |