| 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 #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" |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 } | 827 } |
| 828 | 828 |
| 829 gSampleWindow = this; | 829 gSampleWindow = this; |
| 830 | 830 |
| 831 #ifdef PIPE_FILE | 831 #ifdef PIPE_FILE |
| 832 //Clear existing file or create file if it doesn't exist | 832 //Clear existing file or create file if it doesn't exist |
| 833 FILE* f = fopen(FILE_PATH, "wb"); | 833 FILE* f = fopen(FILE_PATH, "wb"); |
| 834 fclose(f); | 834 fclose(f); |
| 835 #endif | 835 #endif |
| 836 | 836 |
| 837 fPicture = NULL; | |
| 838 | |
| 839 fDeviceType = kRaster_DeviceType; | 837 fDeviceType = kRaster_DeviceType; |
| 840 | 838 |
| 841 #if DEFAULT_TO_GPU | 839 #if DEFAULT_TO_GPU |
| 842 fDeviceType = kGPU_DeviceType; | 840 fDeviceType = kGPU_DeviceType; |
| 843 #endif | 841 #endif |
| 844 #if SK_ANGLE && DEFAULT_TO_ANGLE | 842 #if SK_ANGLE && DEFAULT_TO_ANGLE |
| 845 fDeviceType = kANGLE_DeviceType; | 843 fDeviceType = kANGLE_DeviceType; |
| 846 #endif | 844 #endif |
| 847 | 845 |
| 848 fUseClip = false; | 846 fUseClip = false; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 } | 981 } |
| 984 | 982 |
| 985 // can't call this synchronously, since it may require a subclass to | 983 // can't call this synchronously, since it may require a subclass to |
| 986 // to implement, or the caller may need us to have returned from the | 984 // to implement, or the caller may need us to have returned from the |
| 987 // constructor first. Hence we post an event to ourselves. | 985 // constructor first. Hence we post an event to ourselves. |
| 988 // this->updateTitle(); | 986 // this->updateTitle(); |
| 989 post_event_to_sink(new SkEvent(gUpdateWindowTitleEvtName), this); | 987 post_event_to_sink(new SkEvent(gUpdateWindowTitleEvtName), this); |
| 990 } | 988 } |
| 991 | 989 |
| 992 SampleWindow::~SampleWindow() { | 990 SampleWindow::~SampleWindow() { |
| 993 delete fPicture; | |
| 994 delete fPdfCanvas; | 991 delete fPdfCanvas; |
| 995 fTypeface->unref(); | 992 fTypeface->unref(); |
| 996 | 993 |
| 997 SkSafeUnref(fDevManager); | 994 SkSafeUnref(fDevManager); |
| 998 } | 995 } |
| 999 | 996 |
| 1000 static void make_filepath(SkString* path, const char* dir, const SkString& name)
{ | 997 static void make_filepath(SkString* path, const char* dir, const SkString& name)
{ |
| 1001 size_t len = strlen(dir); | 998 size_t len = strlen(dir); |
| 1002 path->set(dir); | 999 path->set(dir); |
| 1003 if (len > 0 && dir[len - 1] != '/') { | 1000 if (len > 0 && dir[len - 1] != '/') { |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) { | 1369 SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) { |
| 1373 if (fSaveToPdf) { | 1370 if (fSaveToPdf) { |
| 1374 const SkBitmap& bmp = canvas->getDevice()->accessBitmap(false); | 1371 const SkBitmap& bmp = canvas->getDevice()->accessBitmap(false); |
| 1375 SkISize size = SkISize::Make(bmp.width(), bmp.height()); | 1372 SkISize size = SkISize::Make(bmp.width(), bmp.height()); |
| 1376 SkPDFDevice* pdfDevice = new SkPDFDevice(size, size, | 1373 SkPDFDevice* pdfDevice = new SkPDFDevice(size, size, |
| 1377 canvas->getTotalMatrix()); | 1374 canvas->getTotalMatrix()); |
| 1378 fPdfCanvas = new SkCanvas(pdfDevice); | 1375 fPdfCanvas = new SkCanvas(pdfDevice); |
| 1379 pdfDevice->unref(); | 1376 pdfDevice->unref(); |
| 1380 canvas = fPdfCanvas; | 1377 canvas = fPdfCanvas; |
| 1381 } else if (kPicture_DeviceType == fDeviceType) { | 1378 } else if (kPicture_DeviceType == fDeviceType) { |
| 1382 fPicture = new SkPicture; | 1379 canvas = fRecorder.beginRecording(9999, 9999); |
| 1383 canvas = fPicture->beginRecording(9999, 9999); | |
| 1384 } else { | 1380 } else { |
| 1385 #if SK_SUPPORT_GPU | 1381 #if SK_SUPPORT_GPU |
| 1386 if (kNullGPU_DeviceType != fDeviceType) | 1382 if (kNullGPU_DeviceType != fDeviceType) |
| 1387 #endif | 1383 #endif |
| 1388 { | 1384 { |
| 1389 canvas = this->INHERITED::beforeChildren(canvas); | 1385 canvas = this->INHERITED::beforeChildren(canvas); |
| 1390 } | 1386 } |
| 1391 } | 1387 } |
| 1392 | 1388 |
| 1393 if (fUseClip) { | 1389 if (fUseClip) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1452 if (device->accessBitmap(false).copyTo(&bmp, kN32_SkColorType)) { | 1448 if (device->accessBitmap(false).copyTo(&bmp, kN32_SkColorType)) { |
| 1453 static int gSampleGrabCounter; | 1449 static int gSampleGrabCounter; |
| 1454 SkString name; | 1450 SkString name; |
| 1455 name.printf("sample_grab_%d.png", gSampleGrabCounter++); | 1451 name.printf("sample_grab_%d.png", gSampleGrabCounter++); |
| 1456 SkImageEncoder::EncodeFile(name.c_str(), bmp, | 1452 SkImageEncoder::EncodeFile(name.c_str(), bmp, |
| 1457 SkImageEncoder::kPNG_Type, 100); | 1453 SkImageEncoder::kPNG_Type, 100); |
| 1458 } | 1454 } |
| 1459 } | 1455 } |
| 1460 | 1456 |
| 1461 if (kPicture_DeviceType == fDeviceType) { | 1457 if (kPicture_DeviceType == fDeviceType) { |
| 1458 SkAutoTUnref<SkPicture> picture(fRecorder.endRecording()); |
| 1459 |
| 1462 if (true) { | 1460 if (true) { |
| 1463 SkPicture* pict = new SkPicture(*fPicture); | 1461 SkPicture* pict = new SkPicture(*picture); |
| 1464 fPicture->unref(); | |
| 1465 this->installDrawFilter(orig); | 1462 this->installDrawFilter(orig); |
| 1466 orig->drawPicture(*pict); | 1463 orig->drawPicture(*pict); |
| 1467 pict->unref(); | 1464 pict->unref(); |
| 1468 } else if (true) { | 1465 } else if (true) { |
| 1469 SkDynamicMemoryWStream ostream; | 1466 SkDynamicMemoryWStream ostream; |
| 1470 fPicture->serialize(&ostream); | 1467 picture->serialize(&ostream); |
| 1471 fPicture->unref(); | |
| 1472 | 1468 |
| 1473 SkAutoDataUnref data(ostream.copyToData()); | 1469 SkAutoDataUnref data(ostream.copyToData()); |
| 1474 SkMemoryStream istream(data->data(), data->size()); | 1470 SkMemoryStream istream(data->data(), data->size()); |
| 1475 SkAutoTUnref<SkPicture> pict(SkPicture::CreateFromStream(&istream)); | 1471 SkAutoTUnref<SkPicture> pict(SkPicture::CreateFromStream(&istream)); |
| 1476 if (pict.get() != NULL) { | 1472 if (pict.get() != NULL) { |
| 1477 orig->drawPicture(*pict.get()); | 1473 orig->drawPicture(*pict.get()); |
| 1478 } | 1474 } |
| 1479 } else { | 1475 } else { |
| 1480 fPicture->draw(orig); | 1476 picture->draw(orig); |
| 1481 fPicture->unref(); | |
| 1482 } | 1477 } |
| 1483 fPicture = NULL; | |
| 1484 } | 1478 } |
| 1485 | 1479 |
| 1486 // Do this after presentGL and other finishing, rather than in afterChild | 1480 // Do this after presentGL and other finishing, rather than in afterChild |
| 1487 if (fMeasureFPS && fMeasureFPS_StartTime) { | 1481 if (fMeasureFPS && fMeasureFPS_StartTime) { |
| 1488 fMeasureFPS_Time += SkTime::GetMSecs() - fMeasureFPS_StartTime; | 1482 fMeasureFPS_Time += SkTime::GetMSecs() - fMeasureFPS_StartTime; |
| 1489 } | 1483 } |
| 1490 | 1484 |
| 1491 // if ((fScrollTestX | fScrollTestY) != 0) | 1485 // if ((fScrollTestX | fScrollTestY) != 0) |
| 1492 if (false) { | 1486 if (false) { |
| 1493 const SkBitmap& bm = orig->getDevice()->accessBitmap(true); | 1487 const SkBitmap& bm = orig->getDevice()->accessBitmap(true); |
| (...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2562 SkGraphics::Init(); | 2556 SkGraphics::Init(); |
| 2563 SkEvent::Init(); | 2557 SkEvent::Init(); |
| 2564 } | 2558 } |
| 2565 | 2559 |
| 2566 // FIXME: this should be in a header | 2560 // FIXME: this should be in a header |
| 2567 void application_term(); | 2561 void application_term(); |
| 2568 void application_term() { | 2562 void application_term() { |
| 2569 SkEvent::Term(); | 2563 SkEvent::Term(); |
| 2570 SkGraphics::Term(); | 2564 SkGraphics::Term(); |
| 2571 } | 2565 } |
| OLD | NEW |