sglez@google.com | 43f2b2c | 2013-07-24 17:48:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #ifndef SkExample_DEFINED |
| 11 | #define SkExample_DEFINED |
| 12 | |
| 13 | #include "SkWindow.h" |
| 14 | #include "SkTRegistry.h" |
| 15 | |
| 16 | class GrContext; |
| 17 | struct GrGLInterface; |
| 18 | class GrRenderTarget; |
| 19 | class SkCanvas; |
| 20 | class SkExampleWindow; |
| 21 | |
| 22 | class SkExample : public SkNoncopyable { |
| 23 | public: |
| 24 | SkExample(SkExampleWindow* window) : fWindow(window) {} |
| 25 | |
commit-bot@chromium.org | b09bfcb | 2013-12-17 23:37:38 +0000 | [diff] [blame^] | 26 | virtual ~SkExample() {} |
| 27 | |
sglez@google.com | 43f2b2c | 2013-07-24 17:48:03 +0000 | [diff] [blame] | 28 | // Your class should override this method to do its thing. |
| 29 | virtual void draw(SkCanvas* canvas) = 0; |
| 30 | |
| 31 | SkString getName() { return fName; }; |
| 32 | // Use this public registry to tell the world about your sample. |
mtklein@google.com | bd6343b | 2013-09-04 17:20:18 +0000 | [diff] [blame] | 33 | typedef SkTRegistry<SkExample*(*)(SkExampleWindow*)> Registry; |
sglez@google.com | 43f2b2c | 2013-07-24 17:48:03 +0000 | [diff] [blame] | 34 | |
| 35 | protected: |
| 36 | SkExampleWindow* fWindow; |
| 37 | SkString fName; |
| 38 | }; |
| 39 | |
| 40 | class SkExampleWindow : public SkOSWindow { |
| 41 | public: |
| 42 | enum DeviceType { |
| 43 | kRaster_DeviceType, |
| 44 | kGPU_DeviceType, |
| 45 | }; |
| 46 | SkExampleWindow(void* hwnd); |
| 47 | |
| 48 | // Changes the device type of the object. |
| 49 | bool setupBackend(DeviceType type); |
| 50 | void tearDownBackend(); |
| 51 | |
| 52 | DeviceType getDeviceType() const { return fType; } |
| 53 | |
| 54 | protected: |
| 55 | virtual void draw(SkCanvas* canvas) SK_OVERRIDE; |
| 56 | |
| 57 | virtual void onSizeChange() SK_OVERRIDE; |
| 58 | |
| 59 | #ifdef SK_BUILD_FOR_WIN |
| 60 | virtual void onHandleInval(const SkIRect&) SK_OVERRIDE; |
| 61 | #endif |
| 62 | |
| 63 | SkCanvas* createCanvas() SK_OVERRIDE; |
| 64 | |
| 65 | private: |
| 66 | bool findNextMatch(); // Set example to the first one that matches FLAGS_match. |
| 67 | void setupRenderTarget(); |
| 68 | bool onHandleChar(SkUnichar unichar) SK_OVERRIDE; |
| 69 | |
| 70 | DeviceType fType; |
| 71 | |
| 72 | SkExample* fCurrExample; |
| 73 | const SkExample::Registry* fRegistry; |
sglez@google.com | 43f2b2c | 2013-07-24 17:48:03 +0000 | [diff] [blame] | 74 | GrContext* fContext; |
| 75 | GrRenderTarget* fRenderTarget; |
| 76 | AttachmentInfo fAttachmentInfo; |
| 77 | const GrGLInterface* fInterface; |
| 78 | |
| 79 | typedef SkOSWindow INHERITED; |
| 80 | }; |
| 81 | |
| 82 | #endif |