Path: blob/main_old/src/common/fuchsia_egl/fuchsia_egl.c
1693 views
// Copyright 2019 The Fuchsia Authors. All rights reserved.1// Use of this source code is governed by a BSD-style license that can be2// found in the LICENSE file.34#include "fuchsia_egl.h"5#include "fuchsia_egl_backend.h"67#include <zircon/assert.h>8#include <zircon/syscalls.h>910#include <stdlib.h>1112#define FUCHSIA_EGL_WINDOW_MAGIC 0x80738870 // "FXIP"1314struct fuchsia_egl_window15{16uint32_t magic;17zx_handle_t image_pipe_handle;18int32_t width;19int32_t height;20};2122fuchsia_egl_window *fuchsia_egl_window_create(zx_handle_t image_pipe_handle,23int32_t width,24int32_t height)25{26if (width <= 0 || height <= 0)27return NULL;2829fuchsia_egl_window *egl_window = malloc(sizeof(*egl_window));30egl_window->magic = FUCHSIA_EGL_WINDOW_MAGIC;31egl_window->image_pipe_handle = image_pipe_handle;32egl_window->width = width;33egl_window->height = height;34return egl_window;35}3637void fuchsia_egl_window_destroy(fuchsia_egl_window *egl_window)38{39ZX_ASSERT(egl_window->magic == FUCHSIA_EGL_WINDOW_MAGIC);40if (egl_window->image_pipe_handle != ZX_HANDLE_INVALID)41{42zx_handle_close(egl_window->image_pipe_handle);43egl_window->image_pipe_handle = ZX_HANDLE_INVALID;44}45egl_window->magic = -1U;46free(egl_window);47}4849void fuchsia_egl_window_resize(fuchsia_egl_window *egl_window, int32_t width, int32_t height)50{51ZX_ASSERT(egl_window->magic == FUCHSIA_EGL_WINDOW_MAGIC);52if (width <= 0 || height <= 0)53return;54egl_window->width = width;55egl_window->height = height;56}5758int32_t fuchsia_egl_window_get_width(fuchsia_egl_window *egl_window)59{60ZX_ASSERT(egl_window->magic == FUCHSIA_EGL_WINDOW_MAGIC);61return egl_window->width;62}6364int32_t fuchsia_egl_window_get_height(fuchsia_egl_window *egl_window)65{66ZX_ASSERT(egl_window->magic == FUCHSIA_EGL_WINDOW_MAGIC);67return egl_window->height;68}6970zx_handle_t fuchsia_egl_window_release_image_pipe(fuchsia_egl_window *egl_window)71{72ZX_ASSERT(egl_window->magic == FUCHSIA_EGL_WINDOW_MAGIC);73zx_handle_t image_pipe_handle = egl_window->image_pipe_handle;74egl_window->image_pipe_handle = ZX_HANDLE_INVALID;75return image_pipe_handle;76}777879