jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | #ifndef WindowContext_DEFINED |
| 8 | #define WindowContext_DEFINED |
| 9 | |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 10 | #include "DisplayParams.h" |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 11 | #include "GrTypes.h" |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 12 | #include "SkRefCnt.h" |
| 13 | #include "SkSurfaceProps.h" |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 14 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 15 | class GrContext; |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 16 | class SkSurface; |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 17 | class GrRenderTarget; |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 18 | |
| 19 | namespace sk_app { |
| 20 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 21 | class WindowContext { |
| 22 | public: |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 23 | WindowContext() : fContext(nullptr) |
| 24 | , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType) {} |
| 25 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 26 | virtual ~WindowContext() {} |
| 27 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 28 | virtual sk_sp<SkSurface> getBackbufferSurface() = 0; |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 29 | |
| 30 | virtual void swapBuffers() = 0; |
| 31 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 32 | virtual bool isValid() = 0; |
| 33 | |
bsalomon | ccde4ab | 2016-07-27 08:50:12 -0700 | [diff] [blame^] | 34 | virtual void resize(int w, int h) = 0; |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 35 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 36 | const DisplayParams& getDisplayParams() { return fDisplayParams; } |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 37 | virtual void setDisplayParams(const DisplayParams& params) = 0; |
| 38 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 39 | SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; } |
| 40 | void setSurfaceProps(const SkSurfaceProps& props) { |
| 41 | fSurfaceProps = props; |
| 42 | } |
| 43 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 44 | virtual GrBackendContext getBackendContext() = 0; |
djsollen | 7e73108 | 2016-06-09 13:07:13 -0700 | [diff] [blame] | 45 | GrContext* getGrContext() const { return fContext; } |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 46 | |
liyuqian | 74959a1 | 2016-06-16 14:10:34 -0700 | [diff] [blame] | 47 | sk_sp<SkSurface> createOffscreenSurface(bool sRGB); |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 48 | void presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<GrRenderTarget> rt, |
| 49 | int colorBits); |
| 50 | |
| 51 | protected: |
| 52 | virtual bool isGpuContext() { return true; } |
| 53 | |
bsalomon | c7b4b28 | 2016-07-19 09:46:29 -0700 | [diff] [blame] | 54 | sk_sp<SkSurface> createRenderSurface(GrBackendRenderTargetDesc, int colorBits); |
| 55 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 56 | GrContext* fContext; |
| 57 | |
| 58 | int fWidth; |
| 59 | int fHeight; |
| 60 | DisplayParams fDisplayParams; |
| 61 | GrPixelConfig fPixelConfig; |
| 62 | SkSurfaceProps fSurfaceProps; |
liyuqian | 74959a1 | 2016-06-16 14:10:34 -0700 | [diff] [blame] | 63 | |
| 64 | private: |
| 65 | sk_sp<SkSurface> createSurface( |
bsalomon | c7b4b28 | 2016-07-19 09:46:29 -0700 | [diff] [blame] | 66 | GrBackendRenderTargetDesc*, int colorBits, bool offscreen, bool forceSRGB); |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | } // namespace sk_app |
| 70 | |
| 71 | #endif |