Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions host/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ elif host_machine.system() == 'linux' and use_gles
files_lib_gfxstream_backend += files('native_sub_window_x11.cpp')
elif host_machine.system() == 'qnx'
files_lib_gfxstream_backend += files(
'platform_helper_qnx.cpp',
'native_sub_window_qnx.cpp',
)
endif
Expand Down
26 changes: 5 additions & 21 deletions host/native_sub_window_qnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <pthread.h>
#include <screen/screen.h>

#include "native_sub_window.h"

namespace {

static pthread_once_t once_control = PTHREAD_ONCE_INIT;
static screen_context_t g_screen_ctx;

static void screen_init(void) {
/* initialize the global screen context */
screen_create_context(&g_screen_ctx, SCREEN_APPLICATION_CONTEXT);
}

static screen_context_t get_screen_context() {
pthread_once(&once_control, screen_init);
return g_screen_ctx;
}
#include <errno.h>

} // namespace
#include "native_sub_window.h"
#include "platform_helper_qnx.h"

EGLNativeWindowType createSubWindow(FBNativeWindowType p_window, int x, int y, int width,
int height, float dpr,
Expand All @@ -44,7 +28,7 @@ EGLNativeWindowType createSubWindow(FBNativeWindowType p_window, int x, int y, i
screen_window_t screen_window;
int rc;

screen_ctx = get_screen_context();
screen_ctx = gfxstream::qnx::getScreenContext();
if (screen_ctx == nullptr) {
perror("No screen context");
return nullptr;
Expand Down Expand Up @@ -125,7 +109,7 @@ int moveSubWindow(FBNativeWindowType p_parent_window, EGLNativeWindowType p_sub_
if (screen_set_window_property_iv(p_sub_window, SCREEN_PROPERTY_SIZE, size)) {
return 0;
}
return screen_flush_context(get_screen_context(), 0) == EOK;
return screen_flush_context(gfxstream::qnx::getScreenContext(), 0) == EOK;
}

void* getNativeDisplay() {
Expand Down
110 changes: 110 additions & 0 deletions host/platform_helper_qnx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (C) 2011 The Android Open Source Project
* Copyright (C) 2026 BlackBerry Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "platform_helper_qnx.h"

#include <pthread.h>

#include "gfxstream/common/logging.h"

static pthread_once_t once_control = PTHREAD_ONCE_INIT;
static screen_context_t g_screen_ctx;

static void screen_init(void) {
/* initialize the global screen context */
screen_create_context(&g_screen_ctx, SCREEN_APPLICATION_CONTEXT);
}

static inline int getScreenFormat(GfxstreamFormat format) {
switch (format) {
case GfxstreamFormat::B8G8R8A8_UNORM:
return SCREEN_FORMAT_RGBA8888;
case GfxstreamFormat::R8G8B8A8_UNORM:
return SCREEN_FORMAT_BGRA8888;
case GfxstreamFormat::R8G8B8X8_UNORM:
return SCREEN_FORMAT_BGRX8888;
case GfxstreamFormat::R8_UNORM:
return SCREEN_FORMAT_BYTE;
default:
return -1;
}
}

namespace gfxstream {
namespace qnx {

screen_context_t getScreenContext() {
pthread_once(&once_control, screen_init);
return g_screen_ctx;
}

#define ASSERT_SCREEN_FUNC(func) \
do { \
int rc = (func); \
if (rc != EOK) { \
GFXSTREAM_ERROR("Failed QNX Screen API call: %s", strerror(errno)); \
return std::nullopt; \
} \
} while (0)

std::optional<std::pair<screen_stream_t, screen_buffer_t>> createScreenStreamBuffer(
int width, int height, GfxstreamFormat format, std::string bufferName) {
screen_stream_t screen_stream = NULL;
ASSERT_SCREEN_FUNC(screen_create_stream(&screen_stream, getScreenContext()));
if (!screen_stream) {
GFXSTREAM_ERROR("Could not create screen_stream_t");
return std::nullopt;
}

const int screenUsage = SCREEN_USAGE_NATIVE | SCREEN_USAGE_OPENGL_ES2 |
SCREEN_USAGE_OPENGL_ES3 | SCREEN_USAGE_VULKAN;
ASSERT_SCREEN_FUNC(
screen_set_stream_property_iv(screen_stream, SCREEN_PROPERTY_USAGE, &screenUsage));

int screenFormat = getScreenFormat(format);
if (screenFormat <= 0) {
GFXSTREAM_ERROR("Could not create screen_stream_t");
return std::nullopt;
}
ASSERT_SCREEN_FUNC(
screen_set_stream_property_iv(screen_stream, SCREEN_PROPERTY_FORMAT, &screenFormat));

int size[] = {width, height};
ASSERT_SCREEN_FUNC(
screen_set_stream_property_iv(screen_stream, SCREEN_PROPERTY_BUFFER_SIZE, size));

ASSERT_SCREEN_FUNC(screen_set_stream_property_cv(screen_stream, SCREEN_PROPERTY_ID_STRING,
bufferName.length(), bufferName.c_str()));

int rc = screen_create_stream_buffers(screen_stream, 1);
if (rc) {
GFXSTREAM_ERROR(
"Could not create buffer for screen_stream_t (usage=0x%x, id_str=%s, width=%d, "
"height=%d, format=%d)\n",
screenUsage, bufferName.c_str(), width, height, format);
return std::nullopt;
}

screen_buffer_t stream_buffer;
ASSERT_SCREEN_FUNC(screen_get_stream_property_pv(screen_stream, SCREEN_PROPERTY_BUFFERS,
(void**)&stream_buffer));

return std::make_optional(std::make_pair(screen_stream, stream_buffer));
}

} // namespace qnx
} // namespace gfxstream
47 changes: 47 additions & 0 deletions host/platform_helper_qnx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2011 The Android Open Source Project
* Copyright (C) 2026 BlackBerry Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PLATFORM_HELPER_QNX_H
#define PLATFORM_HELPER_QNX_H

#include <screen/screen.h>

#include <optional>

#include "gfxstream/host/external_object_manager.h"
#include "gfxstream/host/gfxstream_format.h"

#ifdef __cplusplus
extern "C" {
#endif

using namespace gfxstream::host;

namespace gfxstream {
namespace qnx {

screen_context_t getScreenContext();
std::optional<std::pair<screen_stream_t, screen_buffer_t>> createScreenStreamBuffer(
int width, int height, GfxstreamFormat format, std::string bufferName);

} // namespace qnx
} // namespace gfxstream

#ifdef __cplusplus
}
#endif

#endif
Loading
Loading