Skip to content
Open
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
87 changes: 67 additions & 20 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ package {

cc_library_static {
name: "libpixman",

sdk_version: "current",
sdk_variant_only: true,

srcs: [
"pixman/pixman/pixman-access-accessors.c",
Expand Down Expand Up @@ -59,28 +56,17 @@ cc_library_shared {
sdk_variant_only: true,

srcs: [
"shmem_ivshm_ivshmem.c",
"virtio.c",
"virtio_over_shmem.c",
"dm_helpers.c",
"dm_stubs.c",
"utils.c",
"main.cpp",
"devicemodel/lib/dm_string.c",
"devicemodel/core/mevent.c",
"devicemodel/core/timer.c",
"devicemodel/hw/block_if.c",
"devicemodel/hw/gc.c",
"devicemodel/hw/vga.c",
"devicemodel/hw/pci/virtio/vhost.c",
"devicemodel/hw/pci/virtio/virtio_gpu.c",
"devicemodel/hw/vdisplay_egl.c",
"client/main.cpp",
"client/renderer.cpp",
"client/vdisplay_client.cpp",
],

local_include_dirs: [
"devicemodel/include/public",
"misc/library/include",
"devicemodel/include",
"pixman/pixman/",
"client",
],

stl: "libc++_static",
Expand Down Expand Up @@ -112,7 +98,6 @@ cc_library_shared {

static_libs: [
"android_native_app_glue",
"libpixman",
"libbase_ndk",
],
ldflags: [
Expand All @@ -122,3 +107,65 @@ cc_library_shared {
export_static_lib_headers: [
],
}

cc_binary {
name: "acrn-virtio-gpu",

srcs: ["acrn-virtio-gpu.c",
"shmem_ivshm_ivshmem.c",
"virtio.c",
"virtio_over_shmem.c",
"dm_helpers.c",
"dm_stubs.c",
"utils.c",
"devicemodel/lib/dm_string.c",
"devicemodel/core/mevent.c",
"devicemodel/core/timer.c",
"devicemodel/hw/block_if.c",
"devicemodel/hw/gc.c",
"devicemodel/hw/vga.c",
"devicemodel/hw/pci/virtio/vhost.c",
"devicemodel/hw/pci/virtio/virtio_gpu.c",
"devicemodel/hw/vdisplay_server.c",
],

local_include_dirs: [
"devicemodel/include/public",
"misc/library/include",
"devicemodel/include",
],

stl: "libc++_static",
cflags: [
"-pthread",
"-Wall",
"-D__USE_BSD",
],
cppflags: ["-std=c++14"],

shared_libs: [
"libEGL",
"libGLESv3",
"liblog",
"libz",
"libsync",
"libc",
"libandroid",
],

header_libs: [
"jni_headers",
],

export_header_lib_headers: [
],

static_libs: [
"libpixman",
],

export_static_lib_headers: [
],

relative_install_path: "hw"
}
19 changes: 19 additions & 0 deletions acrn-virtio-gpu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <pci_core.h>
#include <vdisplay.h>

#include "utils.h"

extern struct pci_vdev_ops pci_ops_virtio_gpu;

static void init_vdpy(struct virtio_backend_info *info __attribute__((unused))) {
// vdpy_parse_cmd_option(info->opts);
}

static struct virtio_backend_info virtio_gpu_info = {
.pci_vdev_ops = &pci_ops_virtio_gpu,

.hook_before_init = init_vdpy,
};

ACRN_BACKEND_MAIN(virtio_gpu_info)

6 changes: 6 additions & 0 deletions client/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <android/log.h>


#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "main", __VA_ARGS__))
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "main", __VA_ARGS__))
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, "main", __VA_ARGS__))
38 changes: 27 additions & 11 deletions main.cpp → client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,10 @@
// #include "agq.h"
// #include "circle.h"
// #include "common.h"
// #include "renderer.h"
#include "renderer.h"
#include "vdisplay_client.h"
// #include "vecmath.h"

extern "C" {
#include <virtio_over_shmem.h>
#include <utils.h>
#include <vdisplay.h>
}

#include <cassert>
#include <chrono>
#include <cinttypes>
Expand All @@ -42,12 +37,13 @@ extern "C" {
#include <EGL/eglext.h>

#include <android/sensor.h>
#include <android/log.h>
#include <android_native_app_glue.h>

#include "common.h"

#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "main", __VA_ARGS__))
#define USE_GAME_RENDER

#ifndef USE_GAME_RENDER
static void init_vdpy(struct virtio_backend_info *info) {
vdpy_gfx_ui_init(info->native_window);
}
Expand All @@ -57,6 +53,7 @@ static struct virtio_backend_info virtio_gpu_info = {
.pci_vdev_ops = &pci_ops_virtio_gpu,
.hook_before_init = init_vdpy,
};
#endif

namespace {
int animating = 0;
Expand All @@ -75,7 +72,8 @@ int32_t engine_handle_input(struct android_app*, AInputEvent* event) {
/**
* Process the next main command.
*/
void engine_handle_cmd(struct android_app* app, int32_t cmd) {
void engine_handle_cmd(struct android_app* app, int32_t cmd) {
Renderer *renderer = (Renderer *)(app->userData);
switch (cmd) {
case APP_CMD_SAVE_STATE:
// We are not saving the state.
Expand All @@ -86,16 +84,25 @@ void engine_handle_cmd(struct android_app* app, int32_t cmd) {
LOGI("APP_CMD_INIT_WINDOW");
if (app->window != NULL) {
LOGI("APP_CMD_INIT_WINDOW -1");
#ifdef USE_GAME_RENDER
renderer->init(app->window);
renderer->draw();
#else
virtio_gpu_info.native_window = app->window;
create_backend_thread(&virtio_gpu_info);
#endif

animating = 1;
}
LOGI("APP_CMD_INIT_WINDOW -2");
break;
case APP_CMD_TERM_WINDOW:
// The window is being hidden or closed, clean it up.
#ifdef USE_GAME_RENDER
renderer->terminate();
#else
close_backend_thread();
#endif
LOGI("APP_CMD_TERM_WINDOW");
animating = 0;
break;
Expand Down Expand Up @@ -125,6 +132,11 @@ void android_main(struct android_app* state) {

LOGI("Running with SDK %d", state->activity->sdkVersion);

std::unique_ptr<Renderer> renderer(new Renderer());
std::unique_ptr<DisplayClient> display_client(new DisplayClient(renderer.get()));
display_client->start();

state->userData = renderer.get();
state->onAppCmd = engine_handle_cmd;
state->onInputEvent = engine_handle_input;

Expand All @@ -147,7 +159,11 @@ void android_main(struct android_app* state) {
LOGI("ALooper_pollAll -2");
// Check if we are exiting.
if (state->destroyRequested != 0) {
#ifdef USE_GAME_RENDER
renderer->terminate();
#else
close_backend_thread();
#endif
LOGI("state->destroyRequested != 0, exit...");
return;
}
Expand All @@ -156,7 +172,7 @@ void android_main(struct android_app* state) {

#ifdef USE_GAME_RENDER
if (animating) {
renderer->update();
// renderer->update();

// Drawing is throttled to the screen update rate, so there
// is no need to do timing here.
Expand Down
Loading