OLD | NEW |
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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 SkASSERT(fDeferredSaveCount == 0); | 311 SkASSERT(fDeferredSaveCount == 0); |
312 | 312 |
313 fMatrix.reset(); | 313 fMatrix.reset(); |
314 fRasterClip.setRect(bounds); | 314 fRasterClip.setRect(bounds); |
315 fLayer->reset(bounds); | 315 fLayer->reset(bounds); |
316 } | 316 } |
317 }; | 317 }; |
318 | 318 |
319 class SkDrawIter : public SkDraw { | 319 class SkDrawIter : public SkDraw { |
320 public: | 320 public: |
321 SkDrawIter(SkCanvas* canvas, bool skipEmptyClips = true) { | 321 SkDrawIter(SkCanvas* canvas) { |
322 canvas = canvas->canvasForDrawIter(); | 322 canvas = canvas->canvasForDrawIter(); |
323 fCanvas = canvas; | 323 fCanvas = canvas; |
324 canvas->updateDeviceCMCache(); | 324 canvas->updateDeviceCMCache(); |
325 | 325 |
326 fClipStack = canvas->fClipStack; | 326 fClipStack = canvas->fClipStack; |
327 fCurrLayer = canvas->fMCRec->fTopLayer; | 327 fCurrLayer = canvas->fMCRec->fTopLayer; |
328 fSkipEmptyClips = skipEmptyClips; | |
329 } | 328 } |
330 | 329 |
331 bool next() { | 330 bool next() { |
332 // skip over recs with empty clips | 331 // skip over recs with empty clips |
333 if (fSkipEmptyClips) { | 332 while (fCurrLayer && fCurrLayer->fClip.isEmpty()) { |
334 while (fCurrLayer && fCurrLayer->fClip.isEmpty()) { | 333 fCurrLayer = fCurrLayer->fNext; |
335 fCurrLayer = fCurrLayer->fNext; | |
336 } | |
337 } | 334 } |
338 | 335 |
339 const DeviceCM* rec = fCurrLayer; | 336 const DeviceCM* rec = fCurrLayer; |
340 if (rec && rec->fDevice) { | 337 if (rec && rec->fDevice) { |
341 | 338 |
342 fMatrix = rec->fMatrix; | 339 fMatrix = rec->fMatrix; |
343 fRC = &rec->fClip; | 340 fRC = &rec->fClip; |
344 fDevice = rec->fDevice; | 341 fDevice = rec->fDevice; |
345 if (!fDevice->accessPixels(&fDst)) { | 342 if (!fDevice->accessPixels(&fDst)) { |
346 fDst.reset(fDevice->imageInfo(), nullptr, 0); | 343 fDst.reset(fDevice->imageInfo(), nullptr, 0); |
(...skipping 13 matching lines...) Expand all Loading... |
360 const SkRasterClip& getClip() const { return *fRC; } | 357 const SkRasterClip& getClip() const { return *fRC; } |
361 int getX() const { return fDevice->getOrigin().x(); } | 358 int getX() const { return fDevice->getOrigin().x(); } |
362 int getY() const { return fDevice->getOrigin().y(); } | 359 int getY() const { return fDevice->getOrigin().y(); } |
363 const SkMatrix& getMatrix() const { return *fMatrix; } | 360 const SkMatrix& getMatrix() const { return *fMatrix; } |
364 const SkPaint* getPaint() const { return fPaint; } | 361 const SkPaint* getPaint() const { return fPaint; } |
365 | 362 |
366 private: | 363 private: |
367 SkCanvas* fCanvas; | 364 SkCanvas* fCanvas; |
368 const DeviceCM* fCurrLayer; | 365 const DeviceCM* fCurrLayer; |
369 const SkPaint* fPaint; // May be null. | 366 const SkPaint* fPaint; // May be null. |
370 SkBool8 fSkipEmptyClips; | |
371 | 367 |
372 typedef SkDraw INHERITED; | 368 typedef SkDraw INHERITED; |
373 }; | 369 }; |
374 | 370 |
375 ///////////////////////////////////////////////////////////////////////////// | 371 ///////////////////////////////////////////////////////////////////////////// |
376 | 372 |
377 static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) { | 373 static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) { |
378 return lazy->isValid() ? lazy->get() : lazy->set(orig); | 374 return lazy->isValid() ? lazy->get() : lazy->set(orig); |
379 } | 375 } |
380 | 376 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 } else { | 421 } else { |
426 return rawBounds; | 422 return rawBounds; |
427 } | 423 } |
428 } | 424 } |
429 | 425 |
430 class AutoDrawLooper { | 426 class AutoDrawLooper { |
431 public: | 427 public: |
432 // "rawBounds" is the original bounds of the primitive about to be drawn, un
modified by the | 428 // "rawBounds" is the original bounds of the primitive about to be drawn, un
modified by the |
433 // paint. It's used to determine the size of the offscreen layer for filters
. | 429 // paint. It's used to determine the size of the offscreen layer for filters
. |
434 // If null, the clip will be used instead. | 430 // If null, the clip will be used instead. |
435 AutoDrawLooper(SkCanvas* canvas, const SkSurfaceProps& props, const SkPaint&
paint, | 431 AutoDrawLooper(SkCanvas* canvas, const SkPaint& paint, bool skipLayerForImag
eFilter = false, |
436 bool skipLayerForImageFilter = false, | |
437 const SkRect* rawBounds = nullptr) : fOrigPaint(paint) { | 432 const SkRect* rawBounds = nullptr) : fOrigPaint(paint) { |
438 fCanvas = canvas; | 433 fCanvas = canvas; |
439 #ifdef SK_SUPPORT_LEGACY_DRAWFILTER | 434 #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
440 fFilter = canvas->getDrawFilter(); | 435 fFilter = canvas->getDrawFilter(); |
441 #else | 436 #else |
442 fFilter = nullptr; | 437 fFilter = nullptr; |
443 #endif | 438 #endif |
444 fPaint = &fOrigPaint; | 439 fPaint = &fOrigPaint; |
445 fSaveCount = canvas->getSaveCount(); | 440 fSaveCount = canvas->getSaveCount(); |
446 fTempLayerForImageFilter = false; | 441 fTempLayerForImageFilter = false; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 // call this after any possible paint modifiers | 568 // call this after any possible paint modifiers |
574 if (fPaint->nothingToDraw()) { | 569 if (fPaint->nothingToDraw()) { |
575 fPaint = nullptr; | 570 fPaint = nullptr; |
576 return false; | 571 return false; |
577 } | 572 } |
578 return true; | 573 return true; |
579 } | 574 } |
580 | 575 |
581 ////////// macros to place around the internal draw calls ////////////////// | 576 ////////// macros to place around the internal draw calls ////////////////// |
582 | 577 |
583 #define LOOPER_BEGIN_DRAWBITMAP(paint, skipLayerForFilter, bounds) \ | 578 #define LOOPER_BEGIN_DRAWBITMAP(paint, skipLayerForFilter, bounds) \ |
584 this->predrawNotify(); \ | 579 this->predrawNotify(); \ |
585 AutoDrawLooper looper(this, fProps, paint, skipLayerForFilter, bounds); \ | 580 AutoDrawLooper looper(this, paint, skipLayerForFilter, bounds); \ |
586 while (looper.next(SkDrawFilter::kBitmap_Type)) { \ | 581 while (looper.next(SkDrawFilter::kBitmap_Type)) { \ |
587 SkDrawIter iter(this); | 582 SkDrawIter iter(this); |
588 | 583 |
589 | 584 |
590 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ | 585 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ |
591 this->predrawNotify(); \ | 586 this->predrawNotify(); \ |
592 AutoDrawLooper looper(this, fProps, paint, true); \ | 587 AutoDrawLooper looper(this, paint, true); \ |
593 while (looper.next(type)) { \ | 588 while (looper.next(type)) { \ |
594 SkDrawIter iter(this); | 589 SkDrawIter iter(this); |
595 | 590 |
596 #define LOOPER_BEGIN(paint, type, bounds) \ | 591 #define LOOPER_BEGIN(paint, type, bounds) \ |
597 this->predrawNotify(); \ | 592 this->predrawNotify(); \ |
598 AutoDrawLooper looper(this, fProps, paint, false, bounds); \ | 593 AutoDrawLooper looper(this, paint, false, bounds); \ |
599 while (looper.next(type)) { \ | 594 while (looper.next(type)) { \ |
600 SkDrawIter iter(this); | 595 SkDrawIter iter(this); |
601 | 596 |
602 #define LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, type, bounds, auxOpaque) \ | 597 #define LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, type, bounds, auxOpaque) \ |
603 this->predrawNotify(bounds, &paint, auxOpaque); \ | 598 this->predrawNotify(bounds, &paint, auxOpaque); \ |
604 AutoDrawLooper looper(this, fProps, paint, false, bounds); \ | 599 AutoDrawLooper looper(this, paint, false, bounds); \ |
605 while (looper.next(type)) { \ | 600 while (looper.next(type)) { \ |
606 SkDrawIter iter(this); | 601 SkDrawIter iter(this); |
607 | 602 |
608 #define LOOPER_END } | 603 #define LOOPER_END } |
609 | 604 |
610 //////////////////////////////////////////////////////////////////////////// | 605 //////////////////////////////////////////////////////////////////////////// |
611 | 606 |
612 static inline SkRect qr_clip_bounds(const SkIRect& bounds) { | 607 static inline SkRect qr_clip_bounds(const SkIRect& bounds) { |
613 if (bounds.isEmpty()) { | 608 if (bounds.isEmpty()) { |
614 return SkRect::MakeEmpty(); | 609 return SkRect::MakeEmpty(); |
(...skipping 2641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3256 | 3251 |
3257 shadowPaint.setShader(shadowShader); | 3252 shadowPaint.setShader(shadowShader); |
3258 | 3253 |
3259 this->drawRect(SkRect::MakeIWH(diffuseMap->width(), diffuseMap->height()), s
hadowPaint); | 3254 this->drawRect(SkRect::MakeIWH(diffuseMap->width(), diffuseMap->height()), s
hadowPaint); |
3260 } | 3255 } |
3261 #endif | 3256 #endif |
3262 | 3257 |
3263 /////////////////////////////////////////////////////////////////////////////// | 3258 /////////////////////////////////////////////////////////////////////////////// |
3264 /////////////////////////////////////////////////////////////////////////////// | 3259 /////////////////////////////////////////////////////////////////////////////// |
3265 | 3260 |
3266 SkCanvas::LayerIter::LayerIter(SkCanvas* canvas, bool skipEmptyClips) { | 3261 SkCanvas::LayerIter::LayerIter(SkCanvas* canvas) { |
3267 static_assert(sizeof(fStorage) >= sizeof(SkDrawIter), "fStorage_too_small"); | 3262 static_assert(sizeof(fStorage) >= sizeof(SkDrawIter), "fStorage_too_small"); |
3268 | 3263 |
3269 SkASSERT(canvas); | 3264 SkASSERT(canvas); |
3270 | 3265 |
3271 fImpl = new (fStorage) SkDrawIter(canvas, skipEmptyClips); | 3266 fImpl = new (fStorage) SkDrawIter(canvas); |
3272 fDone = !fImpl->next(); | 3267 fDone = !fImpl->next(); |
3273 } | 3268 } |
3274 | 3269 |
3275 SkCanvas::LayerIter::~LayerIter() { | 3270 SkCanvas::LayerIter::~LayerIter() { |
3276 fImpl->~SkDrawIter(); | 3271 fImpl->~SkDrawIter(); |
3277 } | 3272 } |
3278 | 3273 |
3279 void SkCanvas::LayerIter::next() { | 3274 void SkCanvas::LayerIter::next() { |
3280 fDone = !fImpl->next(); | 3275 fDone = !fImpl->next(); |
3281 } | 3276 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3363 | 3358 |
3364 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3359 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
3365 fCanvas->restoreToCount(fSaveCount); | 3360 fCanvas->restoreToCount(fSaveCount); |
3366 } | 3361 } |
3367 | 3362 |
3368 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API | 3363 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
3369 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { | 3364 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { |
3370 return this->makeSurface(info, props).release(); | 3365 return this->makeSurface(info, props).release(); |
3371 } | 3366 } |
3372 #endif | 3367 #endif |
OLD | NEW |