OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
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 "SkPDFDevice.h" | 8 #include "SkPDFDevice.h" |
9 | 9 |
10 #include "SkAnnotationKeys.h" | 10 #include "SkAnnotationKeys.h" |
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 } | 1153 } |
1154 // recompute dst, based on the smaller tmpSrc | 1154 // recompute dst, based on the smaller tmpSrc |
1155 matrix.mapRect(&tmpDst, tmpSrc); | 1155 matrix.mapRect(&tmpDst, tmpSrc); |
1156 } | 1156 } |
1157 | 1157 |
1158 // since we may need to clamp to the borders of the src rect within | 1158 // since we may need to clamp to the borders of the src rect within |
1159 // the bitmap, we extract a subset. | 1159 // the bitmap, we extract a subset. |
1160 SkIRect srcIR; | 1160 SkIRect srcIR; |
1161 tmpSrc.roundOut(&srcIR); | 1161 tmpSrc.roundOut(&srcIR); |
1162 | 1162 |
1163 autoImageUnref.reset(image->newSubset(srcIR)); | 1163 autoImageUnref = image->makeSubset(srcIR); |
1164 if (!autoImageUnref) { | 1164 if (!autoImageUnref) { |
1165 return; | 1165 return; |
1166 } | 1166 } |
1167 image = autoImageUnref.get(); | 1167 image = autoImageUnref.get(); |
1168 // Since we did an extract, we need to adjust the matrix accordingly | 1168 // Since we did an extract, we need to adjust the matrix accordingly |
1169 SkScalar dx = 0, dy = 0; | 1169 SkScalar dx = 0, dy = 0; |
1170 if (srcIR.fLeft > 0) { | 1170 if (srcIR.fLeft > 0) { |
1171 dx = SkIntToScalar(srcIR.fLeft); | 1171 dx = SkIntToScalar(srcIR.fLeft); |
1172 } | 1172 } |
1173 if (srcIR.fTop > 0) { | 1173 if (srcIR.fTop > 0) { |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2180 SkImageInfo::MakeN32Premul(image->dimensions()))); | 2180 SkImageInfo::MakeN32Premul(image->dimensions()))); |
2181 if (!surface) { | 2181 if (!surface) { |
2182 return image; | 2182 return image; |
2183 } | 2183 } |
2184 SkCanvas* canvas = surface->getCanvas(); | 2184 SkCanvas* canvas = surface->getCanvas(); |
2185 canvas->clear(SK_ColorTRANSPARENT); | 2185 canvas->clear(SK_ColorTRANSPARENT); |
2186 SkPaint paint; | 2186 SkPaint paint; |
2187 paint.setColorFilter(colorFilter); | 2187 paint.setColorFilter(colorFilter); |
2188 canvas->drawImage(image, 0, 0, &paint); | 2188 canvas->drawImage(image, 0, 0, &paint); |
2189 canvas->flush(); | 2189 canvas->flush(); |
2190 return surface->newImageSnapshot(); | 2190 return surface->makeImageSnapshot().release(); |
2191 } | 2191 } |
2192 | 2192 |
2193 //////////////////////////////////////////////////////////////////////////////// | 2193 //////////////////////////////////////////////////////////////////////////////// |
2194 void SkPDFDevice::internalDrawImage(const SkMatrix& origMatrix, | 2194 void SkPDFDevice::internalDrawImage(const SkMatrix& origMatrix, |
2195 const SkClipStack* clipStack, | 2195 const SkClipStack* clipStack, |
2196 const SkRegion& origClipRegion, | 2196 const SkRegion& origClipRegion, |
2197 const SkImage* image, | 2197 const SkImage* image, |
2198 const SkIRect* srcRect, | 2198 const SkIRect* srcRect, |
2199 const SkPaint& paint) { | 2199 const SkPaint& paint) { |
2200 SkASSERT(image); | 2200 SkASSERT(image); |
2201 #ifdef SK_PDF_IMAGE_STATS | 2201 #ifdef SK_PDF_IMAGE_STATS |
2202 gDrawImageCalls.fetch_add(1); | 2202 gDrawImageCalls.fetch_add(1); |
2203 #endif | 2203 #endif |
2204 SkMatrix matrix = origMatrix; | 2204 SkMatrix matrix = origMatrix; |
2205 SkRegion perspectiveBounds; | 2205 SkRegion perspectiveBounds; |
2206 const SkRegion* clipRegion = &origClipRegion; | 2206 const SkRegion* clipRegion = &origClipRegion; |
2207 sk_sp<const SkImage> autoImageUnref; | 2207 sk_sp<const SkImage> autoImageUnref; |
2208 | 2208 |
2209 if (srcRect) { | 2209 if (srcRect) { |
2210 autoImageUnref.reset(image->newSubset(*srcRect)); | 2210 autoImageUnref = image->makeSubset(*srcRect); |
2211 if (!autoImageUnref) { | 2211 if (!autoImageUnref) { |
2212 return; | 2212 return; |
2213 } | 2213 } |
2214 image = autoImageUnref.get(); | 2214 image = autoImageUnref.get(); |
2215 } | 2215 } |
2216 // Rasterize the bitmap using perspective in a new bitmap. | 2216 // Rasterize the bitmap using perspective in a new bitmap. |
2217 if (origMatrix.hasPerspective()) { | 2217 if (origMatrix.hasPerspective()) { |
2218 if (fRasterDpi == 0) { | 2218 if (fRasterDpi == 0) { |
2219 return; | 2219 return; |
2220 } | 2220 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2279 | 2279 |
2280 // In the new space, we use the identity matrix translated | 2280 // In the new space, we use the identity matrix translated |
2281 // and scaled to reflect DPI. | 2281 // and scaled to reflect DPI. |
2282 matrix.setScale(1 / scaleX, 1 / scaleY); | 2282 matrix.setScale(1 / scaleX, 1 / scaleY); |
2283 matrix.postTranslate(deltaX, deltaY); | 2283 matrix.postTranslate(deltaX, deltaY); |
2284 | 2284 |
2285 perspectiveBounds.setRect(bounds.roundOut()); | 2285 perspectiveBounds.setRect(bounds.roundOut()); |
2286 clipRegion = &perspectiveBounds; | 2286 clipRegion = &perspectiveBounds; |
2287 srcRect = nullptr; | 2287 srcRect = nullptr; |
2288 | 2288 |
2289 autoImageUnref.reset(surface->newImageSnapshot()); | 2289 autoImageUnref.reset(surface->makeImageSnapshot().release()); |
2290 image = autoImageUnref.get(); | 2290 image = autoImageUnref.get(); |
2291 } | 2291 } |
2292 | 2292 |
2293 SkMatrix scaled; | 2293 SkMatrix scaled; |
2294 // Adjust for origin flip. | 2294 // Adjust for origin flip. |
2295 scaled.setScale(SK_Scalar1, -SK_Scalar1); | 2295 scaled.setScale(SK_Scalar1, -SK_Scalar1); |
2296 scaled.postTranslate(0, SK_Scalar1); | 2296 scaled.postTranslate(0, SK_Scalar1); |
2297 // Scale the image up from 1x1 to WxH. | 2297 // Scale the image up from 1x1 to WxH. |
2298 SkIRect subset = image->bounds(); | 2298 SkIRect subset = image->bounds(); |
2299 scaled.postScale(SkIntToScalar(image->width()), | 2299 scaled.postScale(SkIntToScalar(image->width()), |
(...skipping 29 matching lines...) Expand all Loading... |
2329 pdfimage.reset(SkPDFCreateBitmapObject( | 2329 pdfimage.reset(SkPDFCreateBitmapObject( |
2330 image, fCanon->getPixelSerializer())); | 2330 image, fCanon->getPixelSerializer())); |
2331 if (!pdfimage) { | 2331 if (!pdfimage) { |
2332 return; | 2332 return; |
2333 } | 2333 } |
2334 fCanon->addPDFBitmap(image->uniqueID(), pdfimage.get()); | 2334 fCanon->addPDFBitmap(image->uniqueID(), pdfimage.get()); |
2335 } | 2335 } |
2336 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), | 2336 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), |
2337 &content.entry()->fContent); | 2337 &content.entry()->fContent); |
2338 } | 2338 } |
OLD | NEW |