| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 if (this->wouldOverwriteEntireSurface(rect, paint, overrideOpacity))
{ | 168 if (this->wouldOverwriteEntireSurface(rect, paint, overrideOpacity))
{ |
| 169 mode = SkSurface::kDiscard_ContentChangeMode; | 169 mode = SkSurface::kDiscard_ContentChangeMode; |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 fSurfaceBase->aboutToDraw(mode); | 172 fSurfaceBase->aboutToDraw(mode); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 /////////////////////////////////////////////////////////////////////////////// | 176 /////////////////////////////////////////////////////////////////////////////// |
| 177 | 177 |
| 178 static uint32_t filter_paint_flags(const SkSurfaceProps& props, uint32_t flags)
{ | |
| 179 const uint32_t propFlags = props.flags(); | |
| 180 if (propFlags & SkSurfaceProps::kDisallowDither_Flag) { | |
| 181 flags &= ~SkPaint::kDither_Flag; | |
| 182 } | |
| 183 if (propFlags & SkSurfaceProps::kDisallowAntiAlias_Flag) { | |
| 184 flags &= ~SkPaint::kAntiAlias_Flag; | |
| 185 } | |
| 186 return flags; | |
| 187 } | |
| 188 | |
| 189 /////////////////////////////////////////////////////////////////////////////// | |
| 190 | |
| 191 /* This is the record we keep for each SkBaseDevice that the user installs. | 178 /* This is the record we keep for each SkBaseDevice that the user installs. |
| 192 The clip/matrix/proc are fields that reflect the top of the save/restore | 179 The clip/matrix/proc are fields that reflect the top of the save/restore |
| 193 stack. Whenever the canvas changes, it marks a dirty flag, and then before | 180 stack. Whenever the canvas changes, it marks a dirty flag, and then before |
| 194 these are used (assuming we're not on a layer) we rebuild these cache | 181 these are used (assuming we're not on a layer) we rebuild these cache |
| 195 values: they reflect the top of the save stack, but translated and clipped | 182 values: they reflect the top of the save stack, but translated and clipped |
| 196 by the device's XY offset and bitmap-bounds. | 183 by the device's XY offset and bitmap-bounds. |
| 197 */ | 184 */ |
| 198 struct DeviceCM { | 185 struct DeviceCM { |
| 199 DeviceCM* fNext; | 186 DeviceCM* fNext; |
| 200 SkBaseDevice* fDevice; | 187 SkBaseDevice* fDevice; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 if (SkDrawLooper* looper = paint.getLooper()) { | 487 if (SkDrawLooper* looper = paint.getLooper()) { |
| 501 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex
t>( | 488 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex
t>( |
| 502 looper->contextSize()); | 489 looper->contextSize()); |
| 503 fLooperContext = looper->createContext(canvas, buffer); | 490 fLooperContext = looper->createContext(canvas, buffer); |
| 504 fIsSimple = false; | 491 fIsSimple = false; |
| 505 } else { | 492 } else { |
| 506 fLooperContext = nullptr; | 493 fLooperContext = nullptr; |
| 507 // can we be marked as simple? | 494 // can we be marked as simple? |
| 508 fIsSimple = !fFilter && !fTempLayerForImageFilter; | 495 fIsSimple = !fFilter && !fTempLayerForImageFilter; |
| 509 } | 496 } |
| 510 | |
| 511 uint32_t oldFlags = paint.getFlags(); | |
| 512 fNewPaintFlags = filter_paint_flags(props, oldFlags); | |
| 513 if (fIsSimple && (fNewPaintFlags != oldFlags)) { | |
| 514 SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint); | |
| 515 paint->setFlags(fNewPaintFlags); | |
| 516 fPaint = paint; | |
| 517 // if we're not simple, doNext() will take care of calling setFlags(
) | |
| 518 } | |
| 519 } | 497 } |
| 520 | 498 |
| 521 ~AutoDrawLooper() { | 499 ~AutoDrawLooper() { |
| 522 if (fTempLayerForImageFilter) { | 500 if (fTempLayerForImageFilter) { |
| 523 fCanvas->internalRestore(); | 501 fCanvas->internalRestore(); |
| 524 } | 502 } |
| 525 SkASSERT(fCanvas->getSaveCount() == fSaveCount); | 503 SkASSERT(fCanvas->getSaveCount() == fSaveCount); |
| 526 } | 504 } |
| 527 | 505 |
| 528 const SkPaint& paint() const { | 506 const SkPaint& paint() const { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 542 } | 520 } |
| 543 | 521 |
| 544 private: | 522 private: |
| 545 SkLazyPaint fLazyPaintInit; // base paint storage in case we need to mod
ify it | 523 SkLazyPaint fLazyPaintInit; // base paint storage in case we need to mod
ify it |
| 546 SkLazyPaint fLazyPaintPerLooper; // per-draw-looper storage, so the loo
per can modify it | 524 SkLazyPaint fLazyPaintPerLooper; // per-draw-looper storage, so the loo
per can modify it |
| 547 SkCanvas* fCanvas; | 525 SkCanvas* fCanvas; |
| 548 const SkPaint& fOrigPaint; | 526 const SkPaint& fOrigPaint; |
| 549 SkDrawFilter* fFilter; | 527 SkDrawFilter* fFilter; |
| 550 const SkPaint* fPaint; | 528 const SkPaint* fPaint; |
| 551 int fSaveCount; | 529 int fSaveCount; |
| 552 uint32_t fNewPaintFlags; | |
| 553 bool fTempLayerForImageFilter; | 530 bool fTempLayerForImageFilter; |
| 554 bool fDone; | 531 bool fDone; |
| 555 bool fIsSimple; | 532 bool fIsSimple; |
| 556 SkDrawLooper::Context* fLooperContext; | 533 SkDrawLooper::Context* fLooperContext; |
| 557 SkSmallAllocator<1, 32> fLooperContextAllocator; | 534 SkSmallAllocator<1, 32> fLooperContextAllocator; |
| 558 | 535 |
| 559 bool doNext(SkDrawFilter::Type drawType); | 536 bool doNext(SkDrawFilter::Type drawType); |
| 560 }; | 537 }; |
| 561 | 538 |
| 562 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { | 539 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { |
| 563 fPaint = nullptr; | 540 fPaint = nullptr; |
| 564 SkASSERT(!fIsSimple); | 541 SkASSERT(!fIsSimple); |
| 565 SkASSERT(fLooperContext || fFilter || fTempLayerForImageFilter); | 542 SkASSERT(fLooperContext || fFilter || fTempLayerForImageFilter); |
| 566 | 543 |
| 567 SkPaint* paint = fLazyPaintPerLooper.set(fLazyPaintInit.isValid() ? | 544 SkPaint* paint = fLazyPaintPerLooper.set(fLazyPaintInit.isValid() ? |
| 568 *fLazyPaintInit.get() : fOrigPaint)
; | 545 *fLazyPaintInit.get() : fOrigPaint)
; |
| 569 paint->setFlags(fNewPaintFlags); | |
| 570 | 546 |
| 571 if (fTempLayerForImageFilter) { | 547 if (fTempLayerForImageFilter) { |
| 572 paint->setImageFilter(nullptr); | 548 paint->setImageFilter(nullptr); |
| 573 paint->setXfermode(nullptr); | 549 paint->setXfermode(nullptr); |
| 574 } | 550 } |
| 575 | 551 |
| 576 if (fLooperContext && !fLooperContext->next(fCanvas, paint)) { | 552 if (fLooperContext && !fLooperContext->next(fCanvas, paint)) { |
| 577 fDone = true; | 553 fDone = true; |
| 578 return false; | 554 return false; |
| 579 } | 555 } |
| (...skipping 2807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3387 | 3363 |
| 3388 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3364 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 3389 fCanvas->restoreToCount(fSaveCount); | 3365 fCanvas->restoreToCount(fSaveCount); |
| 3390 } | 3366 } |
| 3391 | 3367 |
| 3392 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API | 3368 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
| 3393 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { | 3369 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { |
| 3394 return this->makeSurface(info, props).release(); | 3370 return this->makeSurface(info, props).release(); |
| 3395 } | 3371 } |
| 3396 #endif | 3372 #endif |
| OLD | NEW |