blob: 53b81fda1fbe23b294f77482254fbf9753f301fb [file] [log] [blame]
Jim Van Verthbe39f712019-02-08 15:36:14 -05001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkRefCnt.h"
11#include "include/core/SkSurface.h"
Jim Van Verthbe39f712019-02-08 15:36:14 -050012
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "tools/sk_app/WindowContext.h"
Jim Van Verthbe39f712019-02-08 15:36:14 -050014
15#import <Metal/Metal.h>
Jim Van Verthd063e8b2019-05-16 10:31:56 -040016#import <QuartzCore/CAMetalLayer.h>
Jim Van Verthbe39f712019-02-08 15:36:14 -050017
18namespace sk_app {
19
20class MetalWindowContext : public WindowContext {
21public:
22 sk_sp<SkSurface> getBackbufferSurface() override;
23
24 bool isValid() override { return fValid; }
25
Jim Van Verthbe39f712019-02-08 15:36:14 -050026 void swapBuffers() override;
27
28 void setDisplayParams(const DisplayParams& params) override;
29
30protected:
31 MetalWindowContext(const DisplayParams&);
32 // This should be called by subclass constructor. It is also called when window/display
33 // parameters change. This will in turn call onInitializeContext().
34 void initializeContext();
35 virtual bool onInitializeContext() = 0;
36
37 // This should be called by subclass destructor. It is also called when window/display
Jim Van Verthd063e8b2019-05-16 10:31:56 -040038 // parameters change prior to initializing a new Metal context. This will in turn call
Jim Van Verthbe39f712019-02-08 15:36:14 -050039 // onDestroyContext().
40 void destroyContext();
41 virtual void onDestroyContext() = 0;
42
Jim Van Verthbe39f712019-02-08 15:36:14 -050043 bool fValid;
44 id<MTLDevice> fDevice;
45 id<MTLCommandQueue> fQueue;
Jim Van Verthd063e8b2019-05-16 10:31:56 -040046 CAMetalLayer* fMetalLayer;
Jim Van Verthcbf59e02019-10-17 14:58:37 -040047 GrMTLHandle fDrawableHandle;
Jim Van Verthbe39f712019-02-08 15:36:14 -050048};
49
50} // namespace sk_app
51
52#endif