1 /* 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 10 #include "include/core/SkRefCnt.h" 11 #include "include/core/SkSurface.h" 12 13 #include "tools/sk_app/WindowContext.h" 14 15 #import <Metal/Metal.h> 16 #import <QuartzCore/CAMetalLayer.h> 17 18 namespace sk_app { 19 20 class MetalWindowContext : public WindowContext { 21 public: 22 sk_sp<SkSurface> getBackbufferSurface() override; 23 isValid()24 bool isValid() override { return fValid; } 25 26 void swapBuffers() override; 27 28 void setDisplayParams(const DisplayParams& params) override; 29 30 protected: 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 38 // parameters change prior to initializing a new Metal context. This will in turn call 39 // onDestroyContext(). 40 void destroyContext(); 41 virtual void onDestroyContext() = 0; 42 43 bool fValid; 44 id<MTLDevice> fDevice; 45 id<MTLCommandQueue> fQueue; 46 CAMetalLayer* fMetalLayer; 47 id<CAMetalDrawable> fCurrentDrawable; 48 }; 49 50 } // namespace sk_app 51 52 #endif 53