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" |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
869 fPerspAnim = false; | 869 fPerspAnim = false; |
870 fRequestGrabImage = false; | 870 fRequestGrabImage = false; |
871 fTilingMode = kNo_Tiling; | 871 fTilingMode = kNo_Tiling; |
872 fMeasureFPS = false; | 872 fMeasureFPS = false; |
873 fLCDState = SkOSMenu::kMixedState; | 873 fLCDState = SkOSMenu::kMixedState; |
874 fAAState = SkOSMenu::kMixedState; | 874 fAAState = SkOSMenu::kMixedState; |
875 fSubpixelState = SkOSMenu::kMixedState; | 875 fSubpixelState = SkOSMenu::kMixedState; |
876 fHintingState = 0; | 876 fHintingState = 0; |
877 fFilterQualityIndex = 0; | 877 fFilterQualityIndex = 0; |
878 fFlipAxis = 0; | 878 fFlipAxis = 0; |
879 fScrollTestX = fScrollTestY = 0; | |
880 | 879 |
881 fMouseX = fMouseY = 0; | 880 fMouseX = fMouseY = 0; |
882 fFatBitsScale = 8; | 881 fFatBitsScale = 8; |
883 fTypeface = SkTypeface::CreateFromTypeface(nullptr, SkTypeface::kBold); | 882 fTypeface = SkTypeface::CreateFromTypeface(nullptr, SkTypeface::kBold); |
884 fShowZoomer = false; | 883 fShowZoomer = false; |
885 | 884 |
886 fZoomLevel = 0; | 885 fZoomLevel = 0; |
887 fZoomScale = SK_Scalar1; | 886 fZoomScale = SK_Scalar1; |
887 fOffset = { 0, 0 }; | |
888 | 888 |
889 fMagnify = false; | 889 fMagnify = false; |
890 | 890 |
891 fSaveToPdf = false; | 891 fSaveToPdf = false; |
892 fSaveToSKP = false; | 892 fSaveToSKP = false; |
893 | 893 |
894 int sinkID = this->getSinkID(); | 894 int sinkID = this->getSinkID(); |
895 fAppMenu = new SkOSMenu; | 895 fAppMenu = new SkOSMenu; |
896 fAppMenu->setTitle("Global Settings"); | 896 fAppMenu->setTitle("Global Settings"); |
897 int itemID; | 897 int itemID; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1055 | 1055 |
1056 if (fMeasureFPS) { | 1056 if (fMeasureFPS) { |
1057 fMeasureFPS_Time = 0; | 1057 fMeasureFPS_Time = 0; |
1058 } | 1058 } |
1059 | 1059 |
1060 SkSize tile = this->tileSize(); | 1060 SkSize tile = this->tileSize(); |
1061 | 1061 |
1062 if (kNo_Tiling == fTilingMode) { | 1062 if (kNo_Tiling == fTilingMode) { |
1063 this->INHERITED::draw(canvas); // no looping or surfaces needed | 1063 this->INHERITED::draw(canvas); // no looping or surfaces needed |
1064 } else { | 1064 } else { |
1065 const int w = SkScalarRoundToInt(tile.width()); | 1065 const SkScalar w = SkScalarCeilToScalar(tile.width()); |
1066 const int h = SkScalarRoundToInt(tile.height()); | 1066 const SkScalar h = SkScalarCeilToScalar(tile.height()); |
1067 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); | 1067 SkImageInfo info = SkImageInfo::MakeN32Premul(SkScalarTruncToInt(w), SkS calarTruncToInt(h)); |
1068 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); | 1068 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); |
1069 SkCanvas* tileCanvas = surface->getCanvas(); | 1069 SkCanvas* tileCanvas = surface->getCanvas(); |
1070 | 1070 |
1071 for (SkScalar y = 0; y < height(); y += tile.height()) { | 1071 for (SkScalar y = 0; y < height(); y += h) { |
1072 for (SkScalar x = 0; x < width(); x += tile.width()) { | 1072 for (SkScalar x = 0; x < width(); x += w) { |
1073 SkAutoCanvasRestore acr(tileCanvas, true); | 1073 SkAutoCanvasRestore acr(tileCanvas, true); |
1074 tileCanvas->translate(-x, -y); | 1074 tileCanvas->translate(-x, -y); |
bungeman-skia
2016/03/03 22:42:37
Just to make things more clear, when x and y are n
| |
1075 tileCanvas->clear(0); | 1075 tileCanvas->clear(0); |
1076 this->INHERITED::draw(tileCanvas); | 1076 this->INHERITED::draw(tileCanvas); |
1077 surface->draw(canvas, x, y, nullptr); | 1077 surface->draw(canvas, x, y, nullptr); |
1078 } | 1078 } |
1079 } | 1079 } |
1080 | 1080 |
1081 // for drawing the borders between tiles | 1081 // for drawing the borders between tiles |
1082 SkPaint paint; | 1082 SkPaint paint; |
1083 paint.setColor(0x60FF00FF); | 1083 paint.setColor(0x60FF00FF); |
1084 paint.setStyle(SkPaint::kStroke_Style); | 1084 paint.setStyle(SkPaint::kStroke_Style); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1455 (void)SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT); | 1455 (void)SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT); |
1456 fTimer.start(); | 1456 fTimer.start(); |
1457 } else { | 1457 } else { |
1458 (void)SampleView::SetRepeatDraw(child, 1); | 1458 (void)SampleView::SetRepeatDraw(child, 1); |
1459 } | 1459 } |
1460 if (fPerspAnim || fRotate) { | 1460 if (fPerspAnim || fRotate) { |
1461 this->inval(nullptr); | 1461 this->inval(nullptr); |
1462 } | 1462 } |
1463 } | 1463 } |
1464 | 1464 |
1465 void SampleWindow::changeOffset(SkVector delta) { | |
1466 fOffset += delta; | |
1467 this->updateMatrix(); | |
1468 } | |
1469 | |
1465 void SampleWindow::changeZoomLevel(float delta) { | 1470 void SampleWindow::changeZoomLevel(float delta) { |
1466 fZoomLevel += delta; | 1471 fZoomLevel += delta; |
1467 if (fZoomLevel > 0) { | 1472 if (fZoomLevel > 0) { |
1468 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL); | 1473 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL); |
1469 fZoomScale = fZoomLevel + SK_Scalar1; | 1474 fZoomScale = fZoomLevel + SK_Scalar1; |
1470 } else if (fZoomLevel < 0) { | 1475 } else if (fZoomLevel < 0) { |
1471 fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL); | 1476 fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL); |
1472 fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel); | 1477 fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel); |
1473 } else { | 1478 } else { |
1474 fZoomScale = SK_Scalar1; | 1479 fZoomScale = SK_Scalar1; |
1475 } | 1480 } |
1476 this->updateMatrix(); | 1481 this->updateMatrix(); |
1477 } | 1482 } |
1478 | 1483 |
1479 void SampleWindow::updateMatrix(){ | 1484 void SampleWindow::updateMatrix(){ |
1480 SkMatrix m; | 1485 SkMatrix m; |
1481 m.reset(); | 1486 m.reset(); |
1487 | |
1482 if (fZoomLevel) { | 1488 if (fZoomLevel) { |
1483 SkPoint center; | 1489 SkPoint center; |
1484 //m = this->getLocalMatrix();//.invert(&m); | 1490 //m = this->getLocalMatrix();//.invert(&m); |
1485 m.mapXY(fZoomCenterX, fZoomCenterY, ¢er); | 1491 m.mapXY(fZoomCenterX, fZoomCenterY, ¢er); |
1486 SkScalar cx = center.fX; | 1492 SkScalar cx = center.fX; |
1487 SkScalar cy = center.fY; | 1493 SkScalar cy = center.fY; |
1488 | 1494 |
1489 m.setTranslate(-cx, -cy); | 1495 m.setTranslate(-cx, -cy); |
1490 m.postScale(fZoomScale, fZoomScale); | 1496 m.postScale(fZoomScale, fZoomScale); |
1491 m.postTranslate(cx, cy); | 1497 m.postTranslate(cx, cy); |
1492 } | 1498 } |
1493 | 1499 |
1500 m.postTranslate(fOffset.fX, fOffset.fY); | |
1501 | |
1494 if (fFlipAxis) { | 1502 if (fFlipAxis) { |
1495 m.preTranslate(fZoomCenterX, fZoomCenterY); | 1503 m.preTranslate(fZoomCenterX, fZoomCenterY); |
1496 if (fFlipAxis & kFlipAxis_X) { | 1504 if (fFlipAxis & kFlipAxis_X) { |
1497 m.preScale(-SK_Scalar1, SK_Scalar1); | 1505 m.preScale(-SK_Scalar1, SK_Scalar1); |
1498 } | 1506 } |
1499 if (fFlipAxis & kFlipAxis_Y) { | 1507 if (fFlipAxis & kFlipAxis_Y) { |
1500 m.preScale(SK_Scalar1, -SK_Scalar1); | 1508 m.preScale(SK_Scalar1, -SK_Scalar1); |
1501 } | 1509 } |
1502 m.preTranslate(-fZoomCenterX, -fZoomCenterY); | 1510 m.preTranslate(-fZoomCenterX, -fZoomCenterY); |
1503 //canvas->concat(m); | 1511 //canvas->concat(m); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1678 case '7': dx = -1; dy = -1; break; | 1686 case '7': dx = -1; dy = -1; break; |
1679 case '9': dx = 1; dy = -1; break; | 1687 case '9': dx = 1; dy = -1; break; |
1680 case '3': dx = 1; dy = 1; break; | 1688 case '3': dx = 1; dy = 1; break; |
1681 case '1': dx = -1; dy = 1; break; | 1689 case '1': dx = -1; dy = 1; break; |
1682 | 1690 |
1683 default: | 1691 default: |
1684 break; | 1692 break; |
1685 } | 1693 } |
1686 | 1694 |
1687 if (0xFF != dx && 0xFF != dy) { | 1695 if (0xFF != dx && 0xFF != dy) { |
1688 if ((dx | dy) == 0) { | 1696 this->changeOffset({SkIntToScalar(dx / 32.0f), SkIntToScalar(dy / 32.0f) }); |
1689 fScrollTestX = fScrollTestY = 0; | |
1690 } else { | |
1691 fScrollTestX += dx; | |
1692 fScrollTestY += dy; | |
1693 } | |
1694 this->inval(nullptr); | |
1695 return true; | 1697 return true; |
1696 } | 1698 } |
1697 | 1699 |
1698 switch (uni) { | 1700 switch (uni) { |
1699 case 27: // ESC | 1701 case 27: // ESC |
1700 gAnimTimer.stop(); | 1702 gAnimTimer.stop(); |
1701 if (this->sendAnimatePulse()) { | 1703 if (this->sendAnimatePulse()) { |
1702 this->inval(nullptr); | 1704 this->inval(nullptr); |
1703 } | 1705 } |
1704 break; | 1706 break; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1848 { | 1850 { |
1849 SkView* view = curr_view(this); | 1851 SkView* view = curr_view(this); |
1850 if (view) { | 1852 if (view) { |
1851 SkEvent evt(gKeyEvtName); | 1853 SkEvent evt(gKeyEvtName); |
1852 evt.setFast32(key); | 1854 evt.setFast32(key); |
1853 if (view->doQuery(&evt)) { | 1855 if (view->doQuery(&evt)) { |
1854 return true; | 1856 return true; |
1855 } | 1857 } |
1856 } | 1858 } |
1857 } | 1859 } |
1860 | |
1861 int dx = 0xFF; | |
1862 int dy = 0xFF; | |
1863 | |
1858 switch (key) { | 1864 switch (key) { |
1859 case kRight_SkKey: | 1865 case kRight_SkKey: |
1860 if (this->nextSample()) { | 1866 if (this->nextSample()) { |
1861 return true; | 1867 return true; |
1862 } | 1868 } |
1863 break; | 1869 break; |
1864 case kLeft_SkKey: | 1870 case kLeft_SkKey: |
1865 if (this->previousSample()) { | 1871 if (this->previousSample()) { |
1866 return true; | 1872 return true; |
1867 } | 1873 } |
1868 return true; | 1874 return true; |
1869 case kUp_SkKey: | 1875 case kUp_SkKey: |
1870 this->changeZoomLevel(1.f / 32.f); | 1876 this->changeZoomLevel(1.f / 32.f); |
1871 return true; | 1877 return true; |
1872 case kDown_SkKey: | 1878 case kDown_SkKey: |
1873 this->changeZoomLevel(-1.f / 32.f); | 1879 this->changeZoomLevel(-1.f / 32.f); |
1874 return true; | 1880 return true; |
1875 case kOK_SkKey: { | 1881 case kOK_SkKey: { |
1876 SkString title; | 1882 SkString title; |
1877 if (curr_title(this, &title)) { | 1883 if (curr_title(this, &title)) { |
1878 writeTitleToPrefs(title.c_str()); | 1884 writeTitleToPrefs(title.c_str()); |
1879 } | 1885 } |
1880 return true; | 1886 return true; |
1881 } | 1887 } |
1882 case kBack_SkKey: | 1888 case kBack_SkKey: |
1883 this->showOverview(); | 1889 this->showOverview(); |
1884 return true; | 1890 return true; |
1891 | |
1892 case k5_SkKey: dx = 0; dy = 0; break; | |
1893 case k8_SkKey: dx = 0; dy = -1; break; | |
1894 case k6_SkKey: dx = 1; dy = 0; break; | |
1895 case k2_SkKey: dx = 0; dy = 1; break; | |
1896 case k4_SkKey: dx = -1; dy = 0; break; | |
1897 case k7_SkKey: dx = -1; dy = -1; break; | |
1898 case k9_SkKey: dx = 1; dy = -1; break; | |
1899 case k3_SkKey: dx = 1; dy = 1; break; | |
1900 case k1_SkKey: dx = -1; dy = 1; break; | |
1901 | |
1885 default: | 1902 default: |
1886 break; | 1903 break; |
1887 } | 1904 } |
1905 | |
1906 if (0xFF != dx && 0xFF != dy) { | |
1907 this->changeOffset({SkIntToScalar(dx / 32.0f), SkIntToScalar(dy / 32.0f) }); | |
1908 return true; | |
1909 } | |
1910 | |
1888 return this->INHERITED::onHandleKey(key); | 1911 return this->INHERITED::onHandleKey(key); |
1889 } | 1912 } |
1890 | 1913 |
1891 /////////////////////////////////////////////////////////////////////////////// | 1914 /////////////////////////////////////////////////////////////////////////////// |
1892 | 1915 |
1893 static const char gGestureClickType[] = "GestureClickType"; | 1916 static const char gGestureClickType[] = "GestureClickType"; |
1894 | 1917 |
1895 bool SampleWindow::onDispatchClick(int x, int y, Click::State state, | 1918 bool SampleWindow::onDispatchClick(int x, int y, Click::State state, |
1896 void* owner, unsigned modi) { | 1919 void* owner, unsigned modi) { |
1897 if (Click::kMoved_State == state) { | 1920 if (Click::kMoved_State == state) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2041 } | 2064 } |
2042 | 2065 |
2043 title.prepend(trystate_str(fLCDState, "LCD ", "lcd ")); | 2066 title.prepend(trystate_str(fLCDState, "LCD ", "lcd ")); |
2044 title.prepend(trystate_str(fAAState, "AA ", "aa ")); | 2067 title.prepend(trystate_str(fAAState, "AA ", "aa ")); |
2045 title.prepend(gFilterQualityStates[fFilterQualityIndex].fLabel); | 2068 title.prepend(gFilterQualityStates[fFilterQualityIndex].fLabel); |
2046 title.prepend(trystate_str(fSubpixelState, "S ", "s ")); | 2069 title.prepend(trystate_str(fSubpixelState, "S ", "s ")); |
2047 title.prepend(fFlipAxis & kFlipAxis_X ? "X " : nullptr); | 2070 title.prepend(fFlipAxis & kFlipAxis_X ? "X " : nullptr); |
2048 title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : nullptr); | 2071 title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : nullptr); |
2049 title.prepend(gHintingStates[fHintingState].label); | 2072 title.prepend(gHintingStates[fHintingState].label); |
2050 | 2073 |
2074 if (fOffset.fX || fOffset.fY) { | |
2075 title.prependf("(%.2f, %.2f) ", SkScalarToFloat(fOffset.fX), SkScalarToF loat(fOffset.fY)); | |
2076 } | |
2051 if (fZoomLevel) { | 2077 if (fZoomLevel) { |
2052 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel)); | 2078 title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel)); |
2053 } | 2079 } |
2054 | 2080 |
2055 if (fMeasureFPS) { | 2081 if (fMeasureFPS) { |
2056 title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT); | 2082 title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT); |
2057 } | 2083 } |
2058 | 2084 |
2059 #if SK_SUPPORT_GPU | 2085 #if SK_SUPPORT_GPU |
2060 if (IsGpuDeviceType(fDeviceType) && | 2086 if (IsGpuDeviceType(fDeviceType) && |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2303 #ifdef SK_BUILD_FOR_MAC | 2329 #ifdef SK_BUILD_FOR_MAC |
2304 setenv("ANDROID_ROOT", "/android/device/data", 0); | 2330 setenv("ANDROID_ROOT", "/android/device/data", 0); |
2305 #endif | 2331 #endif |
2306 SkGraphics::Init(); | 2332 SkGraphics::Init(); |
2307 SkEvent::Init(); | 2333 SkEvent::Init(); |
2308 } | 2334 } |
2309 | 2335 |
2310 void application_term() { | 2336 void application_term() { |
2311 SkEvent::Term(); | 2337 SkEvent::Term(); |
2312 } | 2338 } |
OLD | NEW |