skia2/tools/sk_app/MetalWindowContext.h
Jim Van Verth cbf59e0e39 Use LazyProxy to set up Metal swapchain.
The purpose of this is to delay acquiring the next drawable in the
swapchain to avoid stalling and gain better parallel execution between
the CPU and GPU.

Change-Id: I40ef7672394fd00616de43685530d2feaf7cab2d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/249005
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
2019-10-18 14:04:41 +00:00

53 lines
1.5 KiB
Objective-C

/*
* 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
#include "include/core/SkRefCnt.h"
#include "include/core/SkSurface.h"
#include "tools/sk_app/WindowContext.h"
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
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;
protected:
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
// parameters change prior to initializing a new Metal context. This will in turn call
// onDestroyContext().
void destroyContext();
virtual void onDestroyContext() = 0;
bool fValid;
id<MTLDevice> fDevice;
id<MTLCommandQueue> fQueue;
CAMetalLayer* fMetalLayer;
GrMTLHandle fDrawableHandle;
};
} // namespace sk_app
#endif