SkExample.h revision bd6343b1d60d2a85e930f33f4b06b4502b3e8caa
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 16class GrContext; 17struct GrGLInterface; 18class GrRenderTarget; 19class SkCanvas; 20class SkExampleWindow; 21 22class SkExample : public SkNoncopyable { 23public: 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. 31 typedef SkTRegistry<SkExample*(*)(SkExampleWindow*)> Registry; 32 33protected: 34 SkExampleWindow* fWindow; 35 SkString fName; 36}; 37 38class SkExampleWindow : public SkOSWindow { 39public: 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 52protected: 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 63private: 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; 72 GrContext* fContext; 73 GrRenderTarget* fRenderTarget; 74 AttachmentInfo fAttachmentInfo; 75 const GrGLInterface* fInterface; 76 77 typedef SkOSWindow INHERITED; 78}; 79 80#endif 81