| OLD | NEW |
| (Empty) |
| 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 "SkSurface.h" | |
| 14 #include "SkWindow.h" | |
| 15 #include "SkTRegistry.h" | |
| 16 | |
| 17 class GrContext; | |
| 18 struct GrGLInterface; | |
| 19 class GrRenderTarget; | |
| 20 class SkCanvas; | |
| 21 class SkExampleWindow; | |
| 22 | |
| 23 class SkExample : SkNoncopyable { | |
| 24 public: | |
| 25 SkExample(SkExampleWindow* window) : fWindow(window) {} | |
| 26 | |
| 27 virtual ~SkExample() {} | |
| 28 | |
| 29 // Your class should override this method to do its thing. | |
| 30 virtual void draw(SkCanvas* canvas) = 0; | |
| 31 | |
| 32 SkString getName() { return fName; }; | |
| 33 // Use this public registry to tell the world about your sample. | |
| 34 typedef SkTRegistry<SkExample*(*)(SkExampleWindow*)> Registry; | |
| 35 | |
| 36 protected: | |
| 37 SkExampleWindow* fWindow; | |
| 38 SkString fName; | |
| 39 }; | |
| 40 | |
| 41 class SkExampleWindow : public SkOSWindow { | |
| 42 public: | |
| 43 enum DeviceType { | |
| 44 kRaster_DeviceType, | |
| 45 kGPU_DeviceType, | |
| 46 }; | |
| 47 SkExampleWindow(void* hwnd); | |
| 48 virtual ~SkExampleWindow() SK_OVERRIDE; | |
| 49 | |
| 50 // Changes the device type of the object. | |
| 51 bool setUpBackend(); | |
| 52 | |
| 53 DeviceType getDeviceType() const { return fType; } | |
| 54 | |
| 55 protected: | |
| 56 SkSurface* createSurface() SK_OVERRIDE { | |
| 57 if (kGPU_DeviceType == fType) { | |
| 58 SkSurfaceProps props(INHERITED::getSurfaceProps()); | |
| 59 return SkSurface::NewRenderTargetDirect(fRenderTarget, &props); | |
| 60 } | |
| 61 static const SkImageInfo info = SkImageInfo::MakeN32Premul( | |
| 62 SkScalarRoundToInt(this->width()), SkScalarRoundToInt(this->heig
ht())); | |
| 63 return fSurface = SkSurface::NewRaster(info); | |
| 64 } | |
| 65 | |
| 66 void draw(SkCanvas* canvas) SK_OVERRIDE; | |
| 67 void drawContents(SkCanvas* canvas); | |
| 68 | |
| 69 void onSizeChange() SK_OVERRIDE; | |
| 70 | |
| 71 private: | |
| 72 bool findNextMatch(); // Set example to the first one that matches FLAGS_ma
tch. | |
| 73 void setTitle(); | |
| 74 void setUpRenderTarget(); | |
| 75 bool onHandleChar(SkUnichar unichar) SK_OVERRIDE; | |
| 76 void tearDownBackend(); | |
| 77 | |
| 78 // draw contents | |
| 79 SkScalar fRotationAngle; | |
| 80 | |
| 81 // support framework | |
| 82 DeviceType fType; | |
| 83 SkSurface* fSurface; | |
| 84 GrContext* fContext; | |
| 85 GrRenderTarget* fRenderTarget; | |
| 86 AttachmentInfo fAttachmentInfo; | |
| 87 const GrGLInterface* fInterface; | |
| 88 | |
| 89 typedef SkOSWindow INHERITED; | |
| 90 }; | |
| 91 | |
| 92 #endif | |
| OLD | NEW |