Commit 375fee94 by Yiwei Zhang

Use vndk/window.h instead of the system one

Bug: b/159763893 Change-Id: I9c662b726ccd77d8974cefb8bacfee8994f8c7b1 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/48829 Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarTrevor Black <vantablack@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarYiwei Zhang <zzyiwei@google.com>
parent 02818d1f
/*
* Copyright (C) 2018 The Android Open Source Project
*
* 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.
*/
#pragma once
#include <nativebase/nativebase.h>
#include <system/graphics.h>
#define ANDROID_NATIVE_WINDOW_MAGIC ANDROID_NATIVE_MAKE_CONSTANT('_', 'w', 'n', 'd')
enum {
NATIVE_WINDOW_WIDTH = 0,
NATIVE_WINDOW_HEIGHT = 1,
};
struct ANativeWindow {
ANativeWindow() : flags(0), minSwapInterval(0), maxSwapInterval(0), xdpi(0), ydpi(0) {
common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
common.version = sizeof(ANativeWindowBuffer);
memset(common.reserved, 0, sizeof(common.reserved));
}
android_native_base_t common;
const uint32_t flags;
const int minSwapInterval;
const int maxSwapInterval;
const float xdpi;
const float ydpi;
intptr_t oem[4];
int (*setSwapInterval)(ANativeWindow*, int);
int (*dequeueBuffer_DEPRECATED)(ANativeWindow*, ANativeWindowBuffer**);
int (*lockBuffer_DEPRECATED)(ANativeWindow*, ANativeWindowBuffer*);
int (*queueBuffer_DEPRECATED)(ANativeWindow*, ANativeWindowBuffer*);
int (*query)(const ANativeWindow*, int, int*);
int (*perform)(ANativeWindow*, int, ...);
int (*cancelBuffer_DEPRECATED)(ANativeWindow*, ANativeWindowBuffer*);
int (*dequeueBuffer)(ANativeWindow*, ANativeWindowBuffer**, int*);
int (*queueBuffer)(ANativeWindow*, ANativeWindowBuffer*, int);
int (*cancelBuffer)(ANativeWindow*, ANativeWindowBuffer*, int);
};
static inline int native_window_set_usage(ANativeWindow*, uint64_t) {
// No-op
return 0;
}
static inline int native_window_dequeue_buffer_and_wait(ANativeWindow* anw,
ANativeWindowBuffer** anwb) {
return anw->dequeueBuffer_DEPRECATED(anw, anwb);
}
/*
* Copyright (C) 2020 The Android Open Source Project
*
* 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.
*/
#pragma once
#include <nativebase/nativebase.h>
struct ANativeWindow;
typedef struct ANativeWindow ANativeWindow;
void ANativeWindow_acquire(ANativeWindow* window);
void ANativeWindow_release(ANativeWindow* window);
int32_t ANativeWindow_getWidth(ANativeWindow* window);
int32_t ANativeWindow_getHeight(ANativeWindow* window);
int ANativeWindow_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd);
int ANativeWindow_queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd);
int ANativeWindow_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd);
int ANativeWindow_setUsage(ANativeWindow* window, uint64_t usage);
......@@ -16,7 +16,9 @@
#ifndef ANDROID_NDK_BUILD
#include "Common/GrallocAndroid.hpp"
#include <system/window.h>
#include <sync/sync.h>
#include <system/graphics.h>
#include <vndk/window.h>
#else
#include <android/native_window.h>
#endif
......@@ -26,29 +28,22 @@ namespace sw
#if !defined(ANDROID_NDK_BUILD)
inline int dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer)
{
#if ANDROID_PLATFORM_SDK_VERSION > 16
return native_window_dequeue_buffer_and_wait(window, buffer);
#else
return window->dequeueBuffer(window, buffer);
#endif
int fenceFd = -1;
int ret = ANativeWindow_dequeueBuffer(window, buffer, &fenceFd);
if (ret || fenceFd < 0) return ret;
sync_wait(fenceFd, -1 /* forever */);
close(fenceFd);
return ret;
}
inline int queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd)
{
#if ANDROID_PLATFORM_SDK_VERSION > 16
return window->queueBuffer(window, buffer, fenceFd);
#else
return window->queueBuffer(window, buffer);
#endif
return ANativeWindow_queueBuffer(window, buffer, fenceFd);
}
inline int cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd)
{
#if ANDROID_PLATFORM_SDK_VERSION > 16
return window->cancelBuffer(window, buffer, fenceFd);
#else
return window->cancelBuffer(window, buffer);
#endif
return ANativeWindow_cancelBuffer(window, buffer, fenceFd);
}
#endif // !defined(ANDROID_NDK_BUILD)
......@@ -57,15 +52,15 @@ namespace sw
nativeWindow(window), buffer(nullptr)
{
#ifndef ANDROID_NDK_BUILD
nativeWindow->common.incRef(&nativeWindow->common);
native_window_set_usage(nativeWindow, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
ANativeWindow_acquire(nativeWindow);
ANativeWindow_setUsage(nativeWindow, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
#endif
}
FrameBufferAndroid::~FrameBufferAndroid()
{
#ifndef ANDROID_NDK_BUILD
nativeWindow->common.decRef(&nativeWindow->common);
ANativeWindow_release(nativeWindow);
#endif
}
......
......@@ -22,7 +22,8 @@
#include <GLES2/gl2ext.h>
#if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
#include <system/window.h>
#include <system/graphics.h>
#include <vndk/window.h>
#include "../../Common/GrallocAndroid.hpp"
#endif
......
......@@ -26,7 +26,7 @@
#include "Common/RecursiveLock.hpp"
#if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
#include <system/window.h>
#include <vndk/window.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <fcntl.h>
......@@ -674,13 +674,6 @@ bool Display::isValidWindow(EGLNativeWindowType window)
ERR("%s called with window==NULL %s:%d", __FUNCTION__, __FILE__, __LINE__);
return false;
}
#if !defined(ANDROID_NDK_BUILD)
if(static_cast<ANativeWindow*>(window)->common.magic != ANDROID_NATIVE_WINDOW_MAGIC)
{
ERR("%s called with window==%p bad magic %s:%d", __FUNCTION__, window, __FILE__, __LINE__);
return false;
}
#endif // !defined(ANDROID_NDK_BUILD)
return true;
#elif defined(USE_X11)
if(nativeDisplay)
......
......@@ -344,13 +344,8 @@ bool WindowSurface::checkForResize()
int windowWidth = client.right - client.left;
int windowHeight = client.bottom - client.top;
#elif defined(__ANDROID__)
#ifdef ANDROID_NDK_BUILD
int windowWidth = ANativeWindow_getWidth(window);
int windowHeight = ANativeWindow_getHeight(window);
#else
int windowWidth; window->query(window, NATIVE_WINDOW_WIDTH, &windowWidth);
int windowHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &windowHeight);
#endif
#elif defined(USE_X11)
XWindowAttributes windowAttributes;
Status status = libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes);
......
......@@ -24,7 +24,7 @@
#include "Common/Version.h"
#if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
#include <system/window.h>
#include <vndk/window.h>
#elif defined(USE_X11)
#include "Main/libX11.hpp"
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment