Jorge Betancourt | b7508e2 | 2023-02-14 12:49:32 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 Google LLC |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
Florin Malita | 28f5db5 | 2023-05-02 10:34:11 -0400 | [diff] [blame] | 7 | #ifndef GLWindowContext_DEFINED |
| 8 | #define GLWindowContext_DEFINED |
Jorge Betancourt | b7508e2 | 2023-02-14 12:49:32 -0500 | [diff] [blame] | 9 | |
| 10 | |
| 11 | #include "include/gpu/gl/GrGLInterface.h" |
| 12 | |
| 13 | #include "include/core/SkRefCnt.h" |
| 14 | #include "include/core/SkSurface.h" |
| 15 | |
Florin Malita | 28f5db5 | 2023-05-02 10:34:11 -0400 | [diff] [blame] | 16 | #include "tools/window/WindowContext.h" |
Jorge Betancourt | b7508e2 | 2023-02-14 12:49:32 -0500 | [diff] [blame] | 17 | |
Florin Malita | 28f5db5 | 2023-05-02 10:34:11 -0400 | [diff] [blame] | 18 | namespace skwindow::internal { |
| 19 | |
| 20 | class GLWindowContext : public WindowContext { |
Jorge Betancourt | b7508e2 | 2023-02-14 12:49:32 -0500 | [diff] [blame] | 21 | public: |
| 22 | sk_sp<SkSurface> getBackbufferSurface() override; |
| 23 | |
| 24 | bool isValid() override { return SkToBool(fBackendContext.get()); } |
| 25 | |
| 26 | void resize(int w, int h) override; |
Jorge Betancourt | b7508e2 | 2023-02-14 12:49:32 -0500 | [diff] [blame] | 27 | |
Florin Malita | 28f5db5 | 2023-05-02 10:34:11 -0400 | [diff] [blame] | 28 | void setDisplayParams(const DisplayParams& params) override; |
Jorge Betancourt | b7508e2 | 2023-02-14 12:49:32 -0500 | [diff] [blame] | 29 | |
| 30 | protected: |
Florin Malita | 28f5db5 | 2023-05-02 10:34:11 -0400 | [diff] [blame] | 31 | GLWindowContext(const DisplayParams&); |
Jorge Betancourt | b7508e2 | 2023-02-14 12:49:32 -0500 | [diff] [blame] | 32 | // This should be called by subclass constructor. It is also called when window/display |
| 33 | // parameters change. This will in turn call onInitializeContext(). |
| 34 | void initializeContext(); |
| 35 | virtual sk_sp<const GrGLInterface> onInitializeContext() = 0; |
| 36 | |
| 37 | // This should be called by subclass destructor. It is also called when window/display |
| 38 | // parameters change prior to initializing a new GL context. This will in turn call |
| 39 | // onDestroyContext(). |
| 40 | void destroyContext(); |
| 41 | virtual void onDestroyContext() = 0; |
| 42 | |
Jorge Betancourt | b7508e2 | 2023-02-14 12:49:32 -0500 | [diff] [blame] | 43 | sk_sp<const GrGLInterface> fBackendContext; |
| 44 | sk_sp<SkSurface> fSurface; |
| 45 | }; |
| 46 | |
Florin Malita | 28f5db5 | 2023-05-02 10:34:11 -0400 | [diff] [blame] | 47 | } // namespace skwindow::internal |
| 48 | |
Jorge Betancourt | b7508e2 | 2023-02-14 12:49:32 -0500 | [diff] [blame] | 49 | #endif |