skia2/tools/sk_app/GraphiteMetalWindowContext.h
Jim Van Verth 7bb0ff05ce [graphite] Add support to Mac Viewer.
Adds a type enum to WindowContext to determine which kind of
GPU context (GrDirectContext or skgpu::Context) we're using.

Bug: skia:12466
Change-Id: I288878740392a43cd9e82c925fbe2c372d140dc5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/454699
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
2021-09-30 21:38:25 +00:00

57 lines
1.6 KiB
Objective-C

/*
* Copyright 2021 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GraphiteMetalWindowContext_DEFINED
#define GraphiteMetalWindowContext_DEFINED
#include "include/core/SkRefCnt.h"
#include "include/ports/SkCFObject.h"
#include "tools/sk_app/WindowContext.h"
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
class SkSurface;
namespace sk_app {
class GraphiteMetalWindowContext : public WindowContext {
public:
sk_sp<SkSurface> getBackbufferSurface() override;
bool isValid() override { return fValid; }
void swapBuffers() override;
void setDisplayParams(const DisplayParams& params) override;
void activate(bool isActive) override;
protected:
GraphiteMetalWindowContext(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
// parameters change prior to initializing a new Metal context. This will in turn call
// onDestroyContext().
void destroyContext();
virtual void onDestroyContext() = 0;
bool fValid;
sk_cfp<id<MTLDevice>> fDevice;
sk_cfp<id<MTLCommandQueue>> fQueue;
CAMetalLayer* fMetalLayer;
CFTypeRef fDrawableHandle;
};
} // namespace sk_app
#endif