• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd.
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 
16 #include "tcuOhosPlatform.hpp"
17 
18 #include "deUniquePtr.hpp"
19 #include "ohos_context_i.h"
20 
21 #include "egluGLContextFactory.hpp"
22 #include "display/tcuOhosEglDisplayFactory.hpp"
23 #include "context/tcuOhosEglContextFactory.hpp"
24 
25 using de::MovePtr;
26 using de::UniquePtr;
27 
28 using namespace tcu;
29 using namespace OHOS_ROSEN;
30 
OhosPlatform(void)31 OhosPlatform::OhosPlatform (void)
32 {
33     printf("OhosPlatform construct!\n");
34     m_nativeDisplayFactoryRegistry.registerFactory(new OHOS_ROSEN::egl::OhosDisplayFactory());
35     m_contextFactoryRegistry.registerFactory(new OHOS_ROSEN::egl::OhosContextFactory());
36 }
37 
createOhosPlatform(void)38 tcu::Platform* createOhosPlatform (void)
39 {
40     return new tcu::OHOS_ROSEN::OhosPlatform();
41 }
42 
43 #include "tcuFunctionLibrary.hpp"
44 class VulkanLibrary : public vk::Library
45 {
46 public:
VulkanLibrary(void)47 	VulkanLibrary (void)
48 		: m_library	("libvulkan.so")
49 		, m_driver	(m_library)
50 	{
51 	}
52 
getPlatformInterface(void) const53 	const vk::PlatformInterface& getPlatformInterface		(void) const
54 	{
55 		return m_driver;
56 	}
57 
getFunctionLibrary(void) const58 	const tcu::FunctionLibrary&		getFunctionLibrary		(void) const
59 	{
60 		return m_library;
61 	}
62 
63 private:
64 	const tcu::DynamicFunctionLibrary	m_library;
65 	const vk::PlatformDriver			m_driver;
66 };
67 
68 class VulkanWindowOhos : public vk::wsi::OhosWindowInterface
69 {
70 public:
VulkanWindowOhos(uint64_t windowId)71 	VulkanWindowOhos (uint64_t windowId)
72         : vk::wsi::OhosWindowInterface	(vk::pt::OhosNativeWindowPtr(OHOS::OhosContextI::GetInstance().GetNativeWindow(windowId)))
73 		, windowId_(windowId)
74 	{
75 	}
76 
setVisible(bool visible)77 	void setVisible(bool visible)
78 	{
79 		DE_UNREF(visible);
80 	}
81 
resize(const UVec2 & newSize)82 	void resize(const UVec2& newSize)
83 	{
84 		DE_UNREF(newSize);
85 	}
86 
~VulkanWindowOhos(void)87 	~VulkanWindowOhos (void)
88 	{
89 		OHOS::OhosContextI::GetInstance().DestoryWindow(windowId_);
90 	}
91 
92 private:
93 	uint64_t windowId_;
94 };
95 class VulkanDisplayOhos : public vk::wsi::Display
96 {
97 public:
VulkanDisplayOhos()98 	VulkanDisplayOhos ()
99 	{
100 	}
101 
createWindow(const Maybe<UVec2> & initialSize) const102 	vk::wsi::Window* createWindow (const Maybe<UVec2>& initialSize) const
103 	{
104 		const deUint32		height		= !initialSize ? (deUint32)300 : initialSize->y();
105 		const deUint32		width		= !initialSize ? (deUint32)400 : initialSize->x();
106 		printf("%d,%d\n",width,height);
107 		uint64_t i = OHOS::OhosContextI::GetInstance().CreateWindow(0,0,width,height);
108 		return new VulkanWindowOhos(i);//cxunmz
109 	}
110 
111 private:
112 };
113 
createWsiDisplay(vk::wsi::Type wsiType) const114 vk::wsi::Display* OhosPlatform::createWsiDisplay(vk::wsi::Type wsiType) const
115 {
116     if(wsiType == vk::wsi::TYPE_OHOS){
117         printf("ok\n");
118     }
119     return NULL;
120 }
121 
createLibrary(void) const122 vk::Library* OhosPlatform::createLibrary(void) const
123 {
124     return new VulkanLibrary();
125 }
126 
hasDisplay(vk::wsi::Type wsiType) const127 bool OhosPlatform::hasDisplay(vk::wsi::Type wsiType) const
128 {
129     if (wsiType == vk::wsi::TYPE_OHOS)
130 		return true;
131 
132 	return false;
133 }
134 
135 #include <sys/utsname.h>
136 #include "deMemory.h"
describePlatform(std::ostream & dst) const137 void OhosPlatform::describePlatform(std::ostream& dst) const
138 {
139 	utsname		sysInfo;
140 	deMemset(&sysInfo, 0, sizeof(sysInfo));
141 
142 	if (uname(&sysInfo) != 0)
143 		throw std::runtime_error("uname() failed");
144 
145 	dst << "OS: " << sysInfo.sysname << " " << sysInfo.release << " " << sysInfo.version << "\n";
146 	dst << "CPU: " << sysInfo.machine << "\n";
147 }
148 
getMemoryLimits(vk::PlatformMemoryLimits & limits) const149 void OhosPlatform::getMemoryLimits(vk::PlatformMemoryLimits& limits) const
150 {
151 	limits.totalSystemMemory					= 256*1024*1024;
152 	limits.totalDeviceLocalMemory				= 0;//128*1024*1024;
153 	limits.deviceMemoryAllocationGranularity	= 64*1024;
154 	limits.devicePageSize						= 4096;
155 	limits.devicePageTableEntrySize				= 8;
156 	limits.devicePageTableHierarchyLevels		= 3;
157 }