MetalWindowContext.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include "include/core/SkRefCnt.h"
  10. #include "include/core/SkSurface.h"
  11. #include "tools/sk_app/WindowContext.h"
  12. #import <Metal/Metal.h>
  13. #import <QuartzCore/CAMetalLayer.h>
  14. namespace sk_app {
  15. class MetalWindowContext : public WindowContext {
  16. public:
  17. sk_sp<SkSurface> getBackbufferSurface() override;
  18. bool isValid() override { return fValid; }
  19. void swapBuffers() override;
  20. void setDisplayParams(const DisplayParams& params) override;
  21. protected:
  22. MetalWindowContext(const DisplayParams&);
  23. // This should be called by subclass constructor. It is also called when window/display
  24. // parameters change. This will in turn call onInitializeContext().
  25. void initializeContext();
  26. virtual bool onInitializeContext() = 0;
  27. // This should be called by subclass destructor. It is also called when window/display
  28. // parameters change prior to initializing a new Metal context. This will in turn call
  29. // onDestroyContext().
  30. void destroyContext();
  31. virtual void onDestroyContext() = 0;
  32. bool fValid;
  33. id<MTLDevice> fDevice;
  34. id<MTLCommandQueue> fQueue;
  35. CAMetalLayer* fMetalLayer;
  36. id<CAMetalDrawable> fCurrentDrawable;
  37. };
  38. } // namespace sk_app
  39. #endif