blob: d3fc7cfb16a2279d420cb3416d01083346881749 [file] [log] [blame]
caryclark52edc4d2015-02-02 12:55:14 -08001/*
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
16class GrContext;
17struct GrGLInterface;
18class GrRenderTarget;
19class SkCanvas;
20
21class HelloWorldWindow : public SkOSWindow {
22public:
23 enum DeviceType {
24 kRaster_DeviceType,
25 kGPU_DeviceType,
26 };
27 HelloWorldWindow(void* hwnd);
mtklein36352bf2015-03-25 18:17:31 -070028 virtual ~HelloWorldWindow() override;
caryclark52edc4d2015-02-02 12:55:14 -080029
30 // Changes the device type of the object.
31 bool setUpBackend();
32
33 DeviceType getDeviceType() const { return fType; }
34
35protected:
robertphillipsecf3dbe2016-07-28 15:17:34 -070036 sk_sp<SkSurface> makeSurface() override {
robertphillips702edbd2015-06-23 06:26:08 -070037 SkSurfaceProps props(INHERITED::getSurfaceProps());
caryclark52edc4d2015-02-02 12:55:14 -080038 if (kGPU_DeviceType == fType) {
robertphillipsecf3dbe2016-07-28 15:17:34 -070039 return fGpuSurface;
caryclark52edc4d2015-02-02 12:55:14 -080040 }
robertphillipsecf3dbe2016-07-28 15:17:34 -070041 const SkImageInfo info = SkImageInfo::MakeN32Premul(SkScalarRoundToInt(this->width()),
42 SkScalarRoundToInt(this->height()));
43 fRasterSurface = SkSurface::MakeRaster(info, &props);
44 return fRasterSurface;
robertphillips702edbd2015-06-23 06:26:08 -070045 }
caryclark52edc4d2015-02-02 12:55:14 -080046
mtklein36352bf2015-03-25 18:17:31 -070047 void draw(SkCanvas* canvas) override;
caryclark52edc4d2015-02-02 12:55:14 -080048 void drawContents(SkCanvas* canvas);
49
mtklein36352bf2015-03-25 18:17:31 -070050 void onSizeChange() override;
caryclark52edc4d2015-02-02 12:55:14 -080051
52private:
53 bool findNextMatch(); // Set example to the first one that matches FLAGS_match.
54 void setTitle();
robertphillipsecf3dbe2016-07-28 15:17:34 -070055 void setUpGpuBackedSurface();
mtklein36352bf2015-03-25 18:17:31 -070056 bool onHandleChar(SkUnichar unichar) override;
caryclark52edc4d2015-02-02 12:55:14 -080057 void tearDownBackend();
58
59 // draw contents
60 SkScalar fRotationAngle;
61
62 // support framework
63 DeviceType fType;
robertphillipsecf3dbe2016-07-28 15:17:34 -070064 sk_sp<SkSurface> fRasterSurface;
caryclark52edc4d2015-02-02 12:55:14 -080065 GrContext* fContext;
robertphillipsecf3dbe2016-07-28 15:17:34 -070066 sk_sp<SkSurface> fGpuSurface;
caryclark52edc4d2015-02-02 12:55:14 -080067 AttachmentInfo fAttachmentInfo;
68 const GrGLInterface* fInterface;
69
70 typedef SkOSWindow INHERITED;
71};
72
73#endif