Jim Van Verth | be39f71 | 2019-02-08 15:36:14 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 MetalWindowContext_DEFINED |
| 8 | #define MetalWindowContext_DEFINED |
| 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkRefCnt.h" |
| 11 | #include "include/core/SkSurface.h" |
Jim Van Verth | be39f71 | 2019-02-08 15:36:14 -0500 | [diff] [blame] | 12 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "tools/sk_app/WindowContext.h" |
Jim Van Verth | be39f71 | 2019-02-08 15:36:14 -0500 | [diff] [blame] | 14 | |
| 15 | #import <Metal/Metal.h> |
Jim Van Verth | d063e8b | 2019-05-16 10:31:56 -0400 | [diff] [blame] | 16 | #import <QuartzCore/CAMetalLayer.h> |
Jim Van Verth | be39f71 | 2019-02-08 15:36:14 -0500 | [diff] [blame] | 17 | |
| 18 | namespace sk_app { |
| 19 | |
| 20 | class MetalWindowContext : public WindowContext { |
| 21 | public: |
| 22 | sk_sp<SkSurface> getBackbufferSurface() override; |
| 23 | |
| 24 | bool isValid() override { return fValid; } |
| 25 | |
Jim Van Verth | be39f71 | 2019-02-08 15:36:14 -0500 | [diff] [blame] | 26 | void swapBuffers() override; |
| 27 | |
| 28 | void setDisplayParams(const DisplayParams& params) override; |
| 29 | |
Jim Van Verth | 5a89ed5 | 2020-11-16 11:06:58 -0500 | [diff] [blame] | 30 | void activate(bool isActive) override; |
| 31 | |
Jim Van Verth | be39f71 | 2019-02-08 15:36:14 -0500 | [diff] [blame] | 32 | protected: |
Jim Van Verth | 9e64047 | 2020-11-19 12:59:06 -0500 | [diff] [blame^] | 33 | static NSURL* CacheURL(); |
| 34 | |
Jim Van Verth | be39f71 | 2019-02-08 15:36:14 -0500 | [diff] [blame] | 35 | MetalWindowContext(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(); |
| 39 | virtual bool onInitializeContext() = 0; |
| 40 | |
| 41 | // This should be called by subclass destructor. It is also called when window/display |
Jim Van Verth | d063e8b | 2019-05-16 10:31:56 -0400 | [diff] [blame] | 42 | // parameters change prior to initializing a new Metal context. This will in turn call |
Jim Van Verth | be39f71 | 2019-02-08 15:36:14 -0500 | [diff] [blame] | 43 | // onDestroyContext(). |
| 44 | void destroyContext(); |
| 45 | virtual void onDestroyContext() = 0; |
| 46 | |
Jim Van Verth | be39f71 | 2019-02-08 15:36:14 -0500 | [diff] [blame] | 47 | bool fValid; |
| 48 | id<MTLDevice> fDevice; |
| 49 | id<MTLCommandQueue> fQueue; |
Jim Van Verth | d063e8b | 2019-05-16 10:31:56 -0400 | [diff] [blame] | 50 | CAMetalLayer* fMetalLayer; |
Jim Van Verth | cbf59e0 | 2019-10-17 14:58:37 -0400 | [diff] [blame] | 51 | GrMTLHandle fDrawableHandle; |
Jim Van Verth | 9e64047 | 2020-11-19 12:59:06 -0500 | [diff] [blame^] | 52 | #if GR_METAL_SDK_VERSION >= 230 |
| 53 | id<MTLBinaryArchive> fPipelineArchive SK_API_AVAILABLE(macos(11.0), ios(14.0)); |
| 54 | #endif |
Jim Van Verth | be39f71 | 2019-02-08 15:36:14 -0500 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | } // namespace sk_app |
| 58 | |
| 59 | #endif |