Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / common / winrt / CoreWindowNativeWindow.h
1 //
2 // Copyright (c) 2002-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 COMMON_COREWINDOWNATIVEWINDOW_H_
10 #define COMMON_COREWINDOWNATIVEWINDOW_H_
11
12 #include "common/winrt/IInspectableNativeWindow.h"
13 #include <memory>
14
15 typedef ABI::Windows::Foundation::__FITypedEventHandler_2_Windows__CUI__CCore__CCoreWindow_Windows__CUI__CCore__CWindowSizeChangedEventArgs_t IWindowSizeChangedEventHandler;
16 long ConvertDipsToPixels(float dips);
17
18 class CoreWindowNativeWindow : public IInspectableNativeWindow, public std::enable_shared_from_this<CoreWindowNativeWindow>
19 {
20   public:
21     ~CoreWindowNativeWindow();
22     bool initialize(EGLNativeWindowType window, IPropertySet *propertySet);
23     bool registerForSizeChangeEvents();
24     void unregisterForSizeChangeEvents();
25     HRESULT createSwapChain(ID3D11Device *device, DXGIFactory *factory, DXGI_FORMAT format, unsigned int width, unsigned int height, DXGISwapChain **swapChain);
26   private:
27     ComPtr<ABI::Windows::UI::Core::ICoreWindow> mCoreWindow;
28     ComPtr<IMap<HSTRING, IInspectable*>> mPropertyMap;
29 };
30
31 [uuid(7F924F66-EBAE-40E5-A10B-B8F35E245190)]
32 class CoreWindowSizeChangedHandler :
33     public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, IWindowSizeChangedEventHandler>
34 {
35   public:
36     CoreWindowSizeChangedHandler() { }
37     HRESULT RuntimeClassInitialize(std::shared_ptr<IInspectableNativeWindow> host)
38     {
39         if (!host)
40         {
41             return E_INVALIDARG;
42         }
43
44         mHost = host;
45         return S_OK;
46     }
47
48     // IWindowSizeChangedEventHandler
49     IFACEMETHOD(Invoke)(ABI::Windows::UI::Core::ICoreWindow *sender, ABI::Windows::UI::Core::IWindowSizeChangedEventArgs *e)
50     {
51         std::shared_ptr<IInspectableNativeWindow> host = mHost.lock();
52         if (host)
53         {
54             ABI::Windows::Foundation::Size windowSize;
55             if (SUCCEEDED(e->get_Size(&windowSize)))
56             {
57                 SIZE windowSizeInPixels = { ConvertDipsToPixels(windowSize.Width), ConvertDipsToPixels(windowSize.Height) };
58                 host->setNewClientSize(windowSizeInPixels);
59             }
60         }
61
62         return S_OK;
63     }
64
65   private:
66     std::weak_ptr<IInspectableNativeWindow> mHost;
67 };
68
69 HRESULT getCoreWindowSizeInPixels(const ComPtr<ABI::Windows::UI::Core::ICoreWindow>& coreWindow, RECT *windowSize);
70
71 #endif // COMMON_COREWINDOWNATIVEWINDOW_H_