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

Side by Side Diff: samplecode/SampleApp.cpp

Issue 2201323003: add pipecanvas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add test for writeImage Created 4 years, 3 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
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 "SampleApp.h" 8 #include "SampleApp.h"
9 9
10 #include "OverView.h" 10 #include "OverView.h"
(...skipping 16 matching lines...) Expand all
27 #include "SkPM4fPriv.h" 27 #include "SkPM4fPriv.h"
28 #include "SkStream.h" 28 #include "SkStream.h"
29 #include "SkSurface.h" 29 #include "SkSurface.h"
30 #include "SkTemplates.h" 30 #include "SkTemplates.h"
31 #include "SkTSort.h" 31 #include "SkTSort.h"
32 #include "SkTime.h" 32 #include "SkTime.h"
33 #include "SkTypeface.h" 33 #include "SkTypeface.h"
34 #include "SkWindow.h" 34 #include "SkWindow.h"
35 #include "sk_tool_utils.h" 35 #include "sk_tool_utils.h"
36 36
37 #include "SkReadBuffer.h"
38 #include "SkStream.h"
39
37 #if SK_SUPPORT_GPU 40 #if SK_SUPPORT_GPU
38 # include "gl/GrGLInterface.h" 41 # include "gl/GrGLInterface.h"
39 # include "gl/GrGLUtil.h" 42 # include "gl/GrGLUtil.h"
40 # include "GrContext.h" 43 # include "GrContext.h"
41 # include "SkGr.h" 44 # include "SkGr.h"
42 # if SK_ANGLE 45 # if SK_ANGLE
43 # include "gl/angle/GLTestContext_angle.h" 46 # include "gl/angle/GLTestContext_angle.h"
44 # endif 47 # endif
45 #else 48 #else
46 class GrContext; 49 class GrContext;
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 SkOSMenu::TriState fAAState; 536 SkOSMenu::TriState fAAState;
534 SkOSMenu::TriState fSubpixelState; 537 SkOSMenu::TriState fSubpixelState;
535 int fHintingState; 538 int fHintingState;
536 int fFilterQualityIndex; 539 int fFilterQualityIndex;
537 540
538 typedef SkPaintFilterCanvas INHERITED; 541 typedef SkPaintFilterCanvas INHERITED;
539 }; 542 };
540 543
541 /////////////////////////////////////////////////////////////////////////////// 544 ///////////////////////////////////////////////////////////////////////////////
542 545
546 class SampleTFSerializer : public SkTypefaceSerializer {
547 public:
548 sk_sp<SkData> serialize(SkTypeface* tf) override {
549 tf->ref();
550 return SkData::MakeWithCopy(&tf, sizeof(tf));
551 }
552 };
553
554 class SampleTFDeserializer : public SkTypefaceDeserializer {
555 public:
556 sk_sp<SkTypeface> deserialize(const void* data, size_t size) override {
557 SkASSERT(sizeof(SkTypeface*) == size);
558 SkTypeface* tf;
559 memcpy(&tf, data, size);
560 return sk_sp<SkTypeface>(tf); // this was ref'd in SampleTFSerializer
561 }
562 };
563
564 ///////////////////////////////////////////////////////////////////////////////
565
543 enum TilingMode { 566 enum TilingMode {
544 kNo_Tiling, 567 kNo_Tiling,
545 kAbs_128x128_Tiling, 568 kAbs_128x128_Tiling,
546 kAbs_256x256_Tiling, 569 kAbs_256x256_Tiling,
547 kRel_4x4_Tiling, 570 kRel_4x4_Tiling,
548 kRel_1x16_Tiling, 571 kRel_1x16_Tiling,
549 kRel_16x1_Tiling, 572 kRel_16x1_Tiling,
550 573
551 kLast_TilingMode_Enum 574 kLast_TilingMode_Enum
552 }; 575 };
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 DEFINE_bool(sort, false, "Sort samples by title."); 712 DEFINE_bool(sort, false, "Sort samples by title.");
690 DEFINE_bool(list, false, "List samples?"); 713 DEFINE_bool(list, false, "List samples?");
691 DEFINE_bool(gpu, false, "Start up with gpu?"); 714 DEFINE_bool(gpu, false, "Start up with gpu?");
692 DEFINE_bool(redraw, false, "Force continuous redrawing, for profiling or debuggi ng tools."); 715 DEFINE_bool(redraw, false, "Force continuous redrawing, for profiling or debuggi ng tools.");
693 DEFINE_string(key, "", ""); // dummy to enable gm tests that have platform-spec ific names 716 DEFINE_string(key, "", ""); // dummy to enable gm tests that have platform-spec ific names
694 #ifdef SAMPLE_PDF_FILE_VIEWER 717 #ifdef SAMPLE_PDF_FILE_VIEWER
695 DEFINE_string(pdfPath, "", "Path to direcotry of pdf files."); 718 DEFINE_string(pdfPath, "", "Path to direcotry of pdf files.");
696 #endif 719 #endif
697 720
698 #include "SkTaskGroup.h" 721 #include "SkTaskGroup.h"
722 #include "SkForceLinking.h"
699 723
700 SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev Manager) 724 SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev Manager)
701 : INHERITED(hwnd) 725 : INHERITED(hwnd)
702 , fDevManager(nullptr) { 726 , fDevManager(nullptr) {
703 727
728 SkForceLinking(false);
729
704 SkCommandLineFlags::Parse(argc, argv); 730 SkCommandLineFlags::Parse(argc, argv);
705 731
706 fCurrIndex = -1; 732 fCurrIndex = -1;
707 733
708 if (!FLAGS_pictureDir.isEmpty()) { 734 if (!FLAGS_pictureDir.isEmpty()) {
709 SkOSFile::Iter iter(FLAGS_pictureDir[0], "skp"); 735 SkOSFile::Iter iter(FLAGS_pictureDir[0], "skp");
710 SkString filename; 736 SkString filename;
711 while (iter.next(&filename)) { 737 while (iter.next(&filename)) {
712 *fSamples.append() = new PictFileFactory( 738 *fSamples.append() = new PictFileFactory(
713 SkOSPath::Join(FLAGS_pictureDir[0], filename.c_str())); 739 SkOSPath::Join(FLAGS_pictureDir[0], filename.c_str()));
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 870
845 fZoomLevel = 0; 871 fZoomLevel = 0;
846 fZoomScale = SK_Scalar1; 872 fZoomScale = SK_Scalar1;
847 fOffset = { 0, 0 }; 873 fOffset = { 0, 0 };
848 874
849 fMagnify = false; 875 fMagnify = false;
850 876
851 fSaveToPdf = false; 877 fSaveToPdf = false;
852 fSaveToSKP = false; 878 fSaveToSKP = false;
853 879
880 if (true) {
881 fPipeSerializer.setTypefaceSerializer(new SampleTFSerializer);
882 fPipeDeserializer.setTypefaceDeserializer(new SampleTFDeserializer);
883 }
884
854 int sinkID = this->getSinkID(); 885 int sinkID = this->getSinkID();
855 fAppMenu = new SkOSMenu; 886 fAppMenu = new SkOSMenu;
856 fAppMenu->setTitle("Global Settings"); 887 fAppMenu->setTitle("Global Settings");
857 int itemID; 888 int itemID;
858 889
859 itemID = fAppMenu->appendList("ColorType", "ColorType", sinkID, 0, 890 itemID = fAppMenu->appendList("ColorType", "ColorType", sinkID, 0,
860 gConfig[0].fName, gConfig[1].fName, gConfig[2] .fName, nullptr); 891 gConfig[0].fName, gConfig[1].fName, gConfig[2] .fName, nullptr);
861 fAppMenu->assignKeyEquivalentToItem(itemID, 'C'); 892 fAppMenu->assignKeyEquivalentToItem(itemID, 'C');
862 893
863 itemID = fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, 894 itemID = fAppMenu->appendList("Device Type", "Device Type", sinkID, 0,
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 } 1328 }
1298 name.append(".pdf"); 1329 name.append(".pdf");
1299 #ifdef SK_BUILD_FOR_ANDROID 1330 #ifdef SK_BUILD_FOR_ANDROID
1300 name.prepend("/sdcard/"); 1331 name.prepend("/sdcard/");
1301 #endif 1332 #endif
1302 fPDFDocument = SkDocument::MakePDF(name.c_str()); 1333 fPDFDocument = SkDocument::MakePDF(name.c_str());
1303 canvas = fPDFDocument->beginPage(this->width(), this->height()); 1334 canvas = fPDFDocument->beginPage(this->width(), this->height());
1304 } else if (fSaveToSKP) { 1335 } else if (fSaveToSKP) {
1305 canvas = fRecorder.beginRecording(9999, 9999, nullptr, 0); 1336 canvas = fRecorder.beginRecording(9999, 9999, nullptr, 0);
1306 } else if (fUsePicture) { 1337 } else if (fUsePicture) {
1307 canvas = fRecorder.beginRecording(9999, 9999, nullptr, 0); 1338 fPipeStream.reset(new SkDynamicMemoryWStream);
1339 canvas = fPipeSerializer.beginWrite(SkRect::MakeWH(this->width(), this-> height()),
1340 fPipeStream.get());
1341 // canvas = fRecorder.beginRecording(9999, 9999, nullptr, 0);
1308 } else { 1342 } else {
1309 canvas = this->INHERITED::beforeChildren(canvas); 1343 canvas = this->INHERITED::beforeChildren(canvas);
1310 } 1344 }
1311 1345
1312 if (fUseClip) { 1346 if (fUseClip) {
1313 canvas->drawColor(0xFFFF88FF); 1347 canvas->drawColor(0xFFFF88FF);
1314 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); 1348 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true);
1315 } 1349 }
1316 1350
1317 // Install a flags filter proxy canvas if needed 1351 // Install a flags filter proxy canvas if needed
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 if (fSaveToSKP) { 1393 if (fSaveToSKP) {
1360 sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture()); 1394 sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture());
1361 SkFILEWStream stream("sample_app.skp"); 1395 SkFILEWStream stream("sample_app.skp");
1362 picture->serialize(&stream); 1396 picture->serialize(&stream);
1363 fSaveToSKP = false; 1397 fSaveToSKP = false;
1364 this->inval(nullptr); 1398 this->inval(nullptr);
1365 return; 1399 return;
1366 } 1400 }
1367 1401
1368 if (fUsePicture) { 1402 if (fUsePicture) {
1369 sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture()); 1403 if (true) {
1370 1404 fPipeSerializer.endWrite();
1371 // serialize/deserialize? 1405 sk_sp<SkData> data(fPipeStream->detachAsData());
1372 if (false) { 1406 fPipeDeserializer.playback(data->data(), data->size(), orig);
1373 SkDynamicMemoryWStream wstream; 1407 fPipeStream.reset();
1374 picture->serialize(&wstream); 1408 } else {
1375 1409 sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture());
1376 SkAutoTDelete<SkStream> rstream(wstream.detachAsStream()); 1410 orig->drawPicture(picture.get());
1377 picture = SkPicture::MakeFromStream(rstream);
1378 } 1411 }
1379 orig->drawPicture(picture.get());
1380 } 1412 }
1381 1413
1382 // Do this after presentGL and other finishing, rather than in afterChild 1414 // Do this after presentGL and other finishing, rather than in afterChild
1383 if (fMeasureFPS) { 1415 if (fMeasureFPS) {
1384 orig->flush(); 1416 orig->flush();
1385 fTimer.end(); 1417 fTimer.end();
1386 fMeasureFPS_Time += fTimer.fWall; 1418 fMeasureFPS_Time += fTimer.fWall;
1387 } 1419 }
1388 } 1420 }
1389 1421
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 #ifdef SK_BUILD_FOR_MAC 2304 #ifdef SK_BUILD_FOR_MAC
2273 setenv("ANDROID_ROOT", "/android/device/data", 0); 2305 setenv("ANDROID_ROOT", "/android/device/data", 0);
2274 #endif 2306 #endif
2275 SkGraphics::Init(); 2307 SkGraphics::Init();
2276 SkEvent::Init(); 2308 SkEvent::Init();
2277 } 2309 }
2278 2310
2279 void application_term() { 2311 void application_term() {
2280 SkEvent::Term(); 2312 SkEvent::Term();
2281 } 2313 }
OLDNEW
« no previous file with comments | « samplecode/SampleApp.h ('k') | src/core/SkDeduper.h » ('j') | src/core/SkPipe.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698