| 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 "SkAnimTimer.h" | 14 #include "SkAnimTimer.h" |
| 15 #include "SkCanvas.h" | 15 #include "SkCanvas.h" |
| 16 #include "SkCommandLineFlags.h" | 16 #include "SkCommandLineFlags.h" |
| 17 #include "SkData.h" | 17 #include "SkData.h" |
| 18 #include "SkDeferredCanvas.h" | 18 #include "SkDeferredCanvas.h" |
| 19 #include "SkDevice.h" | 19 #include "SkDevice.h" |
| 20 #include "SkDocument.h" | 20 #include "SkDocument.h" |
| 21 #include "SkGPipe.h" | 21 #include "SkGPipe.h" |
| 22 #include "SkGraphics.h" | 22 #include "SkGraphics.h" |
| 23 #include "SkImageEncoder.h" | 23 #include "SkImageEncoder.h" |
| 24 #include "SkOSFile.h" | 24 #include "SkOSFile.h" |
| 25 #include "SkPaint.h" | 25 #include "SkPaint.h" |
| 26 #include "SkPaintFilterCanvas.h" |
| 26 #include "SkPicture.h" | 27 #include "SkPicture.h" |
| 27 #include "SkPictureRecorder.h" | 28 #include "SkPictureRecorder.h" |
| 28 #include "SkStream.h" | 29 #include "SkStream.h" |
| 29 #include "SkSurface.h" | 30 #include "SkSurface.h" |
| 30 #include "SkTSort.h" | 31 #include "SkTSort.h" |
| 31 #include "SkTime.h" | 32 #include "SkTime.h" |
| 32 #include "SkTypeface.h" | 33 #include "SkTypeface.h" |
| 33 #include "SkWindow.h" | 34 #include "SkWindow.h" |
| 34 #include "sk_tool_utils.h" | 35 #include "sk_tool_utils.h" |
| 35 | 36 |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 const char* fLabel; | 457 const char* fLabel; |
| 457 }; | 458 }; |
| 458 static FilterQualityState gFilterQualityStates[] = { | 459 static FilterQualityState gFilterQualityStates[] = { |
| 459 { kNone_SkFilterQuality, "Mixed", NULL }, | 460 { kNone_SkFilterQuality, "Mixed", NULL }, |
| 460 { kNone_SkFilterQuality, "None", "F0 " }, | 461 { kNone_SkFilterQuality, "None", "F0 " }, |
| 461 { kLow_SkFilterQuality, "Low", "F1 " }, | 462 { kLow_SkFilterQuality, "Low", "F1 " }, |
| 462 { kMedium_SkFilterQuality, "Medium", "F2 " }, | 463 { kMedium_SkFilterQuality, "Medium", "F2 " }, |
| 463 { kHigh_SkFilterQuality, "High", "F3 " }, | 464 { kHigh_SkFilterQuality, "High", "F3 " }, |
| 464 }; | 465 }; |
| 465 | 466 |
| 466 class FlagsDrawFilter : public SkDrawFilter { | 467 class FlagsFilterCanvas : public SkPaintFilterCanvas { |
| 467 public: | 468 public: |
| 468 FlagsDrawFilter(SkOSMenu::TriState lcd, SkOSMenu::TriState aa, | 469 FlagsFilterCanvas(SkCanvas* canvas, SkOSMenu::TriState lcd, SkOSMenu::TriSta
te aa, |
| 469 SkOSMenu::TriState subpixel, int hinting, int filterQuality) | 470 SkOSMenu::TriState subpixel, int hinting, int filterQualit
y) |
| 470 : fLCDState(lcd) | 471 : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height()) |
| 472 , fLCDState(lcd) |
| 471 , fAAState(aa) | 473 , fAAState(aa) |
| 472 , fSubpixelState(subpixel) | 474 , fSubpixelState(subpixel) |
| 473 , fHintingState(hinting) | 475 , fHintingState(hinting) |
| 474 , fFilterQualityIndex(filterQuality) | 476 , fFilterQualityIndex(filterQuality) { |
| 475 { | |
| 476 SkASSERT((unsigned)filterQuality < SK_ARRAY_COUNT(gFilterQualityStates))
; | 477 SkASSERT((unsigned)filterQuality < SK_ARRAY_COUNT(gFilterQualityStates))
; |
| 478 |
| 479 this->addCanvas(canvas); |
| 477 } | 480 } |
| 478 | 481 |
| 479 virtual bool filter(SkPaint* paint, Type t) { | 482 protected: |
| 483 void onFilterPaint(SkPaint* paint, Type t) const override { |
| 480 if (kText_Type == t && SkOSMenu::kMixedState != fLCDState) { | 484 if (kText_Type == t && SkOSMenu::kMixedState != fLCDState) { |
| 481 paint->setLCDRenderText(SkOSMenu::kOnState == fLCDState); | 485 paint->setLCDRenderText(SkOSMenu::kOnState == fLCDState); |
| 482 } | 486 } |
| 483 if (SkOSMenu::kMixedState != fAAState) { | 487 if (SkOSMenu::kMixedState != fAAState) { |
| 484 paint->setAntiAlias(SkOSMenu::kOnState == fAAState); | 488 paint->setAntiAlias(SkOSMenu::kOnState == fAAState); |
| 485 } | 489 } |
| 486 if (0 != fFilterQualityIndex) { | 490 if (0 != fFilterQualityIndex) { |
| 487 paint->setFilterQuality(gFilterQualityStates[fFilterQualityIndex].fQ
uality); | 491 paint->setFilterQuality(gFilterQualityStates[fFilterQualityIndex].fQ
uality); |
| 488 } | 492 } |
| 489 if (SkOSMenu::kMixedState != fSubpixelState) { | 493 if (SkOSMenu::kMixedState != fSubpixelState) { |
| 490 paint->setSubpixelText(SkOSMenu::kOnState == fSubpixelState); | 494 paint->setSubpixelText(SkOSMenu::kOnState == fSubpixelState); |
| 491 } | 495 } |
| 492 if (0 != fHintingState && fHintingState < (int)SK_ARRAY_COUNT(gHintingSt
ates)) { | 496 if (0 != fHintingState && fHintingState < (int)SK_ARRAY_COUNT(gHintingSt
ates)) { |
| 493 paint->setHinting(gHintingStates[fHintingState].hinting); | 497 paint->setHinting(gHintingStates[fHintingState].hinting); |
| 494 } | 498 } |
| 495 return true; | |
| 496 } | 499 } |
| 497 | 500 |
| 498 private: | 501 private: |
| 499 SkOSMenu::TriState fLCDState; | 502 SkOSMenu::TriState fLCDState; |
| 500 SkOSMenu::TriState fAAState; | 503 SkOSMenu::TriState fAAState; |
| 501 SkOSMenu::TriState fSubpixelState; | 504 SkOSMenu::TriState fSubpixelState; |
| 502 int fHintingState; | 505 int fHintingState; |
| 503 int fFilterQualityIndex; | 506 int fFilterQualityIndex; |
| 507 |
| 508 typedef SkPaintFilterCanvas INHERITED; |
| 504 }; | 509 }; |
| 505 | 510 |
| 506 ////////////////////////////////////////////////////////////////////////////// | 511 ////////////////////////////////////////////////////////////////////////////// |
| 507 | 512 |
| 508 #define MAX_ZOOM_LEVEL 8 | 513 #define MAX_ZOOM_LEVEL 8 |
| 509 #define MIN_ZOOM_LEVEL -8 | 514 #define MIN_ZOOM_LEVEL -8 |
| 510 | 515 |
| 511 static const char gCharEvtName[] = "SampleCode_Char_Event"; | 516 static const char gCharEvtName[] = "SampleCode_Char_Event"; |
| 512 static const char gKeyEvtName[] = "SampleCode_Key_Event"; | 517 static const char gKeyEvtName[] = "SampleCode_Key_Event"; |
| 513 static const char gTitleEvtName[] = "SampleCode_Title_Event"; | 518 static const char gTitleEvtName[] = "SampleCode_Title_Event"; |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 } | 1209 } |
| 1205 } else { | 1210 } else { |
| 1206 canvas = this->INHERITED::beforeChildren(canvas); | 1211 canvas = this->INHERITED::beforeChildren(canvas); |
| 1207 } | 1212 } |
| 1208 | 1213 |
| 1209 if (fUseClip) { | 1214 if (fUseClip) { |
| 1210 canvas->drawColor(0xFFFF88FF); | 1215 canvas->drawColor(0xFFFF88FF); |
| 1211 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); | 1216 canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true); |
| 1212 } | 1217 } |
| 1213 | 1218 |
| 1219 // Install a flags filter proxy canvas if needed |
| 1220 if (fLCDState != SkOSMenu::kMixedState || |
| 1221 fAAState != SkOSMenu::kMixedState || |
| 1222 fSubpixelState != SkOSMenu::kMixedState || |
| 1223 fHintingState > 0 || |
| 1224 fFilterQualityIndex > 0) { |
| 1225 |
| 1226 canvas = SkNEW_ARGS(FlagsFilterCanvas, (canvas, fLCDState, fAAState, fSu
bpixelState, |
| 1227 fHintingState, fFilterQualityInd
ex)); |
| 1228 fFlagsFilterCanvas.reset(canvas); |
| 1229 } |
| 1230 |
| 1214 return canvas; | 1231 return canvas; |
| 1215 } | 1232 } |
| 1216 #include "SkMultiPictureDraw.h" | 1233 #include "SkMultiPictureDraw.h" |
| 1217 void SampleWindow::afterChildren(SkCanvas* orig) { | 1234 void SampleWindow::afterChildren(SkCanvas* orig) { |
| 1235 fFlagsFilterCanvas.reset(NULL); |
| 1236 |
| 1218 if (fSaveToPdf) { | 1237 if (fSaveToPdf) { |
| 1219 fSaveToPdf = false; | 1238 fSaveToPdf = false; |
| 1220 fPDFDocument->endPage(); | 1239 fPDFDocument->endPage(); |
| 1221 fPDFDocument.reset(NULL); | 1240 fPDFDocument.reset(NULL); |
| 1222 // We took over the draw calls in order to create the PDF, so we need | 1241 // We took over the draw calls in order to create the PDF, so we need |
| 1223 // to redraw. | 1242 // to redraw. |
| 1224 this->inval(NULL); | 1243 this->inval(NULL); |
| 1225 return; | 1244 return; |
| 1226 } | 1245 } |
| 1227 | 1246 |
| 1228 if (fRequestGrabImage) { | 1247 if (fRequestGrabImage) { |
| 1229 fRequestGrabImage = false; | 1248 fRequestGrabImage = false; |
| 1230 | 1249 |
| 1231 SkBitmap bmp = capture_bitmap(orig); | 1250 SkBitmap bmp = capture_bitmap(orig); |
| 1232 if (!bmp.isNull()) { | 1251 if (!bmp.isNull()) { |
| 1233 static int gSampleGrabCounter; | 1252 static int gSampleGrabCounter; |
| 1234 SkString name; | 1253 SkString name; |
| 1235 name.printf("sample_grab_%d.png", gSampleGrabCounter++); | 1254 name.printf("sample_grab_%d.png", gSampleGrabCounter++); |
| 1236 SkImageEncoder::EncodeFile(name.c_str(), bmp, | 1255 SkImageEncoder::EncodeFile(name.c_str(), bmp, |
| 1237 SkImageEncoder::kPNG_Type, 100); | 1256 SkImageEncoder::kPNG_Type, 100); |
| 1238 } | 1257 } |
| 1239 } | 1258 } |
| 1240 | 1259 |
| 1241 if (kPicture_DeviceType == fDeviceType) { | 1260 if (kPicture_DeviceType == fDeviceType) { |
| 1242 SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording()); | 1261 SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording()); |
| 1243 | 1262 |
| 1244 if (true) { | 1263 if (true) { |
| 1245 this->installDrawFilter(orig); | |
| 1246 | |
| 1247 if (true) { | 1264 if (true) { |
| 1248 SkImageInfo info; | 1265 SkImageInfo info; |
| 1249 size_t rowBytes; | 1266 size_t rowBytes; |
| 1250 void* addr = orig->accessTopLayerPixels(&info, &rowBytes); | 1267 void* addr = orig->accessTopLayerPixels(&info, &rowBytes); |
| 1251 if (addr) { | 1268 if (addr) { |
| 1252 SkSurface* surfs[4]; | 1269 SkSurface* surfs[4]; |
| 1253 SkMultiPictureDraw md; | 1270 SkMultiPictureDraw md; |
| 1254 | 1271 |
| 1255 SkImageInfo n = SkImageInfo::Make(info.width()/2, info.heigh
t()/2, | 1272 SkImageInfo n = SkImageInfo::Make(info.width()/2, info.heigh
t()/2, |
| 1256 info.colorType(), info.alp
haType()); | 1273 info.colorType(), info.alp
haType()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 #if 1 | 1347 #if 1 |
| 1331 m.setPerspY(t); | 1348 m.setPerspY(t); |
| 1332 #else | 1349 #else |
| 1333 m.setPerspY(SK_Scalar1 / 1000); | 1350 m.setPerspY(SK_Scalar1 / 1000); |
| 1334 m.setSkewX(8.0f / 25); | 1351 m.setSkewX(8.0f / 25); |
| 1335 m.dump(); | 1352 m.dump(); |
| 1336 #endif | 1353 #endif |
| 1337 canvas->concat(m); | 1354 canvas->concat(m); |
| 1338 } | 1355 } |
| 1339 | 1356 |
| 1340 this->installDrawFilter(canvas); | |
| 1341 | |
| 1342 if (fMeasureFPS) { | 1357 if (fMeasureFPS) { |
| 1343 if (SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT)) { | 1358 if (SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT)) { |
| 1344 fMeasureFPS_StartTime = SkTime::GetMSecs(); | 1359 fMeasureFPS_StartTime = SkTime::GetMSecs(); |
| 1345 } | 1360 } |
| 1346 } else { | 1361 } else { |
| 1347 (void)SampleView::SetRepeatDraw(child, 1); | 1362 (void)SampleView::SetRepeatDraw(child, 1); |
| 1348 } | 1363 } |
| 1349 if (fPerspAnim || fRotate) { | 1364 if (fPerspAnim || fRotate) { |
| 1350 this->inval(NULL); | 1365 this->inval(NULL); |
| 1351 } | 1366 } |
| 1352 } | 1367 } |
| 1353 | 1368 |
| 1354 void SampleWindow::afterChild(SkView* child, SkCanvas* canvas) { | |
| 1355 canvas->setDrawFilter(NULL); | |
| 1356 } | |
| 1357 | |
| 1358 void SampleWindow::changeZoomLevel(float delta) { | 1369 void SampleWindow::changeZoomLevel(float delta) { |
| 1359 fZoomLevel += delta; | 1370 fZoomLevel += delta; |
| 1360 if (fZoomLevel > 0) { | 1371 if (fZoomLevel > 0) { |
| 1361 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL); | 1372 fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL); |
| 1362 fZoomScale = fZoomLevel + SK_Scalar1; | 1373 fZoomScale = fZoomLevel + SK_Scalar1; |
| 1363 } else if (fZoomLevel < 0) { | 1374 } else if (fZoomLevel < 0) { |
| 1364 fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL); | 1375 fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL); |
| 1365 fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel); | 1376 fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel); |
| 1366 } else { | 1377 } else { |
| 1367 fZoomScale = SK_Scalar1; | 1378 fZoomScale = SK_Scalar1; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 } | 1438 } |
| 1428 | 1439 |
| 1429 int SampleWindow::sampleCount() { | 1440 int SampleWindow::sampleCount() { |
| 1430 return fSamples.count(); | 1441 return fSamples.count(); |
| 1431 } | 1442 } |
| 1432 | 1443 |
| 1433 void SampleWindow::showOverview() { | 1444 void SampleWindow::showOverview() { |
| 1434 this->loadView(create_overview(fSamples.count(), fSamples.begin())); | 1445 this->loadView(create_overview(fSamples.count(), fSamples.begin())); |
| 1435 } | 1446 } |
| 1436 | 1447 |
| 1437 void SampleWindow::installDrawFilter(SkCanvas* canvas) { | |
| 1438 canvas->setDrawFilter(new FlagsDrawFilter(fLCDState, fAAState, fSubpixelStat
e, | |
| 1439 fHintingState, fFilterQualityIndex
))->unref(); | |
| 1440 } | |
| 1441 | |
| 1442 void SampleWindow::postAnimatingEvent() { | 1448 void SampleWindow::postAnimatingEvent() { |
| 1443 if (fAnimating) { | 1449 if (fAnimating) { |
| 1444 (new SkEvent(ANIMATING_EVENTTYPE, this->getSinkID()))->postDelay(ANIMATI
NG_DELAY); | 1450 (new SkEvent(ANIMATING_EVENTTYPE, this->getSinkID()))->postDelay(ANIMATI
NG_DELAY); |
| 1445 } | 1451 } |
| 1446 } | 1452 } |
| 1447 | 1453 |
| 1448 bool SampleWindow::onEvent(const SkEvent& evt) { | 1454 bool SampleWindow::onEvent(const SkEvent& evt) { |
| 1449 if (evt.isType(gUpdateWindowTitleEvtName)) { | 1455 if (evt.isType(gUpdateWindowTitleEvtName)) { |
| 1450 this->updateTitle(); | 1456 this->updateTitle(); |
| 1451 return true; | 1457 return true; |
| (...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2299 setenv("ANDROID_ROOT", "/android/device/data", 0); | 2305 setenv("ANDROID_ROOT", "/android/device/data", 0); |
| 2300 #endif | 2306 #endif |
| 2301 SkGraphics::Init(); | 2307 SkGraphics::Init(); |
| 2302 SkEvent::Init(); | 2308 SkEvent::Init(); |
| 2303 } | 2309 } |
| 2304 | 2310 |
| 2305 void application_term() { | 2311 void application_term() { |
| 2306 SkEvent::Term(); | 2312 SkEvent::Term(); |
| 2307 SkGraphics::Term(); | 2313 SkGraphics::Term(); |
| 2308 } | 2314 } |
| OLD | NEW |