| 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 393 |
| 394 void SampleWindow::postInvalDelay() { | 394 void SampleWindow::postInvalDelay() { |
| 395 (new SkEvent(view_inval_msg, this->getSinkID()))->postDelay(1); | 395 (new SkEvent(view_inval_msg, this->getSinkID()))->postDelay(1); |
| 396 } | 396 } |
| 397 | 397 |
| 398 static bool isInvalEvent(const SkEvent& evt) { | 398 static bool isInvalEvent(const SkEvent& evt) { |
| 399 return evt.isType(view_inval_msg); | 399 return evt.isType(view_inval_msg); |
| 400 } | 400 } |
| 401 ////////////////// | 401 ////////////////// |
| 402 | 402 |
| 403 SkFuncViewFactory::SkFuncViewFactory(SkViewCreateFunc func) | |
| 404 : fCreateFunc(func) { | |
| 405 } | |
| 406 | |
| 407 SkView* SkFuncViewFactory::operator() () const { | |
| 408 return (*fCreateFunc)(); | |
| 409 } | |
| 410 | |
| 411 #include "GMSampleView.h" | 403 #include "GMSampleView.h" |
| 412 | 404 |
| 413 SkGMSampleViewFactory::SkGMSampleViewFactory(GMFactoryFunc func) | |
| 414 : fFunc(func) { | |
| 415 } | |
| 416 | |
| 417 SkView* SkGMSampleViewFactory::operator() () const { | |
| 418 skiagm::GM* gm = fFunc(nullptr); | |
| 419 gm->setMode(skiagm::GM::kSample_Mode); | |
| 420 return new GMSampleView(gm); | |
| 421 } | |
| 422 | |
| 423 SkViewRegister* SkViewRegister::gHead; | |
| 424 SkViewRegister::SkViewRegister(SkViewFactory* fact) : fFact(fact) { | |
| 425 fFact->ref(); | |
| 426 fChain = gHead; | |
| 427 gHead = this; | |
| 428 } | |
| 429 | |
| 430 SkViewRegister::SkViewRegister(SkViewCreateFunc func) { | |
| 431 fFact = new SkFuncViewFactory(func); | |
| 432 fChain = gHead; | |
| 433 gHead = this; | |
| 434 } | |
| 435 | |
| 436 SkViewRegister::SkViewRegister(GMFactoryFunc func) { | |
| 437 fFact = new SkGMSampleViewFactory(func); | |
| 438 fChain = gHead; | |
| 439 gHead = this; | |
| 440 } | |
| 441 | |
| 442 class AutoUnrefArray { | 405 class AutoUnrefArray { |
| 443 public: | 406 public: |
| 444 AutoUnrefArray() {} | 407 AutoUnrefArray() {} |
| 445 ~AutoUnrefArray() { | 408 ~AutoUnrefArray() { |
| 446 int count = fObjs.count(); | 409 int count = fObjs.count(); |
| 447 for (int i = 0; i < count; ++i) { | 410 for (int i = 0; i < count; ++i) { |
| 448 fObjs[i]->unref(); | 411 fObjs[i]->unref(); |
| 449 } | 412 } |
| 450 } | 413 } |
| 451 SkRefCnt*& push_back() { return *fObjs.append(); } | 414 SkRefCnt*& push_back() { return *fObjs.append(); } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 private: | 523 private: |
| 561 SkOSMenu::TriState fLCDState; | 524 SkOSMenu::TriState fLCDState; |
| 562 SkOSMenu::TriState fAAState; | 525 SkOSMenu::TriState fAAState; |
| 563 SkOSMenu::TriState fSubpixelState; | 526 SkOSMenu::TriState fSubpixelState; |
| 564 int fHintingState; | 527 int fHintingState; |
| 565 int fFilterQualityIndex; | 528 int fFilterQualityIndex; |
| 566 | 529 |
| 567 typedef SkPaintFilterCanvas INHERITED; | 530 typedef SkPaintFilterCanvas INHERITED; |
| 568 }; | 531 }; |
| 569 | 532 |
| 570 ////////////////////////////////////////////////////////////////////////////// | |
| 571 | |
| 572 #define MAX_ZOOM_LEVEL 8 | |
| 573 #define MIN_ZOOM_LEVEL -8 | |
| 574 | |
| 575 static const char gCharEvtName[] = "SampleCode_Char_Event"; | |
| 576 static const char gKeyEvtName[] = "SampleCode_Key_Event"; | |
| 577 static const char gTitleEvtName[] = "SampleCode_Title_Event"; | |
| 578 static const char gPrefSizeEvtName[] = "SampleCode_PrefSize_Event"; | |
| 579 static const char gFastTextEvtName[] = "SampleCode_FastText_Event"; | |
| 580 static const char gUpdateWindowTitleEvtName[] = "SampleCode_UpdateWindowTitle"; | |
| 581 | |
| 582 bool SampleCode::CharQ(const SkEvent& evt, SkUnichar* outUni) { | |
| 583 if (evt.isType(gCharEvtName, sizeof(gCharEvtName) - 1)) { | |
| 584 if (outUni) { | |
| 585 *outUni = evt.getFast32(); | |
| 586 } | |
| 587 return true; | |
| 588 } | |
| 589 return false; | |
| 590 } | |
| 591 | |
| 592 bool SampleCode::KeyQ(const SkEvent& evt, SkKey* outKey) { | |
| 593 if (evt.isType(gKeyEvtName, sizeof(gKeyEvtName) - 1)) { | |
| 594 if (outKey) { | |
| 595 *outKey = (SkKey)evt.getFast32(); | |
| 596 } | |
| 597 return true; | |
| 598 } | |
| 599 return false; | |
| 600 } | |
| 601 | |
| 602 bool SampleCode::TitleQ(const SkEvent& evt) { | |
| 603 return evt.isType(gTitleEvtName, sizeof(gTitleEvtName) - 1); | |
| 604 } | |
| 605 | |
| 606 void SampleCode::TitleR(SkEvent* evt, const char title[]) { | |
| 607 SkASSERT(evt && TitleQ(*evt)); | |
| 608 evt->setString(gTitleEvtName, title); | |
| 609 } | |
| 610 | |
| 611 bool SampleCode::RequestTitle(SkView* view, SkString* title) { | |
| 612 SkEvent evt(gTitleEvtName); | |
| 613 if (view->doQuery(&evt)) { | |
| 614 title->set(evt.findString(gTitleEvtName)); | |
| 615 return true; | |
| 616 } | |
| 617 return false; | |
| 618 } | |
| 619 | |
| 620 bool SampleCode::PrefSizeQ(const SkEvent& evt) { | |
| 621 return evt.isType(gPrefSizeEvtName, sizeof(gPrefSizeEvtName) - 1); | |
| 622 } | |
| 623 | |
| 624 void SampleCode::PrefSizeR(SkEvent* evt, SkScalar width, SkScalar height) { | |
| 625 SkASSERT(evt && PrefSizeQ(*evt)); | |
| 626 SkScalar size[2]; | |
| 627 size[0] = width; | |
| 628 size[1] = height; | |
| 629 evt->setScalars(gPrefSizeEvtName, 2, size); | |
| 630 } | |
| 631 | |
| 632 bool SampleCode::FastTextQ(const SkEvent& evt) { | |
| 633 return evt.isType(gFastTextEvtName, sizeof(gFastTextEvtName) - 1); | |
| 634 } | |
| 635 | |
| 636 /////////////////////////////////////////////////////////////////////////////// | 533 /////////////////////////////////////////////////////////////////////////////// |
| 637 | 534 |
| 638 enum TilingMode { | 535 enum TilingMode { |
| 639 kNo_Tiling, | 536 kNo_Tiling, |
| 640 kAbs_128x128_Tiling, | 537 kAbs_128x128_Tiling, |
| 641 kAbs_256x256_Tiling, | 538 kAbs_256x256_Tiling, |
| 642 kRel_4x4_Tiling, | 539 kRel_4x4_Tiling, |
| 643 kRel_1x16_Tiling, | 540 kRel_1x16_Tiling, |
| 644 kRel_16x1_Tiling, | 541 kRel_16x1_Tiling, |
| 645 | 542 |
| (...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2207 this->updateTitle(); // to refresh our config | 2104 this->updateTitle(); // to refresh our config |
| 2208 fDevManager->windowSizeChanged(this); | 2105 fDevManager->windowSizeChanged(this); |
| 2209 | 2106 |
| 2210 if (fTilingMode != kNo_Tiling && SampleView::IsSampleView(view)) { | 2107 if (fTilingMode != kNo_Tiling && SampleView::IsSampleView(view)) { |
| 2211 ((SampleView*)view)->onTileSizeChanged(this->tileSize()); | 2108 ((SampleView*)view)->onTileSizeChanged(this->tileSize()); |
| 2212 } | 2109 } |
| 2213 } | 2110 } |
| 2214 | 2111 |
| 2215 /////////////////////////////////////////////////////////////////////////////// | 2112 /////////////////////////////////////////////////////////////////////////////// |
| 2216 | 2113 |
| 2217 static const char is_sample_view_tag[] = "sample-is-sample-view"; | |
| 2218 static const char repeat_count_tag[] = "sample-set-repeat-count"; | |
| 2219 | |
| 2220 bool SampleView::IsSampleView(SkView* view) { | |
| 2221 SkEvent evt(is_sample_view_tag); | |
| 2222 return view->doQuery(&evt); | |
| 2223 } | |
| 2224 | |
| 2225 bool SampleView::SetRepeatDraw(SkView* view, int count) { | |
| 2226 SkEvent evt(repeat_count_tag); | |
| 2227 evt.setFast32(count); | |
| 2228 return view->doEvent(evt); | |
| 2229 } | |
| 2230 | |
| 2231 bool SampleView::onEvent(const SkEvent& evt) { | |
| 2232 if (evt.isType(repeat_count_tag)) { | |
| 2233 fRepeatCount = evt.getFast32(); | |
| 2234 return true; | |
| 2235 } | |
| 2236 return this->INHERITED::onEvent(evt); | |
| 2237 } | |
| 2238 | |
| 2239 bool SampleView::onQuery(SkEvent* evt) { | |
| 2240 if (evt->isType(is_sample_view_tag)) { | |
| 2241 return true; | |
| 2242 } | |
| 2243 return this->INHERITED::onQuery(evt); | |
| 2244 } | |
| 2245 | |
| 2246 void SampleView::onDraw(SkCanvas* canvas) { | |
| 2247 if (!fHaveCalledOnceBeforeDraw) { | |
| 2248 fHaveCalledOnceBeforeDraw = true; | |
| 2249 this->onOnceBeforeDraw(); | |
| 2250 } | |
| 2251 this->onDrawBackground(canvas); | |
| 2252 | |
| 2253 for (int i = 0; i < fRepeatCount; i++) { | |
| 2254 SkAutoCanvasRestore acr(canvas, true); | |
| 2255 this->onDrawContent(canvas); | |
| 2256 #if SK_SUPPORT_GPU | |
| 2257 // Ensure the GrContext doesn't batch across draw loops. | |
| 2258 if (GrContext* context = canvas->getGrContext()) { | |
| 2259 context->flush(); | |
| 2260 } | |
| 2261 #endif | |
| 2262 } | |
| 2263 } | |
| 2264 | |
| 2265 void SampleView::onDrawBackground(SkCanvas* canvas) { | |
| 2266 canvas->drawColor(fBGColor); | |
| 2267 } | |
| 2268 | |
| 2269 /////////////////////////////////////////////////////////////////////////////// | |
| 2270 | |
| 2271 template <typename T> void SkTBSort(T array[], int count) { | 2114 template <typename T> void SkTBSort(T array[], int count) { |
| 2272 for (int i = 1; i < count - 1; i++) { | 2115 for (int i = 1; i < count - 1; i++) { |
| 2273 bool didSwap = false; | 2116 bool didSwap = false; |
| 2274 for (int j = count - 1; j > i; --j) { | 2117 for (int j = count - 1; j > i; --j) { |
| 2275 if (array[j] < array[j-1]) { | 2118 if (array[j] < array[j-1]) { |
| 2276 T tmp(array[j-1]); | 2119 T tmp(array[j-1]); |
| 2277 array[j-1] = array[j]; | 2120 array[j-1] = array[j]; |
| 2278 array[j] = tmp; | 2121 array[j] = tmp; |
| 2279 didSwap = true; | 2122 didSwap = true; |
| 2280 } | 2123 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2399 #ifdef SK_BUILD_FOR_MAC | 2242 #ifdef SK_BUILD_FOR_MAC |
| 2400 setenv("ANDROID_ROOT", "/android/device/data", 0); | 2243 setenv("ANDROID_ROOT", "/android/device/data", 0); |
| 2401 #endif | 2244 #endif |
| 2402 SkGraphics::Init(); | 2245 SkGraphics::Init(); |
| 2403 SkEvent::Init(); | 2246 SkEvent::Init(); |
| 2404 } | 2247 } |
| 2405 | 2248 |
| 2406 void application_term() { | 2249 void application_term() { |
| 2407 SkEvent::Term(); | 2250 SkEvent::Term(); |
| 2408 } | 2251 } |
| OLD | NEW |