OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The Android Open Source Project | 2 * Copyright 2013 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 "SkPictureImageFilter.h" | 8 #include "SkPictureImageFilter.h" |
9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
12 #include "SkSurfaceProps.h" | 12 #include "SkSurfaceProps.h" |
13 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
14 #include "SkValidationUtils.h" | 14 #include "SkValidationUtils.h" |
15 | 15 |
16 SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture) | 16 SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture) |
17 : INHERITED(0, 0, nullptr) | 17 : INHERITED(0, 0, nullptr) |
18 , fPicture(std::move(picture)) | 18 , fPicture(std::move(picture)) |
19 , fCropRect(fPicture ? fPicture->cullRect() : SkRect::MakeEmpty()) | 19 , fCropRect(fPicture ? fPicture->cullRect() : SkRect::MakeEmpty()) |
20 , fPictureResolution(kDeviceSpace_PictureResolution) | 20 , fPictureResolution(kDeviceSpace_PictureResolution) |
21 , fFilterQuality(kLow_SkFilterQuality) { | 21 , fFilterQuality(kLow_SkFilterQuality) { |
22 } | 22 } |
23 | 23 |
24 SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRec
t& cropRect, | 24 SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRec
t& cropRect, |
25 PictureResolution pictureResolution, | 25 PictureResolution pictureResolution, |
26 SkFilterQuality filterQuality) | 26 SkFilterQuality filterQuality) |
27 : INHERITED(0, 0, nullptr) | 27 : INHERITED(0, 0, nullptr) |
28 , fPicture(std::move(picture)) | 28 , fPicture(std::move(picture)) |
29 , fCropRect(cropRect) | 29 , fCropRect(cropRect) |
30 , fPictureResolution(pictureResolution) | 30 , fPictureResolution(pictureResolution) |
(...skipping 10 matching lines...) Expand all Loading... |
41 if (buffer.readBool()) { | 41 if (buffer.readBool()) { |
42 picture = SkPicture::MakeFromBuffer(buffer); | 42 picture = SkPicture::MakeFromBuffer(buffer); |
43 } | 43 } |
44 } | 44 } |
45 buffer.readRect(&cropRect); | 45 buffer.readRect(&cropRect); |
46 PictureResolution pictureResolution; | 46 PictureResolution pictureResolution; |
47 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterResolution_Version))
{ | 47 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterResolution_Version))
{ |
48 pictureResolution = kDeviceSpace_PictureResolution; | 48 pictureResolution = kDeviceSpace_PictureResolution; |
49 } else { | 49 } else { |
50 pictureResolution = (PictureResolution)buffer.readInt(); | 50 pictureResolution = (PictureResolution)buffer.readInt(); |
51 } | 51 } |
52 | 52 |
53 if (kLocalSpace_PictureResolution == pictureResolution) { | 53 if (kLocalSpace_PictureResolution == pictureResolution) { |
54 //filterLevel is only serialized if pictureResolution is LocalSpace | 54 //filterLevel is only serialized if pictureResolution is LocalSpace |
55 SkFilterQuality filterQuality; | 55 SkFilterQuality filterQuality; |
56 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterLevel_Version))
{ | 56 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterLevel_Version))
{ |
57 filterQuality = kLow_SkFilterQuality; | 57 filterQuality = kLow_SkFilterQuality; |
58 } else { | 58 } else { |
59 filterQuality = (SkFilterQuality)buffer.readInt(); | 59 filterQuality = (SkFilterQuality)buffer.readInt(); |
60 } | 60 } |
61 return MakeForLocalSpace(picture, cropRect, filterQuality).release(); | 61 return MakeForLocalSpace(picture, cropRect, filterQuality).release(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 if (bounds.isEmpty()) { | 98 if (bounds.isEmpty()) { |
99 offset->fX = offset->fY = 0; | 99 offset->fX = offset->fY = 0; |
100 return true; | 100 return true; |
101 } | 101 } |
102 | 102 |
103 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); | 103 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); |
104 if (nullptr == device.get()) { | 104 if (nullptr == device.get()) { |
105 return false; | 105 return false; |
106 } | 106 } |
107 | 107 |
108 if (kDeviceSpace_PictureResolution == fPictureResolution || | 108 if (kDeviceSpace_PictureResolution == fPictureResolution || |
109 0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) { | 109 0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) { |
110 this->drawPictureAtDeviceResolution(device.get(), bounds, ctx); | 110 this->drawPictureAtDeviceResolution(device.get(), bounds, ctx); |
111 } else { | 111 } else { |
112 this->drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx); | 112 this->drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx); |
113 } | 113 } |
114 | 114 |
115 *result = device.get()->accessBitmap(false); | 115 *result = device.get()->accessBitmap(false); |
116 offset->fX = bounds.fLeft; | 116 offset->fX = bounds.fLeft; |
117 offset->fY = bounds.fTop; | 117 offset->fY = bounds.fTop; |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 canvas.concat(ctx.ctm()); | 154 canvas.concat(ctx.ctm()); |
155 SkPaint paint; | 155 SkPaint paint; |
156 paint.setFilterQuality(fFilterQuality); | 156 paint.setFilterQuality(fFilterQuality); |
157 canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(loca
lIBounds.fLeft), | 157 canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(loca
lIBounds.fLeft), |
158 SkIntToScalar(localIBounds.fTop), &paint); | 158 SkIntToScalar(localIBounds.fTop), &paint); |
159 } | 159 } |
160 | 160 |
161 #ifndef SK_IGNORE_TO_STRING | 161 #ifndef SK_IGNORE_TO_STRING |
162 void SkPictureImageFilter::toString(SkString* str) const { | 162 void SkPictureImageFilter::toString(SkString* str) const { |
163 str->appendf("SkPictureImageFilter: ("); | 163 str->appendf("SkPictureImageFilter: ("); |
164 str->appendf("crop: (%f,%f,%f,%f) ", | 164 str->appendf("crop: (%f,%f,%f,%f) ", |
165 fCropRect.fLeft, fCropRect.fTop, fCropRect.fRight, fCropRect.fB
ottom); | 165 fCropRect.fLeft, fCropRect.fTop, fCropRect.fRight, fCropRect.fB
ottom); |
166 if (fPicture) { | 166 if (fPicture) { |
167 str->appendf("picture: (%f,%f,%f,%f)", | 167 str->appendf("picture: (%f,%f,%f,%f)", |
168 fPicture->cullRect().fLeft, fPicture->cullRect().fTop, | 168 fPicture->cullRect().fLeft, fPicture->cullRect().fTop, |
169 fPicture->cullRect().fRight, fPicture->cullRect().fBottom); | 169 fPicture->cullRect().fRight, fPicture->cullRect().fBottom); |
170 } | 170 } |
171 str->append(")"); | 171 str->append(")"); |
172 } | 172 } |
173 #endif | 173 #endif |
OLD | NEW |