d063e8b6f1
Windowing and events: * Use a NSTrackingArea to only capture mouse events within the view. * Use ViewDelegate to track events rather than pulling them out of the event pump. * Sets up the autoreleasepool correctly to clear out old events Context creation: * Don't use a subview for OpenGL (it's not necessary). * For Metal, use a CAMetalLayer rather than MTKView. * Add vsync support to Metal. Bug: skia:8737 Change-Id: I8ea5cc865df65f8dc2fef47082bf6a4d1657cf03 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/213672 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
53 lines
1.5 KiB
Objective-C
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;
|
|
id<CAMetalDrawable> fCurrentDrawable;
|
|
};
|
|
|
|
} // namespace sk_app
|
|
|
|
#endif
|