blob: fc712d7d5541772008897bc9dbbee9d4f85c4077 [file] [log] [blame]
Jim Van Verthbe39f712019-02-08 15:36:14 -05001
2/*
3 * Copyright 2019 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#ifndef MetalWindowContext_DEFINED
9#define MetalWindowContext_DEFINED
10
11#include "SkRefCnt.h"
12#include "SkSurface.h"
13
14#include "WindowContext.h"
15
16#import <Metal/Metal.h>
17#import <MetalKit/MetalKit.h>
18
19class GrContext;
20
21namespace sk_app {
22
23class MetalWindowContext : public WindowContext {
24public:
25 sk_sp<SkSurface> getBackbufferSurface() override;
26
27 bool isValid() override { return fValid; }
28
29 void resize(int w, int h) override;
30 void swapBuffers() override;
31
32 void setDisplayParams(const DisplayParams& params) override;
33
34protected:
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
42 // parameters change prior to initializing a new GL context. This will in turn call
43 // onDestroyContext().
44 void destroyContext();
45 virtual void onDestroyContext() = 0;
46
47
48 bool fValid;
49 id<MTLDevice> fDevice;
50 id<MTLCommandQueue> fQueue;
51 dispatch_semaphore_t fInFlightSemaphore;
52 MTKView* fMTKView;
53 sk_sp<SkSurface> fSurface;
54};
55
56} // namespace sk_app
57
58#endif