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_SWAPCHAIN_H_ 16 #define DAWNNATIVE_SWAPCHAIN_H_ 17 18 #include "dawn_native/Error.h" 19 #include "dawn_native/Forward.h" 20 #include "dawn_native/ObjectBase.h" 21 22 #include "dawn/dawn_wsi.h" 23 #include "dawn_native/dawn_platform.h" 24 25 namespace dawn_native { 26 27 MaybeError ValidateSwapChainDescriptor(const DeviceBase* device, 28 const SwapChainDescriptor* descriptor); 29 30 class SwapChainBase : public ObjectBase { 31 public: 32 SwapChainBase(DeviceBase* device, const SwapChainDescriptor* descriptor); 33 ~SwapChainBase(); 34 35 static SwapChainBase* MakeError(DeviceBase* device); 36 37 // Dawn API 38 void Configure(dawn::TextureFormat format, 39 dawn::TextureUsageBit allowedUsage, 40 uint32_t width, 41 uint32_t height); 42 TextureBase* GetNextTexture(); 43 void Present(TextureBase* texture); 44 45 protected: 46 SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag); 47 48 const DawnSwapChainImplementation& GetImplementation(); 49 virtual TextureBase* GetNextTextureImpl(const TextureDescriptor*) = 0; 50 virtual void OnBeforePresent(TextureBase* texture) = 0; 51 52 private: 53 MaybeError ValidateConfigure(dawn::TextureFormat format, 54 dawn::TextureUsageBit allowedUsage, 55 uint32_t width, 56 uint32_t height) const; 57 MaybeError ValidateGetNextTexture() const; 58 MaybeError ValidatePresent(TextureBase* texture) const; 59 60 DawnSwapChainImplementation mImplementation = {}; 61 dawn::TextureFormat mFormat = {}; 62 dawn::TextureUsageBit mAllowedUsage; 63 uint32_t mWidth = 0; 64 uint32_t mHeight = 0; 65 TextureBase* mLastNextTexture = nullptr; 66 }; 67 68 } // namespace dawn_native 69 70 #endif // DAWNNATIVE_SWAPCHAIN_H_ 71