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 | |
| 26 | // Your class should override this method to do its thing. |
| 27 | virtual void draw(SkCanvas* canvas) = 0; |
| 28 | |
| 29 | SkString getName() { return fName; }; |
| 30 | // Use this public registry to tell the world about your sample. |
mtklein@google.com | bd6343b | 2013-09-04 17:20:18 +0000 | [diff] [blame] | 31 | typedef SkTRegistry<SkExample*(*)(SkExampleWindow*)> Registry; |
sglez@google.com | 43f2b2c | 2013-07-24 17:48:03 +0000 | [diff] [blame] | 32 | |
| 33 | protected: |
| 34 | SkExampleWindow* fWindow; |
| 35 | SkString fName; |
| 36 | }; |
| 37 | |
| 38 | class SkExampleWindow : public SkOSWindow { |
| 39 | public: |
| 40 | enum DeviceType { |
| 41 | kRaster_DeviceType, |
| 42 | kGPU_DeviceType, |
| 43 | }; |
| 44 | SkExampleWindow(void* hwnd); |
| 45 | |
| 46 | // Changes the device type of the object. |
| 47 | bool setupBackend(DeviceType type); |
| 48 | void tearDownBackend(); |
| 49 | |
| 50 | DeviceType getDeviceType() const { return fType; } |
| 51 | |
| 52 | protected: |
| 53 | virtual void draw(SkCanvas* canvas) SK_OVERRIDE; |
| 54 | |
| 55 | virtual void onSizeChange() SK_OVERRIDE; |
| 56 | |
| 57 | #ifdef SK_BUILD_FOR_WIN |
| 58 | virtual void onHandleInval(const SkIRect&) SK_OVERRIDE; |
| 59 | #endif |
| 60 | |
| 61 | SkCanvas* createCanvas() SK_OVERRIDE; |
| 62 | |
| 63 | private: |
| 64 | bool findNextMatch(); // Set example to the first one that matches FLAGS_match. |
| 65 | void setupRenderTarget(); |
| 66 | bool onHandleChar(SkUnichar unichar) SK_OVERRIDE; |
| 67 | |
| 68 | DeviceType fType; |
| 69 | |
| 70 | SkExample* fCurrExample; |
| 71 | const SkExample::Registry* fRegistry; |
sglez@google.com | 43f2b2c | 2013-07-24 17:48:03 +0000 | [diff] [blame] | 72 | GrContext* fContext; |
| 73 | GrRenderTarget* fRenderTarget; |
| 74 | AttachmentInfo fAttachmentInfo; |
| 75 | const GrGLInterface* fInterface; |
| 76 | |
| 77 | typedef SkOSWindow INHERITED; |
| 78 | }; |
| 79 | |
| 80 | #endif |