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

Side by Side Diff: samplecode/SampleApp.cpp

Issue 17904006: Add an option to have a PdfViewer in SampleApp. Add a parameter --pdfDir to pass the dir with pdfs.… (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « samplecode/SampleApp.h ('k') | samplecode/SamplePdfFileViewer.cpp » ('j') | 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 #include "SampleApp.h" 7 #include "SampleApp.h"
8 8
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkDevice.h" 11 #include "SkDevice.h"
12 #include "SkGraphics.h" 12 #include "SkGraphics.h"
13 #include "SkImageDecoder.h" 13 #include "SkImageDecoder.h"
14 #include "SkImageEncoder.h" 14 #include "SkImageEncoder.h"
15 #include "SkPaint.h" 15 #include "SkPaint.h"
16 #include "SkPicture.h" 16 #include "SkPicture.h"
17 #include "SkStream.h" 17 #include "SkStream.h"
18 #include "SkTSort.h"
18 #include "SkTime.h" 19 #include "SkTime.h"
19 #include "SkWindow.h" 20 #include "SkWindow.h"
20 21
21 #include "SampleCode.h" 22 #include "SampleCode.h"
22 #include "SkTypeface.h" 23 #include "SkTypeface.h"
23 24
24 #if SK_SUPPORT_GPU 25 #if SK_SUPPORT_GPU
25 #include "gl/GrGLInterface.h" 26 #include "gl/GrGLInterface.h"
26 #include "gl/GrGLUtil.h" 27 #include "gl/GrGLUtil.h"
27 #include "GrRenderTarget.h" 28 #include "GrRenderTarget.h"
(...skipping 19 matching lines...) Expand all
47 48
48 class PictFileFactory : public SkViewFactory { 49 class PictFileFactory : public SkViewFactory {
49 SkString fFilename; 50 SkString fFilename;
50 public: 51 public:
51 PictFileFactory(const SkString& filename) : fFilename(filename) {} 52 PictFileFactory(const SkString& filename) : fFilename(filename) {}
52 virtual SkView* operator() () const SK_OVERRIDE { 53 virtual SkView* operator() () const SK_OVERRIDE {
53 return CreateSamplePictFileView(fFilename.c_str()); 54 return CreateSamplePictFileView(fFilename.c_str());
54 } 55 }
55 }; 56 };
56 57
58 #ifdef SAMPLE_PDF_FILE_VIEWER
59 extern SampleView* CreateSamplePdfFileViewer(const char filename[]);
60
61 class PdfFileViewerFactory : public SkViewFactory {
62 SkString fFilename;
63 public:
64 PdfFileViewerFactory(const SkString& filename) : fFilename(filename) {}
65 virtual SkView* operator() () const SK_OVERRIDE {
66 return CreateSamplePdfFileViewer(fFilename.c_str());
67 }
68 };
69 #endif // SAMPLE_PDF_FILE_VIEWER
70
57 #define PIPE_FILEx 71 #define PIPE_FILEx
58 #ifdef PIPE_FILE 72 #ifdef PIPE_FILE
59 #define FILE_PATH "/path/to/drawing.data" 73 #define FILE_PATH "/path/to/drawing.data"
60 #endif 74 #endif
61 75
62 #define PIPE_NETx 76 #define PIPE_NETx
63 #ifdef PIPE_NET 77 #ifdef PIPE_NET
64 #include "SkSockets.h" 78 #include "SkSockets.h"
65 SkTCPServer gServer; 79 SkTCPServer gServer;
66 #endif 80 #endif
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 #endif // SK_ANGLE 697 #endif // SK_ANGLE
684 SampleWindow::kRaster_DeviceType, // skip the null gpu device in normal cycling 698 SampleWindow::kRaster_DeviceType, // skip the null gpu device in normal cycling
685 #endif // SK_SUPPORT_GPU 699 #endif // SK_SUPPORT_GPU
686 SampleWindow::kRaster_DeviceType 700 SampleWindow::kRaster_DeviceType
687 }; 701 };
688 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array _size_mismatch); 702 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array _size_mismatch);
689 return gCT[ct]; 703 return gCT[ct];
690 } 704 }
691 705
692 static void usage(const char * argv0) { 706 static void usage(const char * argv0) {
693 SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount] [-- pictureDir dirPath] [--picture path]\n", argv0); 707 SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount] [-- pictureDir dirPath] [--picture path] [--sort]\n", argv0);
708 #ifdef SAMPLE_PDF_FILE_VIEWER
709 SkDebugf(" [--pdfDir pdfPath]\n");
710 SkDebugf(" pdfPath: path to directory pdf files are read from\n");
711 #endif // SAMPLE_PDF_FILE_VIEWER
694 SkDebugf(" sampleName: sample at which to start.\n"); 712 SkDebugf(" sampleName: sample at which to start.\n");
695 SkDebugf(" resourcePath: directory that stores image resources.\n"); 713 SkDebugf(" resourcePath: directory that stores image resources.\n");
696 SkDebugf(" msaa: request multisampling with the given sample count.\n"); 714 SkDebugf(" msaa: request multisampling with the given sample count.\n");
697 SkDebugf(" dirPath: path to directory skia pictures are read from\n"); 715 SkDebugf(" dirPath: path to directory skia pictures are read from\n");
698 SkDebugf(" path: path to skia picture\n"); 716 SkDebugf(" path: path to skia picture\n");
717 SkDebugf(" --sort: sort samples by title, this would help to compare pdf rendering (P:foo.pdf) with skp rendering (P:foo.pdf)\n");
718 }
719
720 static SkString getSampleTitle(const SkViewFactory* sampleFactory) {
721 SkView* view = (*sampleFactory)();
722 SkString title;
723 SampleCode::RequestTitle(view, &title);
724 view->unref();
725 return title;
726 }
727
728 bool compareSampleTitle(const SkViewFactory* first, const SkViewFactory* second) {
729 return strcmp(getSampleTitle(first).c_str(), getSampleTitle(second).c_str()) < 0;
699 } 730 }
700 731
701 SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev Manager) 732 SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev Manager)
702 : INHERITED(hwnd) 733 : INHERITED(hwnd)
703 , fDevManager(NULL) { 734 , fDevManager(NULL) {
704 735
705 fCurrIndex = -1; 736 fCurrIndex = -1;
706 737
707 this->registerPictFileSamples(argv, argc); 738 this->registerPictFileSamples(argv, argc);
708 this->registerPictFileSample(argv, argc); 739 this->registerPictFileSample(argv, argc);
740 #ifdef SAMPLE_PDF_FILE_VIEWER
741 this->registerPdfFileViewerSamples(argv, argc);
742 #endif // SAMPLE_PDF_FILE_VIEWER
709 SkGMRegistyToSampleRegistry(); 743 SkGMRegistyToSampleRegistry();
710 { 744 {
711 const SkViewRegister* reg = SkViewRegister::Head(); 745 const SkViewRegister* reg = SkViewRegister::Head();
712 while (reg) { 746 while (reg) {
713 *fSamples.append() = reg->factory(); 747 *fSamples.append() = reg->factory();
714 reg = reg->next(); 748 reg = reg->next();
715 } 749 }
716 } 750 }
717 751
752 bool sort = false;
753 for (int i = 0; i < argc; ++i) {
754 if (!strcmp(argv[i], "--sort")) {
755 sort = true;
756 break;
757 }
758 }
759
760 if (sort) {
761 // Sort samples, so foo.skp and foo.pdf are consecutive and we can quick ly spot where
762 // skp -> pdf -> png fails.
763 SkTQSort(fSamples.begin(), fSamples.end() ? fSamples.end() - 1 : NULL, c ompareSampleTitle);
764 }
765
718 const char* resourcePath = NULL; 766 const char* resourcePath = NULL;
719 fMSAASampleCount = 0; 767 fMSAASampleCount = 0;
720 768
721 const char* const commandName = argv[0]; 769 const char* const commandName = argv[0];
722 char* const* stop = argv + argc; 770 char* const* stop = argv + argc;
723 for (++argv; argv < stop; ++argv) { 771 for (++argv; argv < stop; ++argv) {
724 if (strcmp(*argv, "-i") == 0) { 772 if (strcmp(*argv, "-i") == 0) {
725 argv++; 773 argv++;
726 if (argv < stop && **argv) { 774 if (argv < stop && **argv) {
727 resourcePath = *argv; 775 resourcePath = *argv;
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 SkOSFile::Iter iter(pictDir, "skp"); 1010 SkOSFile::Iter iter(pictDir, "skp");
963 SkString filename; 1011 SkString filename;
964 while (iter.next(&filename)) { 1012 while (iter.next(&filename)) {
965 SkString path; 1013 SkString path;
966 make_filepath(&path, pictDir, filename); 1014 make_filepath(&path, pictDir, filename);
967 *fSamples.append() = new PictFileFactory(path); 1015 *fSamples.append() = new PictFileFactory(path);
968 } 1016 }
969 } 1017 }
970 } 1018 }
971 1019
1020 #ifdef SAMPLE_PDF_FILE_VIEWER
1021 void SampleWindow::registerPdfFileViewerSamples(char** argv, int argc) {
1022 const char* pdfDir = NULL;
1023
1024 for (int i = 0; i < argc; ++i) {
1025 if (!strcmp(argv[i], "--pdfDir")) {
1026 i += 1;
1027 if (i < argc) {
1028 pdfDir = argv[i];
1029 break;
1030 }
1031 }
1032 }
1033 if (pdfDir) {
1034 SkOSFile::Iter iter(pdfDir, "pdf");
1035 SkString filename;
1036 while (iter.next(&filename)) {
1037 SkString path;
1038 make_filepath(&path, pdfDir, filename);
1039 *fSamples.append() = new PdfFileViewerFactory(path);
1040 }
1041 }
1042 }
1043 #endif // SAMPLE_PDF_FILE_VIEWER
1044
1045
972 int SampleWindow::findByTitle(const char title[]) { 1046 int SampleWindow::findByTitle(const char title[]) {
973 int i, count = fSamples.count(); 1047 int i, count = fSamples.count();
974 for (i = 0; i < count; i++) { 1048 for (i = 0; i < count; i++) {
975 if (getSampleTitle(i).equals(title)) { 1049 if (getSampleTitle(i).equals(title)) {
976 return i; 1050 return i;
977 } 1051 }
978 } 1052 }
979 return -1; 1053 return -1;
980 } 1054 }
981 1055
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 return true; 1601 return true;
1528 } 1602 }
1529 1603
1530 bool SampleWindow::goToSample(int i) { 1604 bool SampleWindow::goToSample(int i) {
1531 fCurrIndex = (i) % fSamples.count(); 1605 fCurrIndex = (i) % fSamples.count();
1532 this->loadView(create_transition(curr_view(this),(*fSamples[fCurrIndex])(), 6)); 1606 this->loadView(create_transition(curr_view(this),(*fSamples[fCurrIndex])(), 6));
1533 return true; 1607 return true;
1534 } 1608 }
1535 1609
1536 SkString SampleWindow::getSampleTitle(int i) { 1610 SkString SampleWindow::getSampleTitle(int i) {
1537 SkView* view = (*fSamples[i])(); 1611 return ::getSampleTitle(fSamples[i]);
1538 SkString title;
1539 SampleCode::RequestTitle(view, &title);
1540 view->unref();
1541 return title;
1542 } 1612 }
1543 1613
1544 int SampleWindow::sampleCount() { 1614 int SampleWindow::sampleCount() {
1545 return fSamples.count(); 1615 return fSamples.count();
1546 } 1616 }
1547 1617
1548 void SampleWindow::showOverview() { 1618 void SampleWindow::showOverview() {
1549 this->loadView(create_transition(curr_view(this), 1619 this->loadView(create_transition(curr_view(this),
1550 create_overview(fSamples.count(), fSamples. begin()), 1620 create_overview(fSamples.count(), fSamples. begin()),
1551 4)); 1621 4));
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
2468 SkGraphics::Init(); 2538 SkGraphics::Init();
2469 SkEvent::Init(); 2539 SkEvent::Init();
2470 } 2540 }
2471 2541
2472 // FIXME: this should be in a header 2542 // FIXME: this should be in a header
2473 void application_term(); 2543 void application_term();
2474 void application_term() { 2544 void application_term() {
2475 SkEvent::Term(); 2545 SkEvent::Term();
2476 SkGraphics::Term(); 2546 SkGraphics::Term();
2477 } 2547 }
OLDNEW
« no previous file with comments | « samplecode/SampleApp.h ('k') | samplecode/SamplePdfFileViewer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698