Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / tools / sk_app / MetalWindowContext.h
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
10 #include "include/core/SkRefCnt.h"
11 #include "include/core/SkSurface.h"
12 #include "include/ports/SkCFObject.h"
13 #include "include/private/gpu/ganesh/GrMtlTypesPriv.h"
14
15 #include "tools/sk_app/WindowContext.h"
16
17 #import <Metal/Metal.h>
18 #import <QuartzCore/CAMetalLayer.h>
19
20 namespace sk_app {
21
22 class MetalWindowContext : public WindowContext {
23 public:
24     sk_sp<SkSurface> getBackbufferSurface() override;
25
26     bool isValid() override { return fValid; }
27
28     void swapBuffers() override;
29
30     void setDisplayParams(const DisplayParams& params) override;
31
32     void activate(bool isActive) override;
33
34 protected:
35     static NSURL* CacheURL();
36
37     MetalWindowContext(const DisplayParams&);
38     // This should be called by subclass constructor. It is also called when window/display
39     // parameters change. This will in turn call onInitializeContext().
40     void initializeContext();
41     virtual bool onInitializeContext() = 0;
42
43     // This should be called by subclass destructor. It is also called when window/display
44     // parameters change prior to initializing a new Metal context. This will in turn call
45     // onDestroyContext().
46     void destroyContext();
47     virtual void onDestroyContext() = 0;
48
49     bool                        fValid;
50     sk_cfp<id<MTLDevice>>       fDevice;
51     sk_cfp<id<MTLCommandQueue>> fQueue;
52     CAMetalLayer*               fMetalLayer;
53     GrMTLHandle                 fDrawableHandle;
54 #if GR_METAL_SDK_VERSION >= 230
55     // wrapping this in sk_cfp throws up an availability warning, so we'll track lifetime manually
56     id<MTLBinaryArchive>        fPipelineArchive SK_API_AVAILABLE(macos(11.0), ios(14.0));
57 #endif
58 };
59
60 }   // namespace sk_app
61
62 #endif