2019-02-08 20:36:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2019 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#ifndef MetalWindowContext_DEFINED
|
|
|
|
#define MetalWindowContext_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
2021-02-22 14:41:27 +00:00
|
|
|
#include "include/ports/SkCFObject.h"
|
2022-04-12 13:59:38 +00:00
|
|
|
#include "include/private/gpu/ganesh/GrMtlTypesPriv.h"
|
2019-02-08 20:36:14 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/sk_app/WindowContext.h"
|
2019-02-08 20:36:14 +00:00
|
|
|
|
|
|
|
#import <Metal/Metal.h>
|
2019-05-16 14:31:56 +00:00
|
|
|
#import <QuartzCore/CAMetalLayer.h>
|
2019-02-08 20:36:14 +00:00
|
|
|
|
|
|
|
namespace sk_app {
|
|
|
|
|
|
|
|
class MetalWindowContext : public WindowContext {
|
|
|
|
public:
|
|
|
|
sk_sp<SkSurface> getBackbufferSurface() override;
|
|
|
|
|
|
|
|
bool isValid() override { return fValid; }
|
|
|
|
|
|
|
|
void swapBuffers() override;
|
|
|
|
|
|
|
|
void setDisplayParams(const DisplayParams& params) override;
|
|
|
|
|
2020-11-16 16:06:58 +00:00
|
|
|
void activate(bool isActive) override;
|
|
|
|
|
2019-02-08 20:36:14 +00:00
|
|
|
protected:
|
2020-11-19 17:59:06 +00:00
|
|
|
static NSURL* CacheURL();
|
|
|
|
|
2019-02-08 20:36:14 +00:00
|
|
|
MetalWindowContext(const DisplayParams&);
|
|
|
|
// This should be called by subclass constructor. It is also called when window/display
|
|
|
|
// parameters change. This will in turn call onInitializeContext().
|
|
|
|
void initializeContext();
|
|
|
|
virtual bool onInitializeContext() = 0;
|
|
|
|
|
|
|
|
// This should be called by subclass destructor. It is also called when window/display
|
2019-05-16 14:31:56 +00:00
|
|
|
// parameters change prior to initializing a new Metal context. This will in turn call
|
2019-02-08 20:36:14 +00:00
|
|
|
// onDestroyContext().
|
|
|
|
void destroyContext();
|
|
|
|
virtual void onDestroyContext() = 0;
|
|
|
|
|
|
|
|
bool fValid;
|
2021-02-22 14:41:27 +00:00
|
|
|
sk_cfp<id<MTLDevice>> fDevice;
|
|
|
|
sk_cfp<id<MTLCommandQueue>> fQueue;
|
2019-05-16 14:31:56 +00:00
|
|
|
CAMetalLayer* fMetalLayer;
|
2019-10-17 18:58:37 +00:00
|
|
|
GrMTLHandle fDrawableHandle;
|
2020-11-19 17:59:06 +00:00
|
|
|
#if GR_METAL_SDK_VERSION >= 230
|
2021-02-22 14:41:27 +00:00
|
|
|
// wrapping this in sk_cfp throws up an availability warning, so we'll track lifetime manually
|
|
|
|
id<MTLBinaryArchive> fPipelineArchive SK_API_AVAILABLE(macos(11.0), ios(14.0));
|
2020-11-19 17:59:06 +00:00
|
|
|
#endif
|
2019-02-08 20:36:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sk_app
|
|
|
|
|
|
|
|
#endif
|