2 * Copyright 2021 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
7 #ifndef GraphiteMetalWindowContext_DEFINED
8 #define GraphiteMetalWindowContext_DEFINED
10 #include "include/core/SkRefCnt.h"
11 #include "include/ports/SkCFObject.h"
13 #include "tools/sk_app/WindowContext.h"
15 #import <Metal/Metal.h>
16 #import <QuartzCore/CAMetalLayer.h>
22 class GraphiteMetalWindowContext : public WindowContext {
24 sk_sp<SkSurface> getBackbufferSurface() override;
26 bool isValid() override { return fValid; }
28 void swapBuffers() override;
30 void setDisplayParams(const DisplayParams& params) override;
32 void activate(bool isActive) override;
35 GraphiteMetalWindowContext(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;
41 // This should be called by subclass destructor. It is also called when window/display
42 // parameters change prior to initializing a new Metal context. This will in turn call
43 // onDestroyContext().
44 void destroyContext();
45 virtual void onDestroyContext() = 0;
48 sk_cfp<id<MTLDevice>> fDevice;
49 sk_cfp<id<MTLCommandQueue>> fQueue;
50 CAMetalLayer* fMetalLayer;
51 CFTypeRef fDrawableHandle;