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" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 return true; | 103 return true; |
104 } | 104 } |
105 | 105 |
106 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); | 106 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); |
107 if (NULL == device.get()) { | 107 if (NULL == device.get()) { |
108 return false; | 108 return false; |
109 } | 109 } |
110 | 110 |
111 if (kDeviceSpace_PictureResolution == fPictureResolution || | 111 if (kDeviceSpace_PictureResolution == fPictureResolution || |
112 0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) { | 112 0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) { |
113 drawPictureAtDeviceResolution(proxy, device.get(), bounds, ctx); | 113 this->drawPictureAtDeviceResolution(device.get(), bounds, ctx); |
114 } else { | 114 } else { |
115 drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx); | 115 this->drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx); |
116 } | 116 } |
117 | 117 |
118 *result = device.get()->accessBitmap(false); | 118 *result = device.get()->accessBitmap(false); |
119 offset->fX = bounds.fLeft; | 119 offset->fX = bounds.fLeft; |
120 offset->fY = bounds.fTop; | 120 offset->fY = bounds.fTop; |
121 return true; | 121 return true; |
122 } | 122 } |
123 | 123 |
124 void SkPictureImageFilter::drawPictureAtDeviceResolution(Proxy* proxy, SkBaseDev
ice* device, | 124 void SkPictureImageFilter::drawPictureAtDeviceResolution(SkBaseDevice* device, |
125 const SkIRect& deviceBo
unds, | 125 const SkIRect& deviceBo
unds, |
126 const Context& ctx) con
st { | 126 const Context& ctx) con
st { |
127 // Pass explicit surface props, as the simplified canvas constructor discard
s device properties. | 127 SkCanvas canvas(device); |
128 // FIXME: switch back to the public constructor (and unfriend) after | |
129 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed. | |
130 SkCanvas canvas(device, &proxy->surfaceProps(), SkCanvas::kDefault_InitFlags
); | |
131 | 128 |
132 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo
unds.fTop)); | 129 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo
unds.fTop)); |
133 canvas.concat(ctx.ctm()); | 130 canvas.concat(ctx.ctm()); |
134 canvas.drawPicture(fPicture); | 131 canvas.drawPicture(fPicture); |
135 } | 132 } |
136 | 133 |
137 void SkPictureImageFilter::drawPictureAtLocalResolution(Proxy* proxy, SkBaseDevi
ce* device, | 134 void SkPictureImageFilter::drawPictureAtLocalResolution(Proxy* proxy, SkBaseDevi
ce* device, |
138 const SkIRect& deviceBou
nds, | 135 const SkIRect& deviceBou
nds, |
139 const Context& ctx) cons
t { | 136 const Context& ctx) cons
t { |
140 SkMatrix inverseCtm; | 137 SkMatrix inverseCtm; |
141 if (!ctx.ctm().invert(&inverseCtm)) | 138 if (!ctx.ctm().invert(&inverseCtm)) { |
142 return; | 139 return; |
| 140 } |
| 141 |
143 SkRect localBounds = SkRect::Make(ctx.clipBounds()); | 142 SkRect localBounds = SkRect::Make(ctx.clipBounds()); |
144 inverseCtm.mapRect(&localBounds); | 143 inverseCtm.mapRect(&localBounds); |
145 if (!localBounds.intersect(fCropRect)) | 144 if (!localBounds.intersect(fCropRect)) { |
146 return; | 145 return; |
| 146 } |
147 SkIRect localIBounds = localBounds.roundOut(); | 147 SkIRect localIBounds = localBounds.roundOut(); |
148 SkAutoTUnref<SkBaseDevice> localDevice(proxy->createDevice(localIBounds.widt
h(), localIBounds.height())); | 148 SkAutoTUnref<SkBaseDevice> localDevice(proxy->createDevice(localIBounds.widt
h(), localIBounds.height())); |
149 | 149 |
150 // Pass explicit surface props, as the simplified canvas constructor discard
s device properties. | 150 SkCanvas localCanvas(localDevice); |
151 // FIXME: switch back to the public constructor (and unfriend) after | |
152 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed. | |
153 SkCanvas localCanvas(localDevice, &proxy->surfaceProps(), SkCanvas::kDefault
_InitFlags); | |
154 localCanvas.translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(loc
alIBounds.fTop)); | 151 localCanvas.translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(loc
alIBounds.fTop)); |
155 localCanvas.drawPicture(fPicture); | 152 localCanvas.drawPicture(fPicture); |
156 | 153 |
157 // Pass explicit surface props, as the simplified canvas constructor discard
s device properties. | 154 SkCanvas canvas(device); |
158 // FIXME: switch back to the public constructor (and unfriend) after | |
159 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed. | |
160 SkCanvas canvas(device, &proxy->surfaceProps(), SkCanvas::kDefault_InitFlags
); | |
161 | 155 |
162 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo
unds.fTop)); | 156 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo
unds.fTop)); |
163 canvas.concat(ctx.ctm()); | 157 canvas.concat(ctx.ctm()); |
164 SkPaint paint; | 158 SkPaint paint; |
165 paint.setFilterQuality(fFilterQuality); | 159 paint.setFilterQuality(fFilterQuality); |
166 canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(loca
lIBounds.fLeft), | 160 canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(loca
lIBounds.fLeft), |
167 SkIntToScalar(localIBounds.fTop), &paint); | 161 SkIntToScalar(localIBounds.fTop), &paint); |
168 //canvas.drawPicture(fPicture); | |
169 } | 162 } |
170 | 163 |
171 #ifndef SK_IGNORE_TO_STRING | 164 #ifndef SK_IGNORE_TO_STRING |
172 void SkPictureImageFilter::toString(SkString* str) const { | 165 void SkPictureImageFilter::toString(SkString* str) const { |
173 str->appendf("SkPictureImageFilter: ("); | 166 str->appendf("SkPictureImageFilter: ("); |
174 str->appendf("crop: (%f,%f,%f,%f) ", | 167 str->appendf("crop: (%f,%f,%f,%f) ", |
175 fCropRect.fLeft, fCropRect.fTop, fCropRect.fRight, fCropRect.fB
ottom); | 168 fCropRect.fLeft, fCropRect.fTop, fCropRect.fRight, fCropRect.fB
ottom); |
176 if (fPicture) { | 169 if (fPicture) { |
177 str->appendf("picture: (%f,%f,%f,%f)", | 170 str->appendf("picture: (%f,%f,%f,%f)", |
178 fPicture->cullRect().fLeft, fPicture->cullRect().fTop, | 171 fPicture->cullRect().fLeft, fPicture->cullRect().fTop, |
179 fPicture->cullRect().fRight, fPicture->cullRect().fBottom); | 172 fPicture->cullRect().fRight, fPicture->cullRect().fBottom); |
180 } | 173 } |
181 str->append(")"); | 174 str->append(")"); |
182 } | 175 } |
183 #endif | 176 #endif |
OLD | NEW |