1 // Copyright 2017 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef DAWNNATIVE_METAL_SWAPCHAINMTL_H_ 16 #define DAWNNATIVE_METAL_SWAPCHAINMTL_H_ 17 18 #include "dawn_native/SwapChain.h" 19 20 #include "common/NSRef.h" 21 22 @class CAMetalLayer; 23 @protocol CAMetalDrawable; 24 25 namespace dawn_native { namespace metal { 26 27 class Device; 28 class Texture; 29 30 class OldSwapChain final : public OldSwapChainBase { 31 public: 32 static Ref<OldSwapChain> Create(Device* deivce, const SwapChainDescriptor* descriptor); 33 34 protected: 35 OldSwapChain(Device* device, const SwapChainDescriptor* descriptor); 36 ~OldSwapChain() override; 37 TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; 38 MaybeError OnBeforePresent(TextureViewBase* view) override; 39 }; 40 41 class SwapChain final : public NewSwapChainBase { 42 public: 43 static ResultOrError<Ref<SwapChain>> Create(Device* device, 44 Surface* surface, 45 NewSwapChainBase* previousSwapChain, 46 const SwapChainDescriptor* descriptor); 47 ~SwapChain() override; 48 49 private: 50 void DestroyImpl() override; 51 52 using NewSwapChainBase::NewSwapChainBase; 53 MaybeError Initialize(NewSwapChainBase* previousSwapChain); 54 55 NSRef<CAMetalLayer> mLayer; 56 57 NSPRef<id<CAMetalDrawable>> mCurrentDrawable; 58 Ref<Texture> mTexture; 59 60 MaybeError PresentImpl() override; 61 ResultOrError<TextureViewBase*> GetCurrentTextureViewImpl() override; 62 void DetachFromSurfaceImpl() override; 63 }; 64 65 }} // namespace dawn_native::metal 66 67 #endif // DAWNNATIVE_METAL_SWAPCHAINMTL_H_ 68