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 "SampleApp.h" | 8 #include "SampleApp.h" |
9 | 9 |
10 #include "OverView.h" | 10 #include "OverView.h" |
11 #include "Resources.h" | 11 #include "Resources.h" |
12 #include "SampleCode.h" | 12 #include "SampleCode.h" |
13 #include "SamplePipeControllers.h" | 13 #include "SamplePipeControllers.h" |
14 #include "SkCanvas.h" | 14 #include "SkCanvas.h" |
15 #include "SkCommandLineFlags.h" | 15 #include "SkCommandLineFlags.h" |
16 #include "SkData.h" | 16 #include "SkData.h" |
17 #include "SkDevice.h" | 17 #include "SkDevice.h" |
| 18 #include "SkDocument.h" |
18 #include "SkGPipe.h" | 19 #include "SkGPipe.h" |
19 #include "SkGraphics.h" | 20 #include "SkGraphics.h" |
20 #include "SkImageEncoder.h" | 21 #include "SkImageEncoder.h" |
21 #include "SkOSFile.h" | 22 #include "SkOSFile.h" |
22 #include "SkPDFDevice.h" | 23 //#include "SkPDFDevice.h" |
23 #include "SkPDFDocument.h" | 24 //#include "SkPDFDocument.h" |
24 #include "SkPaint.h" | 25 #include "SkPaint.h" |
25 #include "SkPicture.h" | 26 #include "SkPicture.h" |
26 #include "SkPictureRecorder.h" | 27 #include "SkPictureRecorder.h" |
27 #include "SkStream.h" | 28 #include "SkStream.h" |
28 #include "SkSurface.h" | 29 #include "SkSurface.h" |
29 #include "SkTSort.h" | 30 #include "SkTSort.h" |
30 #include "SkTime.h" | 31 #include "SkTime.h" |
31 #include "SkTypeface.h" | 32 #include "SkTypeface.h" |
32 #include "SkWindow.h" | 33 #include "SkWindow.h" |
33 #include "TransitionView.h" | 34 #include "TransitionView.h" |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 fFatBitsScale = 8; | 853 fFatBitsScale = 8; |
853 fTypeface = SkTypeface::CreateFromTypeface(NULL, SkTypeface::kBold); | 854 fTypeface = SkTypeface::CreateFromTypeface(NULL, SkTypeface::kBold); |
854 fShowZoomer = false; | 855 fShowZoomer = false; |
855 | 856 |
856 fZoomLevel = 0; | 857 fZoomLevel = 0; |
857 fZoomScale = SK_Scalar1; | 858 fZoomScale = SK_Scalar1; |
858 | 859 |
859 fMagnify = false; | 860 fMagnify = false; |
860 | 861 |
861 fSaveToPdf = false; | 862 fSaveToPdf = false; |
862 fPdfCanvas = NULL; | |
863 | 863 |
864 fTransitionNext = 6; | 864 fTransitionNext = 6; |
865 fTransitionPrev = 2; | 865 fTransitionPrev = 2; |
866 | 866 |
867 int sinkID = this->getSinkID(); | 867 int sinkID = this->getSinkID(); |
868 fAppMenu = new SkOSMenu; | 868 fAppMenu = new SkOSMenu; |
869 fAppMenu->setTitle("Global Settings"); | 869 fAppMenu->setTitle("Global Settings"); |
870 int itemID; | 870 int itemID; |
871 | 871 |
872 itemID =fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, | 872 itemID =fAppMenu->appendList("Device Type", "Device Type", sinkID, 0, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 this->addMenu(fAppMenu); | 941 this->addMenu(fAppMenu); |
942 fSlideMenu = new SkOSMenu; | 942 fSlideMenu = new SkOSMenu; |
943 this->addMenu(fSlideMenu); | 943 this->addMenu(fSlideMenu); |
944 | 944 |
945 this->setColorType(kN32_SkColorType); | 945 this->setColorType(kN32_SkColorType); |
946 this->setVisibleP(true); | 946 this->setVisibleP(true); |
947 this->setClipToBounds(false); | 947 this->setClipToBounds(false); |
948 | 948 |
949 this->loadView((*fSamples[fCurrIndex])()); | 949 this->loadView((*fSamples[fCurrIndex])()); |
950 | 950 |
951 fPDFData = NULL; | |
952 | |
953 if (NULL == devManager) { | 951 if (NULL == devManager) { |
954 fDevManager = new DefaultDeviceManager(); | 952 fDevManager = new DefaultDeviceManager(); |
955 } else { | 953 } else { |
956 devManager->ref(); | 954 devManager->ref(); |
957 fDevManager = devManager; | 955 fDevManager = devManager; |
958 } | 956 } |
959 fDevManager->setUpBackend(this, fMSAASampleCount); | 957 fDevManager->setUpBackend(this, fMSAASampleCount); |
960 | 958 |
961 // If another constructor set our dimensions, ensure that our | 959 // If another constructor set our dimensions, ensure that our |
962 // onSizeChange gets called. | 960 // onSizeChange gets called. |
963 if (this->height() && this->width()) { | 961 if (this->height() && this->width()) { |
964 this->onSizeChange(); | 962 this->onSizeChange(); |
965 } | 963 } |
966 | 964 |
967 // can't call this synchronously, since it may require a subclass to | 965 // can't call this synchronously, since it may require a subclass to |
968 // to implement, or the caller may need us to have returned from the | 966 // to implement, or the caller may need us to have returned from the |
969 // constructor first. Hence we post an event to ourselves. | 967 // constructor first. Hence we post an event to ourselves. |
970 // this->updateTitle(); | 968 // this->updateTitle(); |
971 post_event_to_sink(new SkEvent(gUpdateWindowTitleEvtName), this); | 969 post_event_to_sink(new SkEvent(gUpdateWindowTitleEvtName), this); |
972 } | 970 } |
973 | 971 |
974 SampleWindow::~SampleWindow() { | 972 SampleWindow::~SampleWindow() { |
975 delete fPdfCanvas; | |
976 SkSafeUnref(fTypeface); | 973 SkSafeUnref(fTypeface); |
977 SkSafeUnref(fDevManager); | 974 SkSafeUnref(fDevManager); |
978 } | 975 } |
979 | 976 |
980 | 977 |
981 int SampleWindow::findByTitle(const char title[]) { | 978 int SampleWindow::findByTitle(const char title[]) { |
982 int i, count = fSamples.count(); | 979 int i, count = fSamples.count(); |
983 for (i = 0; i < count; i++) { | 980 for (i = 0; i < count; i++) { |
984 if (getSampleTitle(i).equals(title)) { | 981 if (getSampleTitle(i).equals(title)) { |
985 return i; | 982 return i; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 #include "SkColorPriv.h" | 1271 #include "SkColorPriv.h" |
1275 | 1272 |
1276 void SampleWindow::saveToPdf() | 1273 void SampleWindow::saveToPdf() |
1277 { | 1274 { |
1278 fSaveToPdf = true; | 1275 fSaveToPdf = true; |
1279 this->inval(NULL); | 1276 this->inval(NULL); |
1280 } | 1277 } |
1281 | 1278 |
1282 SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) { | 1279 SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) { |
1283 if (fSaveToPdf) { | 1280 if (fSaveToPdf) { |
1284 const SkBitmap bmp = capture_bitmap(canvas); | 1281 SkString name; |
1285 SkISize size = SkISize::Make(bmp.width(), bmp.height()); | 1282 if (!this->getRawTitle(&name)) { |
1286 SkPDFDevice* pdfDevice = new SkPDFDevice(size, size, | 1283 name.set("unknown_sample"); |
1287 canvas->getTotalMatrix()); | 1284 } |
1288 fPdfCanvas = new SkCanvas(pdfDevice); | 1285 name.append(".pdf"); |
1289 pdfDevice->unref(); | 1286 #ifdef SK_BUILD_FOR_ANDROID |
1290 canvas = fPdfCanvas; | 1287 name.prepend("/sdcard/"); |
| 1288 #endif |
| 1289 fPDFDocument.reset(SkDocument::CreatePDF(name.c_str())); |
| 1290 canvas = fPDFDocument->beginPage(this->width(), this->height()); |
1291 } else if (kPicture_DeviceType == fDeviceType) { | 1291 } else if (kPicture_DeviceType == fDeviceType) { |
1292 canvas = fRecorder.beginRecording(9999, 9999, NULL, 0); | 1292 canvas = fRecorder.beginRecording(9999, 9999, NULL, 0); |
1293 } else { | 1293 } else { |
1294 #if SK_SUPPORT_GPU | 1294 #if SK_SUPPORT_GPU |
1295 if (kNullGPU_DeviceType != fDeviceType) | 1295 if (kNullGPU_DeviceType != fDeviceType) |
1296 #endif | 1296 #endif |
1297 { | 1297 { |
1298 canvas = this->INHERITED::beforeChildren(canvas); | 1298 canvas = this->INHERITED::beforeChildren(canvas); |
1299 } | 1299 } |
1300 } | 1300 } |
1301 | 1301 |
1302 if (fUseClip) { | 1302 if (fUseClip) { |
1303 canvas->drawColor(0xFFFF88FF); | 1303 canvas->drawColor(0xFFFF88FF); |
1304 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); | 1304 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); |
1305 } | 1305 } |
1306 | 1306 |
1307 return canvas; | 1307 return canvas; |
1308 } | 1308 } |
1309 | 1309 |
1310 #include "SkData.h" | |
1311 void SampleWindow::afterChildren(SkCanvas* orig) { | 1310 void SampleWindow::afterChildren(SkCanvas* orig) { |
1312 if (fSaveToPdf) { | 1311 if (fSaveToPdf) { |
1313 fSaveToPdf = false; | 1312 fSaveToPdf = false; |
1314 if (fShowZoomer) { | 1313 fPDFDocument->endPage(); |
1315 showZoomer(fPdfCanvas); | 1314 fPDFDocument.reset(NULL); |
1316 } | |
1317 SkString name; | |
1318 name.printf("%s.pdf", this->getTitle()); | |
1319 SkPDFDocument doc; | |
1320 SkPDFDevice* device = NULL;//static_cast<SkPDFDevice*>(fPdfCanvas->getDe
vice()); | |
1321 SkASSERT(false); | |
1322 doc.appendPage(device); | |
1323 #ifdef SK_BUILD_FOR_ANDROID | |
1324 name.prepend("/sdcard/"); | |
1325 #endif | |
1326 | |
1327 #ifdef SK_BUILD_FOR_IOS | |
1328 SkDynamicMemoryWStream mstream; | |
1329 doc.emitPDF(&mstream); | |
1330 fPDFData = mstream.copyToData(); | |
1331 #endif | |
1332 SkFILEWStream stream(name.c_str()); | |
1333 if (stream.isValid()) { | |
1334 doc.emitPDF(&stream); | |
1335 const char* desc = "File saved from Skia SampleApp"; | |
1336 this->onPDFSaved(this->getTitle(), desc, name.c_str()); | |
1337 } | |
1338 | |
1339 delete fPdfCanvas; | |
1340 fPdfCanvas = NULL; | |
1341 | |
1342 // We took over the draw calls in order to create the PDF, so we need | 1315 // We took over the draw calls in order to create the PDF, so we need |
1343 // to redraw. | 1316 // to redraw. |
1344 this->inval(NULL); | 1317 this->inval(NULL); |
1345 return; | 1318 return; |
1346 } | 1319 } |
1347 | 1320 |
1348 if (fRequestGrabImage) { | 1321 if (fRequestGrabImage) { |
1349 fRequestGrabImage = false; | 1322 fRequestGrabImage = false; |
1350 | 1323 |
1351 SkBitmap bmp = capture_bitmap(orig); | 1324 SkBitmap bmp = capture_bitmap(orig); |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2002 static const char* trystate_str(SkOSMenu::TriState state, | 1975 static const char* trystate_str(SkOSMenu::TriState state, |
2003 const char trueStr[], const char falseStr[]) { | 1976 const char trueStr[], const char falseStr[]) { |
2004 if (SkOSMenu::kOnState == state) { | 1977 if (SkOSMenu::kOnState == state) { |
2005 return trueStr; | 1978 return trueStr; |
2006 } else if (SkOSMenu::kOffState == state) { | 1979 } else if (SkOSMenu::kOffState == state) { |
2007 return falseStr; | 1980 return falseStr; |
2008 } | 1981 } |
2009 return NULL; | 1982 return NULL; |
2010 } | 1983 } |
2011 | 1984 |
| 1985 bool SampleWindow::getRawTitle(SkString* title) { |
| 1986 return curr_title(this, title); |
| 1987 } |
| 1988 |
2012 void SampleWindow::updateTitle() { | 1989 void SampleWindow::updateTitle() { |
2013 SkView* view = curr_view(this); | |
2014 | |
2015 SkString title; | 1990 SkString title; |
2016 if (!curr_title(this, &title)) { | 1991 if (!this->getRawTitle(&title)) { |
2017 title.set("<unknown>"); | 1992 title.set("<unknown>"); |
2018 } | 1993 } |
2019 | 1994 |
2020 title.prepend(gDeviceTypePrefix[fDeviceType]); | 1995 title.prepend(gDeviceTypePrefix[fDeviceType]); |
2021 | 1996 |
2022 title.prepend(" "); | 1997 title.prepend(" "); |
2023 title.prepend(sk_tool_utils::colortype_name(this->getBitmap().colorType())); | 1998 title.prepend(sk_tool_utils::colortype_name(this->getBitmap().colorType())); |
2024 | 1999 |
2025 if (fTilingMode != kNo_Tiling) { | 2000 if (fTilingMode != kNo_Tiling) { |
2026 title.prependf("<T: %s> ", gTilingInfo[fTilingMode].label); | 2001 title.prependf("<T: %s> ", gTilingInfo[fTilingMode].label); |
(...skipping 22 matching lines...) Expand all Loading... |
2049 title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : NULL); | 2024 title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : NULL); |
2050 title.prepend(gHintingStates[fHintingState].label); | 2025 title.prepend(gHintingStates[fHintingState].label); |
2051 | 2026 |
2052 if (fZoomLevel) { | 2027 if (fZoomLevel) { |
2053 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel)); | 2028 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel)); |
2054 } | 2029 } |
2055 | 2030 |
2056 if (fMeasureFPS) { | 2031 if (fMeasureFPS) { |
2057 title.appendf(" %8.3f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT); | 2032 title.appendf(" %8.3f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT); |
2058 } | 2033 } |
| 2034 |
| 2035 SkView* view = curr_view(this); |
2059 if (SampleView::IsSampleView(view)) { | 2036 if (SampleView::IsSampleView(view)) { |
2060 switch (fPipeState) { | 2037 switch (fPipeState) { |
2061 case SkOSMenu::kOnState: | 2038 case SkOSMenu::kOnState: |
2062 title.prepend("<Pipe> "); | 2039 title.prepend("<Pipe> "); |
2063 break; | 2040 break; |
2064 case SkOSMenu::kMixedState: | 2041 case SkOSMenu::kMixedState: |
2065 title.prepend("<Tiled Pipe> "); | 2042 title.prepend("<Tiled Pipe> "); |
2066 break; | 2043 break; |
2067 | 2044 |
2068 default: | 2045 default: |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2416 setenv("ANDROID_ROOT", "/android/device/data", 0); | 2393 setenv("ANDROID_ROOT", "/android/device/data", 0); |
2417 #endif | 2394 #endif |
2418 SkGraphics::Init(); | 2395 SkGraphics::Init(); |
2419 SkEvent::Init(); | 2396 SkEvent::Init(); |
2420 } | 2397 } |
2421 | 2398 |
2422 void application_term() { | 2399 void application_term() { |
2423 SkEvent::Term(); | 2400 SkEvent::Term(); |
2424 SkGraphics::Term(); | 2401 SkGraphics::Term(); |
2425 } | 2402 } |
OLD | NEW |