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

Side by Side Diff: experimental/PdfViewer/SkPdfRenderer.cpp

Issue 21537003: pdfviewer: remove simple implementation for non-isolated groups. will be implemented in skia most p… (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 2013 Google Inc. 2 * Copyright 2013 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkForceLinking.h" 10 #include "SkForceLinking.h"
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 // CON: multiple drawings (but on smaller areas), pay a price at loading pdf to compute a pdf draw plan 643 // CON: multiple drawings (but on smaller areas), pay a price at loading pdf to compute a pdf draw plan
644 // on average, a load with empty draw is 100ms on all the skps we have, for complete sites 644 // on average, a load with empty draw is 100ms on all the skps we have, for complete sites
645 // 3) support them natively in SkCanvas 645 // 3) support them natively in SkCanvas
646 // PRO: simple 646 // PRO: simple
647 // CON: we would still need to use a form of readPixels anyway, so perf migh t be the same as 1) 647 // CON: we would still need to use a form of readPixels anyway, so perf migh t be the same as 1)
648 // 4) compile a plan using pathops, and render once without any fancy rules with backdrop 648 // 4) compile a plan using pathops, and render once without any fancy rules with backdrop
649 // PRO: simple, fast 649 // PRO: simple, fast
650 // CON: pathops must be bug free first + time to compute new paths 650 // CON: pathops must be bug free first + time to compute new paths
651 // pay a price at loading pdf to compute a pdf draw plan 651 // pay a price at loading pdf to compute a pdf draw plan
652 // on average, a load with empty draw is 100ms on all the skps we have, for complete sites 652 // on average, a load with empty draw is 100ms on all the skps we have, for complete sites
653 // 5) for knockout, render the objects in reverse order, and add every object to the clip, and any new draw will be cliped
653 654
654 655
655 // TODO(edisonn): draw plan from point! - list of draw ops of a point, like a tr ee! 656 // TODO(edisonn): draw plan from point! - list of draw ops of a point, like a tr ee!
656 // TODO(edisonn): Minimal PDF to draw some points - remove everything that it is not needed, save pdf uncompressed 657 // TODO(edisonn): Minimal PDF to draw some points - remove everything that it is not needed, save pdf uncompressed
657 658
658 659
659 660
660 static void doGroup_before(PdfContext* pdfContext, SkCanvas* canvas, SkRect bbox , SkPdfTransparencyGroupDictionary* tgroup, bool page) { 661 static void doGroup_before(PdfContext* pdfContext, SkCanvas* canvas, SkRect bbox , SkPdfTransparencyGroupDictionary* tgroup, bool page) {
661 SkRect bboxOrig = bbox; 662 SkRect bboxOrig = bbox;
662 SkBitmap backdrop; 663 SkBitmap backdrop;
663 bool isolatedGroup = tgroup->I(pdfContext->fPdfDoc); 664 bool isolatedGroup = tgroup->I(pdfContext->fPdfDoc);
664 // bool knockoutGroup = tgroup->K(pdfContext->fPdfDoc); 665 // bool knockoutGroup = tgroup->K(pdfContext->fPdfDoc);
665 bool hasPixels = false;
666 if (!isolatedGroup) {
667 // TODO(edisonn): if the rect is not mapable, the operation could be exp ensive, e.g.
668 // a diagonal long but small rect would require to save all the page
669 SkMatrix inverse;
670 if (pdfContext->fGraphicsState.fCTM.mapRect(&bbox) &&
671 canvas->getTotalMatrix().invert(&inverse) &&
672 inverse.mapRect(&bbox)) {
673 SkIRect area = SkIRect::MakeLTRB(SkScalarTruncToInt(bbox.left()),
674 SkScalarTruncToInt(bbox.top()),
675 SkScalarTruncToInt(bbox.right()) + 2,
676 SkScalarTruncToInt(bbox.bottom()) + 2);
677 SkBitmap dummy;
678 if (canvas->readPixels(area, &dummy)) {
679 hasPixels = true;
680 }
681 }
682 }
683 SkPaint paint; 666 SkPaint paint;
684 pdfContext->fGraphicsState.applyGraphicsState(&paint, false); 667 pdfContext->fGraphicsState.applyGraphicsState(&paint, false);
685 canvas->saveLayer(&bboxOrig, isolatedGroup ? &paint : NULL); 668 canvas->saveLayer(&bboxOrig, isolatedGroup ? &paint : NULL);
686
687 if (hasPixels) {
688 canvas->drawBitmapRect(backdrop, bboxOrig, NULL);
689 }
690 } 669 }
691 670
671 // TODO(edisonn): non isolation implemented in skia
692 //static void doGroup_after(PdfContext* pdfContext, SkCanvas* canvas, SkRect bbo x, SkPdfTransparencyGroupDictionary* tgroup) { 672 //static void doGroup_after(PdfContext* pdfContext, SkCanvas* canvas, SkRect bbo x, SkPdfTransparencyGroupDictionary* tgroup) {
673 // if not isolated
674 // canvas->drawBitmapRect(backdrop, bboxOrig, NULL);
693 //} 675 //}
694 676
695 static PdfResult doXObject_Form(PdfContext* pdfContext, SkCanvas* canvas, SkPdfT ype1FormDictionary* skobj) { 677 static PdfResult doXObject_Form(PdfContext* pdfContext, SkCanvas* canvas, SkPdfT ype1FormDictionary* skobj) {
696 if (!skobj || !skobj->hasStream()) { 678 if (!skobj || !skobj->hasStream()) {
697 return kIgnoreError_PdfResult; 679 return kIgnoreError_PdfResult;
698 } 680 }
699 681
700 if (!skobj->has_BBox()) { 682 if (!skobj->has_BBox()) {
701 return kIgnoreError_PdfResult; 683 return kIgnoreError_PdfResult;
702 } 684 }
703 685
704 PdfOp_q(pdfContext, canvas, NULL); 686 PdfOp_q(pdfContext, canvas, NULL);
705 687
706
707
708 canvas->save(); 688 canvas->save();
709 689
710 690
711 if (skobj->Resources(pdfContext->fPdfDoc)) { 691 if (skobj->Resources(pdfContext->fPdfDoc)) {
712 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd fDoc); 692 pdfContext->fGraphicsState.fResources = skobj->Resources(pdfContext->fPd fDoc);
713 } 693 }
714 694
715 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Current matrix"); 695 SkTraceMatrix(pdfContext->fGraphicsState.fCTM, "Current matrix");
716 696
717 if (skobj->has_Matrix()) { 697 if (skobj->has_Matrix()) {
(...skipping 1745 matching lines...) Expand 10 before | Expand all | Expand 10 after
2463 2443
2464 rect = SkRect::MakeWH(width, height); 2444 rect = SkRect::MakeWH(width, height);
2465 2445
2466 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght)); 2446 setup_bitmap(output, (int)SkScalarToDouble(width), (int)SkScalarToDouble(hei ght));
2467 2447
2468 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output))); 2448 SkAutoTUnref<SkDevice> device(SkNEW_ARGS(SkDevice, (*output)));
2469 SkCanvas canvas(device); 2449 SkCanvas canvas(device);
2470 2450
2471 return renderer.renderPage(page, &canvas, rect); 2451 return renderer.renderPage(page, &canvas, rect);
2472 } 2452 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698