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 #include "SampleApp.h" | 8 #include "SampleApp.h" |
8 | 9 |
9 #include "SkData.h" | 10 #include "SkData.h" |
10 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
11 #include "SkDevice.h" | 12 #include "SkDevice.h" |
12 #include "SkGraphics.h" | 13 #include "SkGraphics.h" |
13 #include "SkImageDecoder.h" | 14 #include "SkImageDecoder.h" |
14 #include "SkImageEncoder.h" | 15 #include "SkImageEncoder.h" |
15 #include "SkPaint.h" | 16 #include "SkPaint.h" |
16 #include "SkPicture.h" | 17 #include "SkPicture.h" |
(...skipping 2246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2263 fRepeatCount = evt.getFast32(); | 2264 fRepeatCount = evt.getFast32(); |
2264 return true; | 2265 return true; |
2265 } | 2266 } |
2266 | 2267 |
2267 int32_t pipeHolder; | 2268 int32_t pipeHolder; |
2268 if (evt.findS32(set_use_pipe_tag, &pipeHolder)) { | 2269 if (evt.findS32(set_use_pipe_tag, &pipeHolder)) { |
2269 fPipeState = static_cast<SkOSMenu::TriState>(pipeHolder); | 2270 fPipeState = static_cast<SkOSMenu::TriState>(pipeHolder); |
2270 return true; | 2271 return true; |
2271 } | 2272 } |
2272 | 2273 |
2273 if (evt.isType("debug-hit-test")) { | |
2274 fDebugHitTest = true; | |
2275 evt.findS32("debug-hit-test-x", &fDebugHitTestLoc.fX); | |
2276 evt.findS32("debug-hit-test-y", &fDebugHitTestLoc.fY); | |
2277 this->inval(NULL); | |
2278 return true; | |
2279 } | |
2280 | |
2281 return this->INHERITED::onEvent(evt); | 2274 return this->INHERITED::onEvent(evt); |
2282 } | 2275 } |
2283 | 2276 |
2284 bool SampleView::onQuery(SkEvent* evt) { | 2277 bool SampleView::onQuery(SkEvent* evt) { |
2285 if (evt->isType(is_sample_view_tag)) { | 2278 if (evt->isType(is_sample_view_tag)) { |
2286 return true; | 2279 return true; |
2287 } | 2280 } |
2288 return this->INHERITED::onQuery(evt); | 2281 return this->INHERITED::onQuery(evt); |
2289 } | 2282 } |
2290 | 2283 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2378 | 2371 |
2379 canvas = writer.startRecording(pc, flags); | 2372 canvas = writer.startRecording(pc, flags); |
2380 //Must draw before controller goes out of scope and sends data | 2373 //Must draw before controller goes out of scope and sends data |
2381 this->INHERITED::draw(canvas); | 2374 this->INHERITED::draw(canvas); |
2382 //explicitly end recording to ensure writer is flushed before the memory | 2375 //explicitly end recording to ensure writer is flushed before the memory |
2383 //is freed in the deconstructor of the controller | 2376 //is freed in the deconstructor of the controller |
2384 writer.endRecording(); | 2377 writer.endRecording(); |
2385 } | 2378 } |
2386 } | 2379 } |
2387 | 2380 |
2388 #include "SkBounder.h" | |
2389 | |
2390 class DebugHitTestBounder : public SkBounder { | |
2391 public: | |
2392 DebugHitTestBounder(int x, int y) { | |
2393 fLoc.set(x, y); | |
2394 } | |
2395 | |
2396 virtual bool onIRect(const SkIRect& bounds) SK_OVERRIDE { | |
2397 if (bounds.contains(fLoc.x(), fLoc.y())) { | |
2398 // | |
2399 // Set a break-point here to see what was being drawn under | |
2400 // the click point (just needed a line of code to stop the debugger) | |
2401 // | |
2402 bounds.centerX(); | |
2403 } | |
2404 return true; | |
2405 } | |
2406 | |
2407 private: | |
2408 SkIPoint fLoc; | |
2409 typedef SkBounder INHERITED; | |
2410 }; | |
2411 | |
2412 void SampleView::onDraw(SkCanvas* canvas) { | 2381 void SampleView::onDraw(SkCanvas* canvas) { |
2413 this->onDrawBackground(canvas); | 2382 this->onDrawBackground(canvas); |
2414 | 2383 |
2415 DebugHitTestBounder bounder(fDebugHitTestLoc.x(), fDebugHitTestLoc.y()); | |
2416 if (fDebugHitTest) { | |
2417 canvas->setBounder(&bounder); | |
2418 } | |
2419 | |
2420 for (int i = 0; i < fRepeatCount; i++) { | 2384 for (int i = 0; i < fRepeatCount; i++) { |
2421 SkAutoCanvasRestore acr(canvas, true); | 2385 SkAutoCanvasRestore acr(canvas, true); |
2422 this->onDrawContent(canvas); | 2386 this->onDrawContent(canvas); |
2423 } | 2387 } |
2424 | |
2425 fDebugHitTest = false; | |
2426 canvas->setBounder(NULL); | |
2427 } | 2388 } |
2428 | 2389 |
2429 void SampleView::onDrawBackground(SkCanvas* canvas) { | 2390 void SampleView::onDrawBackground(SkCanvas* canvas) { |
2430 canvas->drawColor(fBGColor); | 2391 canvas->drawColor(fBGColor); |
2431 } | 2392 } |
2432 | 2393 |
2433 /////////////////////////////////////////////////////////////////////////////// | 2394 /////////////////////////////////////////////////////////////////////////////// |
2434 | 2395 |
2435 template <typename T> void SkTBSort(T array[], int count) { | 2396 template <typename T> void SkTBSort(T array[], int count) { |
2436 for (int i = 1; i < count - 1; i++) { | 2397 for (int i = 1; i < count - 1; i++) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2565 SkGraphics::Init(); | 2526 SkGraphics::Init(); |
2566 SkEvent::Init(); | 2527 SkEvent::Init(); |
2567 } | 2528 } |
2568 | 2529 |
2569 // FIXME: this should be in a header | 2530 // FIXME: this should be in a header |
2570 void application_term(); | 2531 void application_term(); |
2571 void application_term() { | 2532 void application_term() { |
2572 SkEvent::Term(); | 2533 SkEvent::Term(); |
2573 SkGraphics::Term(); | 2534 SkGraphics::Term(); |
2574 } | 2535 } |
OLD | NEW |