Debian Codegraph @

tools/window/GraphiteNativeMetalWindowContext.h

raw
1 /*
2 * Copyright 2021 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 GraphiteMetalWindowContext_DEFINED
8 #define GraphiteMetalWindowContext_DEFINED
9
10 #include "include/core/SkRefCnt.h"
11 #include "include/ports/SkCFObject.h"
12
13 #include "tools/window/WindowContext.h"
14
15 #import <Metal/Metal.h>
16 #import <QuartzCore/CAMetalLayer.h>
17
18 class SkSurface;
19
20 namespace skwindow::internal {
21
22 class GraphiteMetalWindowContext : public WindowContext {
23 public:
24 sk_sp<SkSurface> getBackbufferSurface() override;
25
26 bool isValid() override { return fValid; }
27
28 void setDisplayParams(std::unique_ptr<const DisplayParams> params) override;
29
30 void activate(bool isActive) override;
31
32 protected:
33 GraphiteMetalWindowContext(std::unique_ptr<const DisplayParams>);
34 // This should be called by subclass constructor. It is also called when window/display
35 // parameters change. This will in turn call onInitializeContext().
36 void initializeContext();
37 virtual bool onInitializeContext() = 0;
38
39 // This should be called by subclass destructor. It is also called when window/display
40 // parameters change prior to initializing a new Metal context. This will in turn call
41 // onDestroyContext().
42 void destroyContext();
43 virtual void onDestroyContext() = 0;
44
45 void onSwapBuffers() override;
46
47 bool fValid;
48 sk_cfp<id<MTLDevice>> fDevice;
49 sk_cfp<id<MTLCommandQueue>> fQueue;
50 CAMetalLayer* fMetalLayer;
51 CFTypeRef fDrawableHandle;
52 };
53
54 } // namespace skwindow::internal
55
56 #endif