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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkCanvasPriv.h" | 9 #include "SkCanvasPriv.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 values: they reflect the top of the save stack, but translated and clipped | 107 values: they reflect the top of the save stack, but translated and clipped |
108 by the device's XY offset and bitmap-bounds. | 108 by the device's XY offset and bitmap-bounds. |
109 */ | 109 */ |
110 struct DeviceCM { | 110 struct DeviceCM { |
111 DeviceCM* fNext; | 111 DeviceCM* fNext; |
112 SkBaseDevice* fDevice; | 112 SkBaseDevice* fDevice; |
113 SkRasterClip fClip; | 113 SkRasterClip fClip; |
114 const SkMatrix* fMatrix; | 114 const SkMatrix* fMatrix; |
115 SkPaint* fPaint; // may be null (in the future) | 115 SkPaint* fPaint; // may be null (in the future) |
116 | 116 |
117 DeviceCM(SkBaseDevice* device, int x, int y, const SkPaint* paint, SkCanvas*
canvas, | 117 DeviceCM(SkBaseDevice* device, const SkPaint* paint, SkCanvas* canvas, |
118 bool conservativeRasterClip) | 118 bool conservativeRasterClip) |
119 : fNext(NULL) | 119 : fNext(NULL) |
120 , fClip(conservativeRasterClip) | 120 , fClip(conservativeRasterClip) |
121 { | 121 { |
122 if (NULL != device) { | 122 if (NULL != device) { |
123 device->ref(); | 123 device->ref(); |
124 device->onAttachToCanvas(canvas); | 124 device->onAttachToCanvas(canvas); |
125 } | 125 } |
126 fDevice = device; | 126 fDevice = device; |
127 fPaint = paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL; | 127 fPaint = paint ? SkNEW_ARGS(SkPaint, (*paint)) : NULL; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 fCachedLocalClipBoundsDirty = true; | 431 fCachedLocalClipBoundsDirty = true; |
432 fAllowSoftClip = true; | 432 fAllowSoftClip = true; |
433 fAllowSimplifyClip = false; | 433 fAllowSimplifyClip = false; |
434 fDeviceCMDirty = true; | 434 fDeviceCMDirty = true; |
435 fSaveCount = 1; | 435 fSaveCount = 1; |
436 fMetaData = NULL; | 436 fMetaData = NULL; |
437 | 437 |
438 fMCRec = (MCRec*)fMCStack.push_back(); | 438 fMCRec = (MCRec*)fMCStack.push_back(); |
439 new (fMCRec) MCRec(fConservativeRasterClip); | 439 new (fMCRec) MCRec(fConservativeRasterClip); |
440 | 440 |
441 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative
RasterClip)); | 441 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, NULL, NULL, fConservativeRaster
Clip)); |
442 fMCRec->fTopLayer = fMCRec->fLayer; | 442 fMCRec->fTopLayer = fMCRec->fLayer; |
443 | 443 |
444 fSurfaceBase = NULL; | 444 fSurfaceBase = NULL; |
445 | 445 |
446 fClipStack.reset(SkNEW(SkClipStack)); | 446 fClipStack.reset(SkNEW(SkClipStack)); |
447 | 447 |
448 if (device) { | 448 if (device) { |
449 device->initForRootLayer(fProps.pixelGeometry()); | 449 device->initForRootLayer(fProps.pixelGeometry()); |
450 if (device->forceConservativeRasterClip()) { | 450 if (device->forceConservativeRasterClip()) { |
451 fConservativeRasterClip = true; | 451 fConservativeRasterClip = true; |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 } | 831 } |
832 | 832 |
833 bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags, | 833 bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags, |
834 SkIRect* intersection, const SkImageFilter* image
Filter) { | 834 SkIRect* intersection, const SkImageFilter* image
Filter) { |
835 SkIRect clipBounds; | 835 SkIRect clipBounds; |
836 SkRegion::Op op = SkRegion::kIntersect_Op; | 836 SkRegion::Op op = SkRegion::kIntersect_Op; |
837 if (!this->getClipDeviceBounds(&clipBounds)) { | 837 if (!this->getClipDeviceBounds(&clipBounds)) { |
838 return false; | 838 return false; |
839 } | 839 } |
840 | 840 |
| 841 const SkMatrix& ctm = fMCRec->fMatrix; // this->getTotalMatrix() |
| 842 |
841 if (imageFilter) { | 843 if (imageFilter) { |
842 imageFilter->filterBounds(clipBounds, fMCRec->fMatrix, &clipBounds); | 844 imageFilter->filterBounds(clipBounds, ctm, &clipBounds); |
843 // Filters may grow the bounds beyond the device bounds. | 845 // Filters may grow the bounds beyond the device bounds. |
844 op = SkRegion::kReplace_Op; | 846 op = SkRegion::kReplace_Op; |
845 } | 847 } |
846 SkIRect ir; | 848 SkIRect ir; |
847 if (bounds) { | 849 if (bounds) { |
848 SkRect r; | 850 SkRect r; |
849 | 851 |
850 this->getTotalMatrix().mapRect(&r, *bounds); | 852 ctm.mapRect(&r, *bounds); |
851 r.roundOut(&ir); | 853 r.roundOut(&ir); |
852 // early exit if the layer's bounds are clipped out | 854 // early exit if the layer's bounds are clipped out |
853 if (!ir.intersect(clipBounds)) { | 855 if (!ir.intersect(clipBounds)) { |
854 if (bounds_affects_clip(flags)) { | 856 if (bounds_affects_clip(flags)) { |
855 fMCRec->fRasterClip.setEmpty(); | 857 fMCRec->fRasterClip.setEmpty(); |
856 } | 858 } |
857 return false; | 859 return false; |
858 } | 860 } |
859 } else { // no user bounds, so just use the clip | 861 } else { // no user bounds, so just use the clip |
860 ir = clipBounds; | 862 ir = clipBounds; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 } | 949 } |
948 device = device->onCreateCompatibleDevice(SkBaseDevice::CreateInfo(info, usa
ge, | 950 device = device->onCreateCompatibleDevice(SkBaseDevice::CreateInfo(info, usa
ge, |
949 fProps.pi
xelGeometry())); | 951 fProps.pi
xelGeometry())); |
950 if (NULL == device) { | 952 if (NULL == device) { |
951 SkErrorInternals::SetError( kInternalError_SkError, | 953 SkErrorInternals::SetError( kInternalError_SkError, |
952 "Unable to create device for layer."); | 954 "Unable to create device for layer."); |
953 return; | 955 return; |
954 } | 956 } |
955 | 957 |
956 device->setOrigin(ir.fLeft, ir.fTop); | 958 device->setOrigin(ir.fLeft, ir.fTop); |
957 DeviceCM* layer = SkNEW_ARGS(DeviceCM, | 959 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRa
sterClip)); |
958 (device, ir.fLeft, ir.fTop, paint, this, fConse
rvativeRasterClip)); | |
959 device->unref(); | 960 device->unref(); |
960 | 961 |
961 layer->fNext = fMCRec->fTopLayer; | 962 layer->fNext = fMCRec->fTopLayer; |
962 fMCRec->fLayer = layer; | 963 fMCRec->fLayer = layer; |
963 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer | 964 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
964 } | 965 } |
965 | 966 |
966 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { | 967 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { |
967 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag); | 968 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag); |
968 } | 969 } |
(...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2523 } | 2524 } |
2524 | 2525 |
2525 if (matrix) { | 2526 if (matrix) { |
2526 canvas->concat(*matrix); | 2527 canvas->concat(*matrix); |
2527 } | 2528 } |
2528 } | 2529 } |
2529 | 2530 |
2530 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2531 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
2531 fCanvas->restoreToCount(fSaveCount); | 2532 fCanvas->restoreToCount(fSaveCount); |
2532 } | 2533 } |
OLD | NEW |