1add_subdirectory(backend)
2add_subdirectory(features)
3add_subdirectory(tracing)
4
5# Codec common sources
6add_subdirectory(apigen-codec-common)
7add_subdirectory(compressedTextureFormats)
8
9# GL
10add_subdirectory(gl)
11
12# Vulkan
13add_subdirectory(vulkan)
14
15# RenderControl decoder
16add_subdirectory(renderControl_dec)
17
18# Magma decoder
19add_subdirectory(magma)
20
21if(CONFIG_AEMU)
22    add_compile_definitions(GFXSTREAM_BUILD_WITH_SNAPSHOT_SUPPORT)
23    add_compile_definitions(CONFIG_AEMU)
24endif()
25
26# Stream server core
27set(stream-server-core-sources
28    Buffer.cpp
29    ExternalObjectManager.cpp
30    ColorBuffer.cpp
31    GfxStreamAgents.cpp
32    VirtioGpuContext.cpp
33    VirtioGpuFrontend.cpp
34    VirtioGpuResource.cpp
35    VirtioGpuRingBlob.cpp
36    VirtioGpuTimelines.cpp
37    VsyncThread.cpp
38    ChannelStream.cpp
39    DisplaySurface.cpp
40    DisplaySurfaceUser.cpp
41    Hwc2.cpp
42    PostWorker.cpp
43    PostWorkerGl.cpp
44    ReadBuffer.cpp
45    RenderChannelImpl.cpp
46    RenderThreadInfo.cpp
47    RenderThreadInfoGl.cpp
48    RenderThreadInfoMagma.cpp
49    RingStream.cpp
50    SyncThread.cpp
51    RenderThread.cpp
52    RenderControl.cpp
53    RenderWindow.cpp
54    RenderLibImpl.cpp
55    RendererImpl.cpp
56    FrameBuffer.cpp)
57if (APPLE)
58    set(stream-server-core-platform-sources NativeSubWindow_cocoa.mm)
59elseif (WIN32)
60    set(stream-server-core-platform-sources NativeSubWindow_win32.cpp)
61elseif (QNX)
62    set(stream-server-core-platform-sources NativeSubWindow_qnx.cpp)
63else()
64    set(stream-server-core-platform-sources NativeSubWindow_x11.cpp)
65endif()
66
67add_library(
68        gfxstream_backend_headers
69        INTERFACE)
70target_include_directories(
71        gfxstream_backend_headers
72        INTERFACE
73        include)
74
75# Compile everything as a static library first so that unit tests can call non-exported functions
76add_library(
77        gfxstream_backend_static
78        STATIC
79        ${stream-server-core-sources}
80        ${stream-server-core-platform-sources}
81)
82target_link_libraries(
83        gfxstream_backend_static
84        PUBLIC
85        GLES_CM_translator_static
86        OpenGLESDispatch
87        renderControl_dec
88        gfxstream_backend_common
89        gfxstream_features
90        gfxstream_host_tracing
91        gfxstream-gl-server
92        gfxstream-magma-server
93        gfxstream-vulkan-server
94        gfxstream_egl_headers
95        gfxstream-snapshot
96        apigen-codec-common
97        ${GFXSTREAM_HOST_COMMON_LIB}
98        ${GFXSTREAM_BASE_LIB})
99
100target_include_directories(
101        gfxstream_backend_static
102        PUBLIC
103        ${GFXSTREAM_REPO_ROOT}
104        ${GFXSTREAM_REPO_ROOT}/include
105        ${GFXSTREAM_REPO_ROOT}/host
106        ${GFXSTREAM_REPO_ROOT}/host/include
107        ${GFXSTREAM_REPO_ROOT}/host/apigen-codec-common
108        ${GFXSTREAM_REPO_ROOT}/host/gl
109        ${GFXSTREAM_REPO_ROOT}/host/gl/glestranslator/include
110        ${GFXSTREAM_REPO_ROOT}/host/magma
111        ${GFXSTREAM_REPO_ROOT}/host/magma/magma_dec
112        ${GFXSTREAM_REPO_ROOT}/host/vulkan
113        ${GFXSTREAM_REPO_ROOT}/host/vulkan/cereal/common
114        ${GFXSTREAM_REPO_ROOT}/third-party/fuchsia/magma/include
115        ${GFXSTREAM_REPO_ROOT}/third-party/glm/include)
116
117if (APPLE)
118    target_link_libraries(gfxstream_backend_static PUBLIC "-framework AppKit -framework QuartzCore -framework IOSurface")
119endif()
120if (WIN32)
121    target_link_libraries(gfxstream_backend_static PRIVATE D3d9.lib)
122endif()
123
124# Suppress some warnings generated by platform/aemu repo
125target_compile_options(
126    gfxstream_backend_static
127    PRIVATE
128    -Wno-invalid-offsetof
129    -Wno-free-nonheap-object
130    -Wno-attributes
131    -DGFXSTREAM_ENABLE_HOST_GLES=1
132    )
133
134# gfxstream_backend.dll
135add_library(
136    gfxstream_backend
137    SHARED
138    render_api.cpp
139    virtio-gpu-gfxstream-renderer.cpp)
140
141target_link_libraries(
142    gfxstream_backend
143    PUBLIC
144    gfxstream_common_utils
145    gfxstream_backend_common
146    gfxstream_features
147    gfxstream_host_tracing
148    gfxstream_backend_static
149    PRIVATE
150    )
151
152if(BUILD_STANDALONE)
153    target_link_libraries(gfxstream_backend
154        PRIVATE
155        gfxstream-gl-host-common)
156endif()
157
158if (APPLE)
159    set_target_properties(gfxstream_backend
160        PROPERTIES
161        LINK_FLAGS  "-undefined dynamic_lookup -flat_namespace")
162endif()
163
164if(CONFIG_AEMU)
165    android_install_shared(gfxstream_backend)
166else()
167    install(
168      TARGETS gfxstream_backend RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX} LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX})
169endif()
170
171# Testing libraries
172add_subdirectory(testlibs)
173
174if (ENABLE_VKCEREAL_TESTS)
175
176set(LIST_OF_TESTS)
177function(discover_tests test_name)
178if (WIN32)
179    gtest_discover_tests(
180        ${test_name}
181        ${ARGN})
182    list(APPEND LIST_OF_TESTS ${test_name})
183    set(LIST_OF_TESTS ${LIST_OF_TESTS} PARENT_SCOPE)
184else()
185    gtest_discover_tests(
186        ${test_name}
187        ${ARGN}
188    )
189endif()
190endfunction()
191    # Backend unit tests
192    add_executable(
193        gfxstream_backend_unittests
194        gfxstream_unittest.cpp)
195    target_link_libraries(
196        gfxstream_backend_unittests
197        PRIVATE
198        OSWindow
199        gfxstream_backend
200        aemu-host-common-testing-support
201        ${GFXSTREAM_BASE_LIB}
202        gtest_main)
203        discover_tests(gfxstream_backend_unittests)
204
205    # More functional tests#########################################################
206
207    # Common testing support library################################################
208    # This includes the server core and testing sources
209    add_library(
210        stream-server-testing-support
211        tests/SampleApplication.cpp
212        tests/GLSnapshotTesting.cpp
213        tests/OpenGLTestContext.cpp
214        tests/GLTestUtils.cpp
215        tests/ShaderUtils.cpp
216        tests/GLSnapshotTestDispatch.cpp
217        tests/GLSnapshotTestStateUtils.cpp
218        tests/HelloTriangleImp.cpp)
219    target_include_directories(
220        stream-server-testing-support
221        PUBLIC
222        ${GFXSTREAM_REPO_ROOT}
223        ${GFXSTREAM_REPO_ROOT}/include
224        ${GFXSTREAM_REPO_ROOT}/host
225        ${GFXSTREAM_REPO_ROOT}/host/gl/glestranslator/GLES_CM
226        ${GFXSTREAM_REPO_ROOT}/host/gl/glestranslator/include
227        ${GFXSTREAM_REPO_ROOT}/host/apigen-codec-common
228        ${GFXSTREAM_REPO_ROOT}/host/vulkan)
229    target_link_libraries(
230        stream-server-testing-support
231        PUBLIC
232        aemu-host-common-testing-support
233        aemu-base-testing-support
234        gfxstream_common_image
235        gfxstream_backend_static
236        gfxstream_stb
237        OSWindow
238        gtest)
239
240    if (LINUX)
241    add_library(
242        x11_testing_support
243        tests/X11TestingSupport.cpp)
244    target_link_libraries(
245        x11_testing_support
246        aemu-base.headers)
247    endif()
248
249    # Basic opengl rendering tests##################################################
250    add_executable(
251        OpenglRender_unittests
252        tests/FrameBuffer_unittest.cpp
253        tests/GLES1Dispatch_unittest.cpp
254        tests/DefaultFramebufferBlit_unittest.cpp
255        tests/TextureDraw_unittest.cpp
256        tests/StalePtrRegistry_unittest.cpp
257        tests/VsyncThread_unittest.cpp)
258    target_link_libraries(
259        OpenglRender_unittests
260        PRIVATE
261        stream-server-testing-support
262        aemu-host-common-testing-support
263        aemu-base-testing-support
264        gfxstream_backend_static
265        gtest_main)
266    if (LINUX)
267        target_compile_definitions(
268            OpenglRender_unittests
269            PRIVATE GFXSTREAM_HAS_X11=1)
270        target_link_libraries(
271            OpenglRender_unittests
272            PRIVATE x11_testing_support)
273    endif()
274    discover_tests(OpenglRender_unittests)
275
276    # Snapshot tests################################################################
277    add_executable(
278        OpenglRender_snapshot_unittests
279        tests/GLSnapshotBuffers_unittest.cpp
280        tests/GLSnapshotFramebufferControl_unittest.cpp
281        tests/GLSnapshotFramebuffers_unittest.cpp
282        tests/GLSnapshotMultisampling_unittest.cpp
283        tests/GLSnapshotPixelOperations_unittest.cpp
284        tests/GLSnapshotPixels_unittest.cpp
285        tests/GLSnapshotPrograms_unittest.cpp
286        tests/GLSnapshotRasterization_unittest.cpp
287        tests/GLSnapshotRenderbuffers_unittest.cpp
288        tests/GLSnapshotRendering_unittest.cpp
289        tests/GLSnapshotShaders_unittest.cpp
290        tests/GLSnapshotTextures_unittest.cpp
291        tests/GLSnapshotTransformation_unittest.cpp
292        tests/GLSnapshotVertexAttributes_unittest.cpp
293        tests/GLSnapshot_unittest.cpp)
294    target_link_libraries(
295        OpenglRender_snapshot_unittests
296        PRIVATE
297        stream-server-testing-support
298        aemu-host-common-testing-support
299        aemu-base-testing-support
300        gfxstream_backend_static
301        gtest_main)
302    discover_tests(OpenglRender_snapshot_unittests)
303
304    # Vulkan tests##################################################################
305    add_executable(
306        Vulkan_unittests
307        tests/Vulkan_unittest.cpp
308        tests/CompositorVk_unittest.cpp
309        tests/SwapChainStateVk_unittest.cpp
310        tests/DisplayVk_unittest.cpp
311        tests/VirtioGpuTimelines_unittest.cpp
312        vulkan/vk_util_unittest.cpp
313        vulkan/VkFormatUtils_unittest.cpp
314        vulkan/VkQsriTimeline_unittest.cpp
315        vulkan/VkDecoderGlobalState_unittest.cpp
316    )
317    target_link_libraries(
318        Vulkan_unittests
319        PRIVATE
320        stream-server-testing-support
321        aemu-host-common-testing-support
322        aemu-base-testing-support
323        gfxstream_backend_static
324        gtest
325        gtest_main
326        gmock)
327    if (APPLE)
328        target_compile_definitions(Vulkan_unittests PRIVATE -DVK_USE_PLATFORM_METAL_EXT)
329        target_link_libraries(Vulkan_unittests PUBLIC "-framework AppKit")
330    endif()
331    discover_tests(
332            Vulkan_unittests
333            WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
334
335    if (APPLE)
336        target_compile_definitions(Vulkan_unittests PRIVATE -DVK_USE_PLATFORM_METAL_EXT)
337    elseif (QNX)
338        target_compile_definitions(Vulkan_unittests PRIVATE -DVK_USE_PLATFORM_SCREEN_QNX)
339    elseif (UNIX)
340        target_compile_definitions(Vulkan_unittests PRIVATE -DVK_USE_PLATFORM_XCB_KHR)
341    endif()
342
343
344    file(GLOB Vulkan_unittests_datafiles "tests/testdata/*.png")
345    add_custom_command(TARGET Vulkan_unittests POST_BUILD
346                       COMMAND ${CMAKE_COMMAND} -E make_directory
347                            ${CMAKE_BINARY_DIR}/tests/testdata
348                       COMMAND ${CMAKE_COMMAND} -E copy_if_different
349                            ${Vulkan_unittests_datafiles}
350                            ${CMAKE_BINARY_DIR}/tests/testdata)
351
352    add_executable(
353            Vulkan_integrationtests
354            vulkan/testing/VkDecoderTestDispatch.h
355            vulkan/testing/VulkanTestHelper.cpp
356    )
357    target_link_libraries(
358            Vulkan_integrationtests
359            PRIVATE
360            gfxstream_backend_static
361            gfxstream-gl-server
362            gfxstream-vulkan-server
363            stream-server-testing-support
364            gtest
365            gtest_main
366            gmock)
367    discover_tests(Vulkan_integrationtests)
368endif()
369if (WIN32)
370    set(BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}")
371    configure_file(../cmake/SetWin32TestEnvironment.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/SetWin32TestEnvironment.cmake @ONLY)
372    set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES ${CMAKE_CURRENT_BINARY_DIR}/SetWin32TestEnvironment.cmake)
373endif()
374