| 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 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1405 // Canvas promises that this ptr is valid until onDetachFromCanvas is called | 1405 // Canvas promises that this ptr is valid until onDetachFromCanvas is called |
| 1406 fClipStack = canvas->getClipStack(); | 1406 fClipStack = canvas->getClipStack(); |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 void SkPDFDevice::onDetachFromCanvas() { | 1409 void SkPDFDevice::onDetachFromCanvas() { |
| 1410 INHERITED::onDetachFromCanvas(); | 1410 INHERITED::onDetachFromCanvas(); |
| 1411 | 1411 |
| 1412 fClipStack = nullptr; | 1412 fClipStack = nullptr; |
| 1413 } | 1413 } |
| 1414 | 1414 |
| 1415 SkSurface* SkPDFDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps
& props) { | 1415 sk_sp<SkSurface> SkPDFDevice::makeSurface(const SkImageInfo& info, const SkSurfa
ceProps& props) { |
| 1416 return SkSurface::NewRaster(info, &props); | 1416 return SkSurface::MakeRaster(info, &props); |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 ContentEntry* SkPDFDevice::getLastContentEntry() { | 1419 ContentEntry* SkPDFDevice::getLastContentEntry() { |
| 1420 if (fDrawingArea == kContent_DrawingArea) { | 1420 if (fDrawingArea == kContent_DrawingArea) { |
| 1421 return fLastContentEntry; | 1421 return fLastContentEntry; |
| 1422 } else { | 1422 } else { |
| 1423 return fLastMarginContentEntry; | 1423 return fLastMarginContentEntry; |
| 1424 } | 1424 } |
| 1425 } | 1425 } |
| 1426 | 1426 |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2108 newFont.get()->ref(); | 2108 newFont.get()->ref(); |
| 2109 } | 2109 } |
| 2110 return resourceIndex; | 2110 return resourceIndex; |
| 2111 } | 2111 } |
| 2112 | 2112 |
| 2113 static SkSize rect_to_size(const SkRect& r) { | 2113 static SkSize rect_to_size(const SkRect& r) { |
| 2114 return SkSize::Make(r.width(), r.height()); | 2114 return SkSize::Make(r.width(), r.height()); |
| 2115 } | 2115 } |
| 2116 | 2116 |
| 2117 static const SkImage* color_filter(const SkImage* image, SkColorFilter* colorFil
ter) { | 2117 static const SkImage* color_filter(const SkImage* image, SkColorFilter* colorFil
ter) { |
| 2118 sk_sp<SkSurface> surface(SkSurface::NewRaster( | 2118 auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(image->dimensi
ons()))); |
| 2119 SkImageInfo::MakeN32Premul(image->dimensions()))); | |
| 2120 if (!surface) { | 2119 if (!surface) { |
| 2121 return image; | 2120 return image; |
| 2122 } | 2121 } |
| 2123 SkCanvas* canvas = surface->getCanvas(); | 2122 SkCanvas* canvas = surface->getCanvas(); |
| 2124 canvas->clear(SK_ColorTRANSPARENT); | 2123 canvas->clear(SK_ColorTRANSPARENT); |
| 2125 SkPaint paint; | 2124 SkPaint paint; |
| 2126 paint.setColorFilter(sk_ref_sp(colorFilter)); | 2125 paint.setColorFilter(sk_ref_sp(colorFilter)); |
| 2127 canvas->drawImage(image, 0, 0, &paint); | 2126 canvas->drawImage(image, 0, 0, &paint); |
| 2128 canvas->flush(); | 2127 canvas->flush(); |
| 2129 return surface->makeImageSnapshot().release(); | 2128 return surface->makeImageSnapshot().release(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2187 | 2186 |
| 2188 // TODO(edisonn): A better approach would be to use a bitmap shader | 2187 // TODO(edisonn): A better approach would be to use a bitmap shader |
| 2189 // (in clamp mode) and draw a rect over the entire bounding box. Then | 2188 // (in clamp mode) and draw a rect over the entire bounding box. Then |
| 2190 // intersect perspectiveOutline to the clip. That will avoid introducing | 2189 // intersect perspectiveOutline to the clip. That will avoid introducing |
| 2191 // alpha to the image while still giving good behavior at the edge of | 2190 // alpha to the image while still giving good behavior at the edge of |
| 2192 // the image. Avoiding alpha will reduce the pdf size and generation | 2191 // the image. Avoiding alpha will reduce the pdf size and generation |
| 2193 // CPU time some. | 2192 // CPU time some. |
| 2194 | 2193 |
| 2195 SkISize wh = rect_to_size(physicalPerspectiveBounds).toCeil(); | 2194 SkISize wh = rect_to_size(physicalPerspectiveBounds).toCeil(); |
| 2196 | 2195 |
| 2197 sk_sp<SkSurface> surface( | 2196 auto surface(SkSurface::MakeRaster(SkImageInfo::MakeN32Premul(wh))); |
| 2198 SkSurface::NewRaster(SkImageInfo::MakeN32Premul(wh))); | |
| 2199 if (!surface) { | 2197 if (!surface) { |
| 2200 return; | 2198 return; |
| 2201 } | 2199 } |
| 2202 SkCanvas* canvas = surface->getCanvas(); | 2200 SkCanvas* canvas = surface->getCanvas(); |
| 2203 canvas->clear(SK_ColorTRANSPARENT); | 2201 canvas->clear(SK_ColorTRANSPARENT); |
| 2204 | 2202 |
| 2205 SkScalar deltaX = bounds.left(); | 2203 SkScalar deltaX = bounds.left(); |
| 2206 SkScalar deltaY = bounds.top(); | 2204 SkScalar deltaY = bounds.top(); |
| 2207 | 2205 |
| 2208 SkMatrix offsetMatrix = origMatrix; | 2206 SkMatrix offsetMatrix = origMatrix; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2274 sk_sp<SkData> encodedImage(image->refEncodedData()); | 2272 sk_sp<SkData> encodedImage(image->refEncodedData()); |
| 2275 if (!encodedImage) { | 2273 if (!encodedImage) { |
| 2276 fDocument->serialize(pdfimage); | 2274 fDocument->serialize(pdfimage); |
| 2277 } | 2275 } |
| 2278 #endif | 2276 #endif |
| 2279 fDocument->canon()->addPDFBitmap(image->uniqueID(), pdfimage.get()); | 2277 fDocument->canon()->addPDFBitmap(image->uniqueID(), pdfimage.get()); |
| 2280 } | 2278 } |
| 2281 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), | 2279 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), |
| 2282 &content.entry()->fContent); | 2280 &content.entry()->fContent); |
| 2283 } | 2281 } |
| OLD | NEW |