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