jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2016 Google Inc. |
| 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 | #ifndef GLWindowContext_DEFINED |
| 9 | #define GLWindowContext_DEFINED |
| 10 | |
| 11 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/gpu/gl/GrGLInterface.h" |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 13 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/core/SkRefCnt.h" |
| 15 | #include "include/core/SkSurface.h" |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 16 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "tools/sk_app/WindowContext.h" |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 18 | |
| 19 | class GrContext; |
| 20 | |
| 21 | namespace sk_app { |
| 22 | |
| 23 | class GLWindowContext : public WindowContext { |
| 24 | public: |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 25 | sk_sp<SkSurface> getBackbufferSurface() override; |
| 26 | |
| 27 | bool isValid() override { return SkToBool(fBackendContext.get()); } |
| 28 | |
bsalomon | ccde4ab | 2016-07-27 08:50:12 -0700 | [diff] [blame] | 29 | void resize(int w, int h) override; |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 30 | void swapBuffers() override; |
| 31 | |
| 32 | void setDisplayParams(const DisplayParams& params) override; |
| 33 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 34 | protected: |
bsalomon | d1bdd1f | 2016-07-26 12:02:50 -0700 | [diff] [blame] | 35 | GLWindowContext(const DisplayParams&); |
| 36 | // This should be called by subclass constructor. It is also called when window/display |
| 37 | // parameters change. This will in turn call onInitializeContext(). |
| 38 | void initializeContext(); |
Brian Salomon | 194db17 | 2017-08-17 14:37:06 -0400 | [diff] [blame] | 39 | virtual sk_sp<const GrGLInterface> onInitializeContext() = 0; |
bsalomon | d1bdd1f | 2016-07-26 12:02:50 -0700 | [diff] [blame] | 40 | |
| 41 | // This should be called by subclass destructor. It is also called when window/display |
| 42 | // parameters change prior to initializing a new GL context. This will in turn call |
| 43 | // onDestroyContext(). |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 44 | void destroyContext(); |
| 45 | virtual void onDestroyContext() = 0; |
bsalomon | d1bdd1f | 2016-07-26 12:02:50 -0700 | [diff] [blame] | 46 | |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 47 | virtual void onSwapBuffers() = 0; |
| 48 | |
Hal Canary | 1b612a8 | 2016-11-03 16:26:13 -0400 | [diff] [blame] | 49 | sk_sp<const GrGLInterface> fBackendContext; |
| 50 | sk_sp<SkSurface> fSurface; |
jvanverth | af236b5 | 2016-05-20 06:01:06 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | } // namespace sk_app |
| 54 | |
| 55 | #endif |