1 // 2 // Copyright 2014 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // CoreWindowNativeWindow.h: NativeWindow for managing ICoreWindow native window types. 8 9 #ifndef LIBANGLE_RENDERER_D3D_D3D11_WINRT_COREWINDOWNATIVEWINDOW_H_ 10 #define LIBANGLE_RENDERER_D3D_D3D11_WINRT_COREWINDOWNATIVEWINDOW_H_ 11 12 #include "libANGLE/renderer/d3d/d3d11/winrt/InspectableNativeWindow.h" 13 14 #include <memory> 15 16 #include <EGL/eglplatform.h> 17 18 typedef ABI::Windows::Foundation:: 19 __FITypedEventHandler_2_Windows__CUI__CCore__CCoreWindow_Windows__CUI__CCore__CWindowSizeChangedEventArgs_t 20 IWindowSizeChangedEventHandler; 21 22 namespace rx 23 { 24 float ConvertDipsToPixels(float dips); 25 26 class CoreWindowNativeWindow : public InspectableNativeWindow, 27 public std::enable_shared_from_this<CoreWindowNativeWindow> 28 { 29 public: 30 ~CoreWindowNativeWindow(); 31 32 bool initialize(EGLNativeWindowType window, IPropertySet *propertySet) override; 33 HRESULT createSwapChain(ID3D11Device *device, 34 IDXGIFactory2 *factory, 35 DXGI_FORMAT format, 36 unsigned int width, 37 unsigned int height, 38 bool containsAlpha, 39 IDXGISwapChain1 **swapChain) override; 40 41 protected: 42 HRESULT scaleSwapChain(const Size &windowSize, const RECT &clientRect) override; 43 44 bool registerForSizeChangeEvents(); 45 void unregisterForSizeChangeEvents(); 46 47 private: 48 ComPtr<ABI::Windows::UI::Core::ICoreWindow> mCoreWindow; 49 ComPtr<IMap<HSTRING, IInspectable *>> mPropertyMap; 50 }; 51 52 __declspec(uuid("7F924F66-EBAE-40E5-A10B-B8F35E245190")) class CoreWindowSizeChangedHandler 53 : public Microsoft::WRL::RuntimeClass< 54 Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, 55 IWindowSizeChangedEventHandler> 56 { 57 public: CoreWindowSizeChangedHandler()58 CoreWindowSizeChangedHandler() {} RuntimeClassInitialize(std::shared_ptr<InspectableNativeWindow> host)59 HRESULT RuntimeClassInitialize(std::shared_ptr<InspectableNativeWindow> host) 60 { 61 if (!host) 62 { 63 return E_INVALIDARG; 64 } 65 66 mHost = host; 67 return S_OK; 68 } 69 70 // IWindowSizeChangedEventHandler IFACEMETHOD(Invoke)71 IFACEMETHOD(Invoke) 72 (ABI::Windows::UI::Core::ICoreWindow *sender, 73 ABI::Windows::UI::Core::IWindowSizeChangedEventArgs *sizeChangedEventArgs) 74 { 75 std::shared_ptr<InspectableNativeWindow> host = mHost.lock(); 76 if (host) 77 { 78 ABI::Windows::Foundation::Size windowSize; 79 if (SUCCEEDED(sizeChangedEventArgs->get_Size(&windowSize))) 80 { 81 Size windowSizeInPixels = {ConvertDipsToPixels(windowSize.Width), 82 ConvertDipsToPixels(windowSize.Height)}; 83 host->setNewClientSize(windowSizeInPixels); 84 } 85 } 86 87 return S_OK; 88 } 89 90 private: 91 std::weak_ptr<InspectableNativeWindow> mHost; 92 }; 93 94 HRESULT GetCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWindow> &coreWindow, 95 Size *windowSize); 96 } // namespace rx 97 98 #endif // LIBANGLE_RENDERER_D3D_D3D11_WINRT_COREWINDOWNATIVEWINDOW_H_ 99