caryclark | 52edc4d | 2015-02-02 12:55:14 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 HelloWorld_DEFINED |
| 11 | #define HelloWorld_DEFINED |
| 12 | |
| 13 | #include "SkSurface.h" |
| 14 | #include "SkWindow.h" |
| 15 | |
| 16 | class GrContext; |
| 17 | struct GrGLInterface; |
| 18 | class GrRenderTarget; |
| 19 | class SkCanvas; |
| 20 | |
| 21 | class HelloWorldWindow : public SkOSWindow { |
| 22 | public: |
| 23 | enum DeviceType { |
| 24 | kRaster_DeviceType, |
| 25 | kGPU_DeviceType, |
| 26 | }; |
| 27 | HelloWorldWindow(void* hwnd); |
| 28 | virtual ~HelloWorldWindow() SK_OVERRIDE; |
| 29 | |
| 30 | // Changes the device type of the object. |
| 31 | bool setUpBackend(); |
| 32 | |
| 33 | DeviceType getDeviceType() const { return fType; } |
| 34 | |
| 35 | protected: |
| 36 | SkSurface* createSurface() SK_OVERRIDE { |
| 37 | if (kGPU_DeviceType == fType) { |
| 38 | SkSurfaceProps props(INHERITED::getSurfaceProps()); |
| 39 | return SkSurface::NewRenderTargetDirect(fRenderTarget, &props); |
| 40 | } |
| 41 | static const SkImageInfo info = SkImageInfo::MakeN32Premul( |
| 42 | SkScalarRoundToInt(this->width()), SkScalarRoundToInt(this->height())); |
| 43 | return fSurface = SkSurface::NewRaster(info); |
| 44 | } |
| 45 | |
| 46 | void draw(SkCanvas* canvas) SK_OVERRIDE; |
| 47 | void drawContents(SkCanvas* canvas); |
| 48 | |
| 49 | void onSizeChange() SK_OVERRIDE; |
| 50 | |
| 51 | private: |
| 52 | bool findNextMatch(); // Set example to the first one that matches FLAGS_match. |
| 53 | void setTitle(); |
| 54 | void setUpRenderTarget(); |
| 55 | bool onHandleChar(SkUnichar unichar) SK_OVERRIDE; |
| 56 | void tearDownBackend(); |
| 57 | |
| 58 | // draw contents |
| 59 | SkScalar fRotationAngle; |
| 60 | |
| 61 | // support framework |
| 62 | DeviceType fType; |
| 63 | SkSurface* fSurface; |
| 64 | GrContext* fContext; |
| 65 | GrRenderTarget* fRenderTarget; |
| 66 | AttachmentInfo fAttachmentInfo; |
| 67 | const GrGLInterface* fInterface; |
| 68 | |
| 69 | typedef SkOSWindow INHERITED; |
| 70 | }; |
| 71 | |
| 72 | #endif |