Coherent UI for Unreal Engine 4  2.5.5.0
A modern user interface library for games
 All Classes Functions Variables Pages
CoherentUIViewListener.h
1 /*
2 This file is part of Coherent UI, modern user interface library for
3 games.
4 
5 Copyright (c) 2012-2014 Coherent Labs AD and/or its licensors. All
6 rights reserved in all media.
7 
8 The coded instructions, statements, computer programs, and/or related
9 material (collectively the "Data") in these files contain confidential
10 and unpublished information proprietary Coherent Labs and/or its
11 licensors, which is protected by United States of America federal
12 copyright law and by international treaties.
13 
14 This software or source code is supplied under the terms of a license
15 agreement and nondisclosure agreement with Coherent Labs Limited and may
16 not be copied, disclosed, or exploited except in accordance with the
17 terms of that agreement. The Data may not be disclosed or distributed to
18 third parties, in whole or in part, without the prior written consent of
19 Coherent Labs Limited.
20 
21 COHERENT LABS MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS
22 SOURCE CODE FOR ANY PURPOSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER, ITS AFFILIATES,
27 PARENT COMPANIES, LICENSORS, SUPPLIERS, OR CONTRIBUTORS BE LIABLE FOR
28 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 ANY WAY OUT OF THE USE OR PERFORMANCE OF THIS SOFTWARE OR SOURCE CODE,
34 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36 #pragma once
37 
38 #include "Coherent/UI/ViewListener.h"
39 
40 namespace Coherent
41 {
42 namespace UI
43 {
44 
45 FORCEINLINE uint32 GetTypeHash(const Coherent::UI::CoherentHandle& handle)
46 {
47  return FCrc::MemCrc32(&handle.HandleValue, sizeof(handle.HandleValue));
48 }
49 
50 }
51 }
52 
53 class CoUISystemWrapper;
54 typedef TSharedPtr<CoUISystemWrapper, ESPMode::ThreadSafe> SystemWrapperSharedPtr;
55 
56 class COHERENTUIPLUGIN_API FCoherentUIViewListener
57  : public Coherent::UI::ViewListener
58 {
59 public:
60  FCoherentUIViewListener();
61  virtual ~FCoherentUIViewListener();
62 
63  Coherent::UI::View* GetView() const;
64  bool IsReadyToCreateView() const;
65 
66  void CreateSystemIfNecessary(UWorld* world);
67  class ACoherentUISystem* GetSystemActor(UWorld* world) const;
68 
69 protected:
70  void DoResize(uint32 width, uint32 height);
71 
72  virtual void OnViewCreated(Coherent::UI::View* view) override;
73  virtual void Release() override;
74  virtual void OnDraw(Coherent::UI::CoherentHandle handle,
75  bool usesSharedMemory,
76  int width,
77  int height) override;
78 
79  virtual void CreateSurface(bool sharedMemory,
80  unsigned width,
81  unsigned height,
82  Coherent::UI::SurfaceResponse* response) override;
83  virtual void DestroySurface(Coherent::UI::CoherentHandle surface,
84  bool usesSharedMemory) override;
85 
86  virtual void OnError(const Coherent::UI::ViewError& error) override;
87 
88  virtual void TickListener();
89 
90  class COHERENTUIPLUGIN_API MappedMemory
91  {
92  public:
93  explicit MappedMemory(Coherent::UI::CoherentHandle handle, size_t size);
94  MappedMemory(const MappedMemory& other);
95  ~MappedMemory();
96  MappedMemory& operator=(const MappedMemory& other);
97 
98  void* GetMemory() const;
99 
100  private:
101  void Release();
102  FThreadSafeCounter* RefCount;
103  void* Memory;
104  size_t Size;
105  };
106 
107 protected:
108  void Destroy();
109 
110  SystemWrapperSharedPtr System;
111  UTexture2D* Texture;
112 
113 private:
114  MappedMemory MapMemory(Coherent::UI::CoherentHandle handle);
115 
116  void DestroyCurrentTexture();
117  void RecreateTexture(uint32 width, uint32 height);
118 
119  Coherent::UI::View* View;
120 
121  TMap<Coherent::UI::CoherentHandle, MappedMemory> MemoryHandles;
122 
123  TMap<Coherent::UI::CoherentHandle, FTexture2DRHIRef> SharedTextureHandles;
124  struct FCreateSurfaceTask
125  {
126  FCreateSurfaceTask();
127 
128  unsigned Width;
129  unsigned Height;
130  Coherent::UI::SurfaceResponse* Response;
131  FTexture2DRHIRef Texture;
132  Coherent::UI::CoherentHandle Handle;
133  };
134  FCriticalSection CreateSurfaceCS;
135  typedef TArray<TSharedPtr<FCreateSurfaceTask>> CreateSurfaceTaskArray;
136  CreateSurfaceTaskArray CreateSurfaceTasksComplete;
137 
138  void DoCreateSurfaceOnRenderThread(const TSharedPtr<FCreateSurfaceTask>& task);
139 };
Definition: CoherentUISystem.h:62