Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: src/pdf/SkPDFDevice.cpp

Issue 2146333004: move responsibility for creating raster-device into pdf (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
10 #include "SkAnnotationKeys.h" 9 #include "SkAnnotationKeys.h"
10 #include "SkBitmapDevice.h"
11 #include "SkBitmapKey.h" 11 #include "SkBitmapKey.h"
12 #include "SkColor.h" 12 #include "SkColor.h"
13 #include "SkColorFilter.h" 13 #include "SkColorFilter.h"
14 #include "SkDraw.h" 14 #include "SkDraw.h"
15 #include "SkGlyphCache.h" 15 #include "SkGlyphCache.h"
16 #include "SkPath.h" 16 #include "SkPath.h"
17 #include "SkPathEffect.h" 17 #include "SkPathEffect.h"
18 #include "SkPathOps.h" 18 #include "SkPathOps.h"
19 #include "SkPDFBitmap.h" 19 #include "SkPDFBitmap.h"
20 #include "SkPDFCanon.h" 20 #include "SkPDFCanon.h"
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 // printer resolution. 537 // printer resolution.
538 // TODO: It may be possible to express some filters natively using PDF 538 // TODO: It may be possible to express some filters natively using PDF
539 // to improve quality and file size (https://bug.skia.org/3043) 539 // to improve quality and file size (https://bug.skia.org/3043)
540 540
541 // TODO: should we return true if there is a colorfilter? 541 // TODO: should we return true if there is a colorfilter?
542 return layerPaint.getImageFilter() != nullptr; 542 return layerPaint.getImageFilter() != nullptr;
543 } 543 }
544 544
545 SkBaseDevice* SkPDFDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint * layerPaint) { 545 SkBaseDevice* SkPDFDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint * layerPaint) {
546 if (layerPaint && not_supported_for_layers(*layerPaint)) { 546 if (layerPaint && not_supported_for_layers(*layerPaint)) {
547 return nullptr; 547 // need to return a raster device, which we will detect in drawDevice()
548 return SkBitmapDevice::Create(cinfo.fInfo, SkSurfaceProps(0, kUnknown_Sk PixelGeometry));
548 } 549 }
549 SkISize size = SkISize::Make(cinfo.fInfo.width(), cinfo.fInfo.height()); 550 SkISize size = SkISize::Make(cinfo.fInfo.width(), cinfo.fInfo.height());
550 return SkPDFDevice::Create(size, fRasterDpi, fDocument); 551 return SkPDFDevice::Create(size, fRasterDpi, fDocument);
551 } 552 }
552 553
553 SkPDFCanon* SkPDFDevice::getCanon() const { return fDocument->canon(); } 554 SkPDFCanon* SkPDFDevice::getCanon() const { return fDocument->canon(); }
554 555
555 556
556 557
557 // A helper class to automatically finish a ContentEntry at the end of a 558 // A helper class to automatically finish a ContentEntry at the end of a
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 SkXfermode* xmode, const uint16_t indices[], 1265 SkXfermode* xmode, const uint16_t indices[],
1265 int indexCount, const SkPaint& paint) { 1266 int indexCount, const SkPaint& paint) {
1266 if (d.fRC->isEmpty()) { 1267 if (d.fRC->isEmpty()) {
1267 return; 1268 return;
1268 } 1269 }
1269 // TODO: implement drawVertices 1270 // TODO: implement drawVertices
1270 } 1271 }
1271 1272
1272 void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device, 1273 void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device,
1273 int x, int y, const SkPaint& paint) { 1274 int x, int y, const SkPaint& paint) {
1275 // Check if the source device is really a bitmapdevice (because that's what we returned
1276 // from createDevice (likely due to an imagefilter)
1277 SkPixmap pmap;
1278 if (device->peekPixels(&pmap)) {
1279 SkBitmap bitmap;
1280 bitmap.installPixels(pmap);
1281 if (paint.getImageFilter()) {
1282 this->drawSpriteWithFilter(d, bitmap, x, y, paint);
1283 } else {
1284 this->drawSprite(d, bitmap, x, y, paint);
1285 }
1286 return;
1287 }
1288
1274 // our onCreateCompatibleDevice() always creates SkPDFDevice subclasses. 1289 // our onCreateCompatibleDevice() always creates SkPDFDevice subclasses.
1275 SkPDFDevice* pdfDevice = static_cast<SkPDFDevice*>(device); 1290 SkPDFDevice* pdfDevice = static_cast<SkPDFDevice*>(device);
1276 1291
1277 SkScalar scalarX = SkIntToScalar(x); 1292 SkScalar scalarX = SkIntToScalar(x);
1278 SkScalar scalarY = SkIntToScalar(y); 1293 SkScalar scalarY = SkIntToScalar(y);
1279 for (const RectWithData& l : pdfDevice->fLinkToURLs) { 1294 for (const RectWithData& l : pdfDevice->fLinkToURLs) {
1280 SkRect r = l.rect.makeOffset(scalarX, scalarY); 1295 SkRect r = l.rect.makeOffset(scalarX, scalarY);
1281 fLinkToURLs.emplace_back(r, l.data.get()); 1296 fLinkToURLs.emplace_back(r, l.data.get());
1282 } 1297 }
1283 for (const RectWithData& l : pdfDevice->fLinkToDestinations) { 1298 for (const RectWithData& l : pdfDevice->fLinkToDestinations) {
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
2121 if (!pdfimage) { 2136 if (!pdfimage) {
2122 return; 2137 return;
2123 } 2138 }
2124 fDocument->serialize(pdfimage); // serialize images early. 2139 fDocument->serialize(pdfimage); // serialize images early.
2125 fDocument->canon()->addPDFBitmap(key, pdfimage); 2140 fDocument->canon()->addPDFBitmap(key, pdfimage);
2126 } 2141 }
2127 // TODO(halcanary): addXObjectResource() should take a sk_sp<SkPDFObject> 2142 // TODO(halcanary): addXObjectResource() should take a sk_sp<SkPDFObject>
2128 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()), 2143 SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()),
2129 &content.entry()->fContent); 2144 &content.entry()->fContent);
2130 } 2145 }
OLDNEW
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698