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); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 28 | virtual ~HelloWorldWindow() override; |
caryclark | 52edc4d | 2015-02-02 12:55:14 -0800 | [diff] [blame] | 29 | |
| 30 | // Changes the device type of the object. |
| 31 | bool setUpBackend(); |
| 32 | |
| 33 | DeviceType getDeviceType() const { return fType; } |
| 34 | |
| 35 | protected: |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 36 | sk_sp<SkSurface> makeSurface() override { |
robertphillips | 702edbd | 2015-06-23 06:26:08 -0700 | [diff] [blame] | 37 | SkSurfaceProps props(INHERITED::getSurfaceProps()); |
caryclark | 52edc4d | 2015-02-02 12:55:14 -0800 | [diff] [blame] | 38 | if (kGPU_DeviceType == fType) { |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 39 | return fGpuSurface; |
caryclark | 52edc4d | 2015-02-02 12:55:14 -0800 | [diff] [blame] | 40 | } |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 41 | const SkImageInfo info = SkImageInfo::MakeN32Premul(SkScalarRoundToInt(this->width()), |
| 42 | SkScalarRoundToInt(this->height())); |
| 43 | fRasterSurface = SkSurface::MakeRaster(info, &props); |
| 44 | return fRasterSurface; |
robertphillips | 702edbd | 2015-06-23 06:26:08 -0700 | [diff] [blame] | 45 | } |
caryclark | 52edc4d | 2015-02-02 12:55:14 -0800 | [diff] [blame] | 46 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 47 | void draw(SkCanvas* canvas) override; |
caryclark | 52edc4d | 2015-02-02 12:55:14 -0800 | [diff] [blame] | 48 | void drawContents(SkCanvas* canvas); |
| 49 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 50 | void onSizeChange() override; |
caryclark | 52edc4d | 2015-02-02 12:55:14 -0800 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | bool findNextMatch(); // Set example to the first one that matches FLAGS_match. |
| 54 | void setTitle(); |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 55 | void setUpGpuBackedSurface(); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 56 | bool onHandleChar(SkUnichar unichar) override; |
caryclark | 52edc4d | 2015-02-02 12:55:14 -0800 | [diff] [blame] | 57 | void tearDownBackend(); |
| 58 | |
| 59 | // draw contents |
| 60 | SkScalar fRotationAngle; |
| 61 | |
| 62 | // support framework |
| 63 | DeviceType fType; |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 64 | sk_sp<SkSurface> fRasterSurface; |
caryclark | 52edc4d | 2015-02-02 12:55:14 -0800 | [diff] [blame] | 65 | GrContext* fContext; |
robertphillips | ecf3dbe | 2016-07-28 15:17:34 -0700 | [diff] [blame] | 66 | sk_sp<SkSurface> fGpuSurface; |
caryclark | 52edc4d | 2015-02-02 12:55:14 -0800 | [diff] [blame] | 67 | AttachmentInfo fAttachmentInfo; |
| 68 | const GrGLInterface* fInterface; |
| 69 | |
| 70 | typedef SkOSWindow INHERITED; |
| 71 | }; |
| 72 | |
| 73 | #endif |