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

Side by Side Diff: samplecode/SampleApp.cpp

Issue 948693002: remove dead code from sampleapp, trim bad asserts (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « samplecode/SampleApp.h ('k') | src/effects/SkMagnifierImageFilter.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 7
8 #include "SampleApp.h" 8 #include "SampleApp.h"
9 9
10 #include "OverView.h" 10 #include "OverView.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 #ifdef PIPE_FILE 70 #ifdef PIPE_FILE
71 #define FILE_PATH "/path/to/drawing.data" 71 #define FILE_PATH "/path/to/drawing.data"
72 #endif 72 #endif
73 73
74 #define PIPE_NETx 74 #define PIPE_NETx
75 #ifdef PIPE_NET 75 #ifdef PIPE_NET
76 #include "SkSockets.h" 76 #include "SkSockets.h"
77 SkTCPServer gServer; 77 SkTCPServer gServer;
78 #endif 78 #endif
79 79
80 #define USE_ARROWS_FOR_ZOOM true
81
82 #if SK_ANGLE 80 #if SK_ANGLE
83 //#define DEFAULT_TO_ANGLE 1 81 //#define DEFAULT_TO_ANGLE 1
84 #else 82 #else
85 #define DEFAULT_TO_GPU 0 // if 1 default rendering is on GPU 83 #define DEFAULT_TO_GPU 0 // if 1 default rendering is on GPU
86 #endif 84 #endif
87 85
88 #define ANIMATING_EVENTTYPE "nextSample" 86 #define ANIMATING_EVENTTYPE "nextSample"
89 #define ANIMATING_DELAY 250 87 #define ANIMATING_DELAY 250
90 88
91 #ifdef SK_DEBUG 89 #ifdef SK_DEBUG
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 fDeviceType = kRaster_DeviceType; 786 fDeviceType = kRaster_DeviceType;
789 787
790 #if DEFAULT_TO_GPU 788 #if DEFAULT_TO_GPU
791 fDeviceType = kGPU_DeviceType; 789 fDeviceType = kGPU_DeviceType;
792 #endif 790 #endif
793 #if SK_ANGLE && DEFAULT_TO_ANGLE 791 #if SK_ANGLE && DEFAULT_TO_ANGLE
794 fDeviceType = kANGLE_DeviceType; 792 fDeviceType = kANGLE_DeviceType;
795 #endif 793 #endif
796 794
797 fUseClip = false; 795 fUseClip = false;
798 fNClip = false;
799 fAnimating = false; 796 fAnimating = false;
800 fRotate = false; 797 fRotate = false;
801 fPerspAnim = false; 798 fPerspAnim = false;
802 fRequestGrabImage = false; 799 fRequestGrabImage = false;
803 fPipeState = SkOSMenu::kOffState; 800 fPipeState = SkOSMenu::kOffState;
804 fTilingMode = kNo_Tiling; 801 fTilingMode = kNo_Tiling;
805 fMeasureFPS = false; 802 fMeasureFPS = false;
806 fLCDState = SkOSMenu::kMixedState; 803 fLCDState = SkOSMenu::kMixedState;
807 fAAState = SkOSMenu::kMixedState; 804 fAAState = SkOSMenu::kMixedState;
808 fSubpixelState = SkOSMenu::kMixedState; 805 fSubpixelState = SkOSMenu::kMixedState;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 "Down and Right", "Down", "Down and Left", 894 "Down and Right", "Down", "Down and Left",
898 "Left", "Up and Left", NULL); 895 "Left", "Up and Left", NULL);
899 fAppMenu->assignKeyEquivalentToItem(itemID, 'k'); 896 fAppMenu->assignKeyEquivalentToItem(itemID, 'k');
900 itemID = fAppMenu->appendAction("Save to PDF", sinkID); 897 itemID = fAppMenu->appendAction("Save to PDF", sinkID);
901 fAppMenu->assignKeyEquivalentToItem(itemID, 'e'); 898 fAppMenu->assignKeyEquivalentToItem(itemID, 'e');
902 899
903 this->addMenu(fAppMenu); 900 this->addMenu(fAppMenu);
904 fSlideMenu = new SkOSMenu; 901 fSlideMenu = new SkOSMenu;
905 this->addMenu(fSlideMenu); 902 this->addMenu(fSlideMenu);
906 903
907 this->setColorType(kN32_SkColorType);
908 this->setVisibleP(true); 904 this->setVisibleP(true);
909 this->setClipToBounds(false); 905 this->setClipToBounds(false);
910 906
911 this->loadView((*fSamples[fCurrIndex])()); 907 this->loadView((*fSamples[fCurrIndex])());
912 908
913 if (NULL == devManager) { 909 if (NULL == devManager) {
914 fDevManager = new DefaultDeviceManager(); 910 fDevManager = new DefaultDeviceManager();
915 } else { 911 } else {
916 devManager->ref(); 912 devManager->ref();
917 fDevManager = devManager; 913 fDevManager = devManager;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 } 954 }
959 955
960 static SkBitmap capture_bitmap(SkCanvas* canvas) { 956 static SkBitmap capture_bitmap(SkCanvas* canvas) {
961 SkBitmap bm; 957 SkBitmap bm;
962 if (bm.tryAllocPixels(canvas->imageInfo())) { 958 if (bm.tryAllocPixels(canvas->imageInfo())) {
963 canvas->readPixels(&bm, 0, 0); 959 canvas->readPixels(&bm, 0, 0);
964 } 960 }
965 return bm; 961 return bm;
966 } 962 }
967 963
968 static bool bitmap_diff(SkCanvas* canvas, const SkBitmap& orig, 964 static void drawText(SkCanvas* canvas, SkString str, SkScalar left, SkScalar top , SkPaint& paint) {
969 SkBitmap* diff) {
970 SkBitmap src = capture_bitmap(canvas);
971
972 SkAutoLockPixels alp0(src);
973 SkAutoLockPixels alp1(orig);
974 for (int y = 0; y < src.height(); y++) {
975 const void* srcP = src.getAddr(0, y);
976 const void* origP = orig.getAddr(0, y);
977 size_t bytes = src.width() * src.bytesPerPixel();
978 if (memcmp(srcP, origP, bytes)) {
979 SkDebugf("---------- difference on line %d\n", y);
980 return true;
981 }
982 }
983 return false;
984 }
985
986 static void drawText(SkCanvas* canvas, SkString string, SkScalar left, SkScalar top, SkPaint& paint)
987 {
988 SkColor desiredColor = paint.getColor(); 965 SkColor desiredColor = paint.getColor();
989 paint.setColor(SK_ColorWHITE); 966 paint.setColor(SK_ColorWHITE);
990 const char* c_str = string.c_str(); 967 const char* c_str = str.c_str();
991 size_t size = string.size(); 968 size_t size = str.size();
992 SkRect bounds; 969 SkRect bounds;
993 paint.measureText(c_str, size, &bounds); 970 paint.measureText(c_str, size, &bounds);
994 bounds.offset(left, top); 971 bounds.offset(left, top);
995 SkScalar inset = SkIntToScalar(-2); 972 SkScalar inset = SkIntToScalar(-2);
996 bounds.inset(inset, inset); 973 bounds.inset(inset, inset);
997 canvas->drawRect(bounds, paint); 974 canvas->drawRect(bounds, paint);
998 if (desiredColor != SK_ColorBLACK) { 975 if (desiredColor != SK_ColorBLACK) {
999 paint.setColor(SK_ColorBLACK); 976 paint.setColor(SK_ColorBLACK);
1000 canvas->drawText(c_str, size, left + SK_Scalar1, top + SK_Scalar1, paint ); 977 canvas->drawText(c_str, size, left + SK_Scalar1, top + SK_Scalar1, paint );
1001 } 978 }
1002 paint.setColor(desiredColor); 979 paint.setColor(desiredColor);
1003 canvas->drawText(c_str, size, left, top, paint); 980 canvas->drawText(c_str, size, left, top, paint);
1004 } 981 }
1005 982
1006 #define XCLIP_N 8 983 #define XCLIP_N 8
1007 #define YCLIP_N 8 984 #define YCLIP_N 8
1008 985
1009 void SampleWindow::draw(SkCanvas* canvas) { 986 void SampleWindow::draw(SkCanvas* canvas) {
1010 gAnimTimer.updateTime(); 987 gAnimTimer.updateTime();
1011 988
1012 if (fGesture.isActive()) { 989 if (fGesture.isActive()) {
1013 this->updateMatrix(); 990 this->updateMatrix();
1014 } 991 }
1015 992
1016 if (fMeasureFPS) { 993 if (fMeasureFPS) {
1017 fMeasureFPS_Time = 0; 994 fMeasureFPS_Time = 0;
1018 } 995 }
1019 996
1020 if (fNClip) { 997 SkSize tile = this->tileSize();
1021 this->INHERITED::draw(canvas);
1022 SkBitmap orig = capture_bitmap(canvas);
1023 998
1024 const SkScalar w = this->width(); 999 if (kNo_Tiling == fTilingMode) {
1025 const SkScalar h = this->height(); 1000 this->INHERITED::draw(canvas); // no looping or surfaces needed
1026 const SkScalar cw = w / XCLIP_N; 1001 } else {
1027 const SkScalar ch = h / YCLIP_N; 1002 const int w = SkScalarRoundToInt(tile.width());
1028 for (int y = 0; y < YCLIP_N; y++) { 1003 const int h = SkScalarRoundToInt(tile.height());
1029 SkRect r; 1004 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
1030 r.fTop = y * ch; 1005 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
1031 r.fBottom = (y + 1) * ch; 1006 SkCanvas* tileCanvas = surface->getCanvas();
1032 if (y == YCLIP_N - 1) { 1007
1033 r.fBottom = h; 1008 for (SkScalar y = 0; y < height(); y += tile.height()) {
1034 } 1009 for (SkScalar x = 0; x < width(); x += tile.width()) {
1035 for (int x = 0; x < XCLIP_N; x++) { 1010 SkAutoCanvasRestore acr(tileCanvas, true);
1036 SkAutoCanvasRestore acr(canvas, true); 1011 tileCanvas->translate(-x, -y);
1037 r.fLeft = x * cw; 1012 tileCanvas->clear(0);
1038 r.fRight = (x + 1) * cw; 1013 this->INHERITED::draw(tileCanvas);
1039 if (x == XCLIP_N - 1) { 1014 surface->draw(canvas, x, y, NULL);
1040 r.fRight = w;
1041 }
1042 canvas->clipRect(r);
1043 this->INHERITED::draw(canvas);
1044 } 1015 }
1045 } 1016 }
1046 1017
1047 SkBitmap diff; 1018 // for drawing the borders between tiles
1048 if (bitmap_diff(canvas, orig, &diff)) { 1019 SkPaint paint;
1049 } 1020 paint.setColor(0x60FF00FF);
1050 } else { 1021 paint.setStyle(SkPaint::kStroke_Style);
1051 SkSize tile = this->tileSize();
1052 1022
1053 if (kNo_Tiling == fTilingMode) { 1023 for (SkScalar y = 0; y < height(); y += tile.height()) {
1054 this->INHERITED::draw(canvas); // no looping or surfaces needed 1024 for (SkScalar x = 0; x < width(); x += tile.width()) {
1055 } else { 1025 canvas->drawRect(SkRect::MakeXYWH(x, y, tile.width(), tile.heigh t()), paint);
1056 const int w = SkScalarRoundToInt(tile.width());
1057 const int h = SkScalarRoundToInt(tile.height());
1058 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
1059 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
1060 SkCanvas* tileCanvas = surface->getCanvas();
1061
1062 for (SkScalar y = 0; y < height(); y += tile.height()) {
1063 for (SkScalar x = 0; x < width(); x += tile.width()) {
1064 SkAutoCanvasRestore acr(tileCanvas, true);
1065 tileCanvas->translate(-x, -y);
1066 tileCanvas->clear(0);
1067 this->INHERITED::draw(tileCanvas);
1068 surface->draw(canvas, x, y, NULL);
1069 }
1070 }
1071
1072 // for drawing the borders between tiles
1073 SkPaint paint;
1074 paint.setColor(0x60FF00FF);
1075 paint.setStyle(SkPaint::kStroke_Style);
1076
1077 for (SkScalar y = 0; y < height(); y += tile.height()) {
1078 for (SkScalar x = 0; x < width(); x += tile.width()) {
1079 canvas->drawRect(SkRect::MakeXYWH(x, y, tile.width(), tile.h eight()), paint);
1080 }
1081 } 1026 }
1082 } 1027 }
1083 } 1028 }
1029
1084 if (fShowZoomer && !fSaveToPdf) { 1030 if (fShowZoomer && !fSaveToPdf) {
1085 showZoomer(canvas); 1031 showZoomer(canvas);
1086 } 1032 }
1087 if (fMagnify && !fSaveToPdf) { 1033 if (fMagnify && !fSaveToPdf) {
1088 magnify(canvas); 1034 magnify(canvas);
1089 } 1035 }
1090 1036
1091 if (fMeasureFPS && fMeasureFPS_Time) { 1037 if (fMeasureFPS && fMeasureFPS_Time) {
1092 this->updateTitle(); 1038 this->updateTitle();
1093 this->postInvalDelay(); 1039 this->postInvalDelay();
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 } 1335 }
1390 if (fPerspAnim || fRotate) { 1336 if (fPerspAnim || fRotate) {
1391 this->inval(NULL); 1337 this->inval(NULL);
1392 } 1338 }
1393 } 1339 }
1394 1340
1395 void SampleWindow::afterChild(SkView* child, SkCanvas* canvas) { 1341 void SampleWindow::afterChild(SkView* child, SkCanvas* canvas) {
1396 canvas->setDrawFilter(NULL); 1342 canvas->setDrawFilter(NULL);
1397 } 1343 }
1398 1344
1399 static SkColorType gColorTypeCycle[] = {
1400 kUnknown_SkColorType, // none -> none
1401 kUnknown_SkColorType, // a8 -> none
1402 kN32_SkColorType, // 565 -> 8888
1403 kN32_SkColorType, // 4444 -> 8888
1404 kRGB_565_SkColorType, // 8888 -> 565
1405 kRGB_565_SkColorType, // 8888 -> 565
1406 kUnknown_SkColorType, // index8 -> none
1407 };
1408
1409 static SkColorType cycle_colortypes(SkColorType c) {
1410 return gColorTypeCycle[c];
1411 }
1412
1413 void SampleWindow::changeZoomLevel(float delta) { 1345 void SampleWindow::changeZoomLevel(float delta) {
1414 fZoomLevel += delta; 1346 fZoomLevel += delta;
1415 if (fZoomLevel > 0) { 1347 if (fZoomLevel > 0) {
1416 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL); 1348 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL);
1417 fZoomScale = fZoomLevel + SK_Scalar1; 1349 fZoomScale = fZoomLevel + SK_Scalar1;
1418 } else if (fZoomLevel < 0) { 1350 } else if (fZoomLevel < 0) {
1419 fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL); 1351 fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL);
1420 fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel); 1352 fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel);
1421 } else { 1353 } else {
1422 fZoomScale = SK_Scalar1; 1354 fZoomScale = SK_Scalar1;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 this->updateTitle(); 1437 this->updateTitle();
1506 return true; 1438 return true;
1507 } 1439 }
1508 if (evt.isType(ANIMATING_EVENTTYPE)) { 1440 if (evt.isType(ANIMATING_EVENTTYPE)) {
1509 if (fAnimating) { 1441 if (fAnimating) {
1510 this->nextSample(); 1442 this->nextSample();
1511 this->postAnimatingEvent(); 1443 this->postAnimatingEvent();
1512 } 1444 }
1513 return true; 1445 return true;
1514 } 1446 }
1515 if (evt.isType("replace-transition-view")) {
1516 this->loadView((SkView*)SkEventSink::FindSink(evt.getFast32()));
1517 return true;
1518 }
1519 if (evt.isType("set-curr-index")) { 1447 if (evt.isType("set-curr-index")) {
1520 this->goToSample(evt.getFast32()); 1448 this->goToSample(evt.getFast32());
1521 return true; 1449 return true;
1522 } 1450 }
1523 if (isInvalEvent(evt)) { 1451 if (isInvalEvent(evt)) {
1524 this->inval(NULL); 1452 this->inval(NULL);
1525 return true; 1453 return true;
1526 } 1454 }
1527 int selected = -1; 1455 int selected = -1;
1528 if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) { 1456 if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 if (this->nextSample()) { 1719 if (this->nextSample()) {
1792 return true; 1720 return true;
1793 } 1721 }
1794 break; 1722 break;
1795 case kLeft_SkKey: 1723 case kLeft_SkKey:
1796 if (this->previousSample()) { 1724 if (this->previousSample()) {
1797 return true; 1725 return true;
1798 } 1726 }
1799 return true; 1727 return true;
1800 case kUp_SkKey: 1728 case kUp_SkKey:
1801 if (USE_ARROWS_FOR_ZOOM) { 1729 this->changeZoomLevel(1.f / 32.f);
1802 this->changeZoomLevel(1.f / 32.f);
1803 } else {
1804 fNClip = !fNClip;
1805 this->inval(NULL);
1806 this->updateTitle();
1807 }
1808 return true; 1730 return true;
1809 case kDown_SkKey: 1731 case kDown_SkKey:
1810 if (USE_ARROWS_FOR_ZOOM) { 1732 this->changeZoomLevel(-1.f / 32.f);
1811 this->changeZoomLevel(-1.f / 32.f);
1812 } else {
1813 this->setColorType(cycle_colortypes(this->getBitmap().colorType( )));
1814 this->updateTitle();
1815 }
1816 return true; 1733 return true;
1817 case kOK_SkKey: { 1734 case kOK_SkKey: {
1818 SkString title; 1735 SkString title;
1819 if (curr_title(this, &title)) { 1736 if (curr_title(this, &title)) {
1820 writeTitleToPrefs(title.c_str()); 1737 writeTitleToPrefs(title.c_str());
1821 } 1738 }
1822 return true; 1739 return true;
1823 } 1740 }
1824 case kBack_SkKey: 1741 case kBack_SkKey:
1825 this->showOverview(); 1742 this->showOverview();
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 1889
1973 if (fTilingMode != kNo_Tiling) { 1890 if (fTilingMode != kNo_Tiling) {
1974 title.prependf("<T: %s> ", gTilingInfo[fTilingMode].label); 1891 title.prependf("<T: %s> ", gTilingInfo[fTilingMode].label);
1975 } 1892 }
1976 if (fAnimating) { 1893 if (fAnimating) {
1977 title.prepend("<A> "); 1894 title.prepend("<A> ");
1978 } 1895 }
1979 if (fRotate) { 1896 if (fRotate) {
1980 title.prepend("<R> "); 1897 title.prepend("<R> ");
1981 } 1898 }
1982 if (fNClip) {
1983 title.prepend("<C> ");
1984 }
1985 if (fPerspAnim) { 1899 if (fPerspAnim) {
1986 title.prepend("<K> "); 1900 title.prepend("<K> ");
1987 } 1901 }
1988 if (this->getSurfaceProps().flags() & SkSurfaceProps::kUseDistanceFieldFonts _Flag) { 1902 if (this->getSurfaceProps().flags() & SkSurfaceProps::kUseDistanceFieldFonts _Flag) {
1989 title.prepend("<DFF> "); 1903 title.prepend("<DFF> ");
1990 } 1904 }
1991 1905
1992 title.prepend(trystate_str(fLCDState, "LCD ", "lcd ")); 1906 title.prepend(trystate_str(fLCDState, "LCD ", "lcd "));
1993 title.prepend(trystate_str(fAAState, "AA ", "aa ")); 1907 title.prepend(trystate_str(fAAState, "AA ", "aa "));
1994 title.prepend(gFilterLevelStates[fFilterLevelIndex].fLabel); 1908 title.prepend(gFilterLevelStates[fFilterLevelIndex].fLabel);
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
2367 setenv("ANDROID_ROOT", "/android/device/data", 0); 2281 setenv("ANDROID_ROOT", "/android/device/data", 0);
2368 #endif 2282 #endif
2369 SkGraphics::Init(); 2283 SkGraphics::Init();
2370 SkEvent::Init(); 2284 SkEvent::Init();
2371 } 2285 }
2372 2286
2373 void application_term() { 2287 void application_term() {
2374 SkEvent::Term(); 2288 SkEvent::Term();
2375 SkGraphics::Term(); 2289 SkGraphics::Term();
2376 } 2290 }
OLDNEW
« no previous file with comments | « samplecode/SampleApp.h ('k') | src/effects/SkMagnifierImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698