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" |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 11 | #include "GrContext.h" |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 12 | #include "GrTypes.h" |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 13 | #include "SkRefCnt.h" |
| 14 | #include "SkSurfaceProps.h" |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 15 | |
| 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: |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 23 | WindowContext(const DisplayParams& params) |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 24 | : fContext(nullptr) |
| 25 | , fDisplayParams(params) |
| 26 | , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType) |
| 27 | , fSampleCount(1) |
| 28 | , fStencilBits(0) {} |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 29 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 30 | virtual ~WindowContext() {} |
| 31 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 32 | virtual sk_sp<SkSurface> getBackbufferSurface() = 0; |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 33 | |
| 34 | virtual void swapBuffers() = 0; |
| 35 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 36 | virtual bool isValid() = 0; |
| 37 | |
bsalomon | ccde4ab | 2016-07-27 08:50:12 -0700 | [diff] [blame] | 38 | virtual void resize(int w, int h) = 0; |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 39 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 40 | const DisplayParams& getDisplayParams() { return fDisplayParams; } |
brianosman | 05de216 | 2016-05-06 13:28:57 -0700 | [diff] [blame] | 41 | virtual void setDisplayParams(const DisplayParams& params) = 0; |
| 42 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 43 | SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; } |
| 44 | void setSurfaceProps(const SkSurfaceProps& props) { |
| 45 | fSurfaceProps = props; |
| 46 | } |
| 47 | |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 48 | virtual GrBackendContext getBackendContext() = 0; |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 49 | GrContext* getGrContext() const { return fContext.get(); } |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 50 | |
Christopher Dalton | 443ec1b | 2017-02-24 13:22:53 -0700 | [diff] [blame] | 51 | int width() const { return fWidth; } |
| 52 | int height() const { return fHeight; } |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 53 | int sampleCount() const { return fSampleCount; } |
| 54 | int stencilBits() const { return fStencilBits; } |
Christopher Dalton | 443ec1b | 2017-02-24 13:22:53 -0700 | [diff] [blame] | 55 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 56 | protected: |
| 57 | virtual bool isGpuContext() { return true; } |
| 58 | |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 59 | sk_sp<GrContext> fContext; |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 60 | |
| 61 | int fWidth; |
| 62 | int fHeight; |
| 63 | DisplayParams fDisplayParams; |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 64 | SkSurfaceProps fSurfaceProps; |
csmartdalton | 578f064 | 2017-02-24 16:04:47 -0700 | [diff] [blame] | 65 | |
| 66 | // parameters obtained from the native window |
| 67 | // Note that the platform .cpp file is responsible for |
| 68 | // initializing fSampleCount and fStencilBits! |
| 69 | int fSampleCount; |
| 70 | int fStencilBits; |
jvanverth | a8d0d6c | 2016-05-05 12:32:03 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } // namespace sk_app |
| 74 | |
| 75 | #endif |