libhidltransport \
libhwbinder \
libvintf \
+ libnativewindow \
LOCAL_SHARED_LIBRARIES += \
libhwui \
libdl \
+# our headers include libnativewindow's public headers
+LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := \
+ libnativewindow \
+
# we need to access the private Bionic header
# <bionic_tls.h> in com_google_android_gles_jni_GLImpl.cpp
LOCAL_C_INCLUDES += bionic/libc/private
#include <android_runtime/android_hardware_HardwareBuffer.h>
#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/Log.h>
+#include <private/android/AHardwareBufferHelpers.h>
#include <binder/Parcel.h>
+
+#include <ui/GraphicBuffer.h>
#include <gui/IGraphicBufferAlloc.h>
#include <gui/ISurfaceComposer.h>
-#include <hardware/gralloc1.h>
-#include <ui/GraphicBuffer.h>
-
#include <private/gui/ComposerService.h>
+#include <hardware/gralloc1.h>
+
#include "core_jni_helpers.h"
using namespace android;
sp<GraphicBuffer> buffer;
};
-
-// ----------------------------------------------------------------------------
-// Helper functions
-// ----------------------------------------------------------------------------
-
-static inline bool containsBits(uint64_t mask, uint64_t bitsToCheck) {
- return (mask & bitsToCheck) == bitsToCheck;
-}
-
// ----------------------------------------------------------------------------
// HardwareBuffer lifecycle
// ----------------------------------------------------------------------------
delete wrapper;
}
-static jlong android_hardware_HardwareBuffer_getNativeFinalizer(JNIEnv* env,
- jobject clazz) {
+static jlong android_hardware_HardwareBuffer_getNativeFinalizer(JNIEnv* env, jobject clazz) {
return static_cast<jlong>(reinterpret_cast<uintptr_t>(&destroyWrapper));
}
if (env->IsInstanceOf(hardwareBufferObj, gHardwareBufferClassInfo.clazz)) {
GraphicBuffer* buffer = GraphicBufferWrapper_to_GraphicBuffer(
env->GetLongField(hardwareBufferObj, gHardwareBufferClassInfo.mNativeObject));
- return reinterpret_cast<AHardwareBuffer*>(buffer);
+ return AHardwareBuffer_from_GraphicBuffer(buffer);
+
} else {
return nullptr;
}
jobject android_hardware_HardwareBuffer_createFromAHardwareBuffer(
JNIEnv* env, AHardwareBuffer* hardwareBuffer) {
- GraphicBuffer* buffer = reinterpret_cast<GraphicBuffer*>(hardwareBuffer);
+ GraphicBuffer* buffer = AHardwareBuffer_to_GraphicBuffer(hardwareBuffer);
GraphicBufferWrapper* wrapper = new GraphicBufferWrapper(buffer);
jobject hardwareBufferObj = env->NewObject(gHardwareBufferClassInfo.clazz,
gHardwareBufferClassInfo.ctor, reinterpret_cast<jlong>(wrapper));
}
uint32_t android_hardware_HardwareBuffer_convertFromPixelFormat(uint32_t format) {
- switch (format) {
- case HAL_PIXEL_FORMAT_RGBA_8888:
- return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
- case HAL_PIXEL_FORMAT_RGBX_8888:
- return AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM;
- case HAL_PIXEL_FORMAT_RGB_565:
- return AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM;
- case HAL_PIXEL_FORMAT_RGB_888:
- return AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM;
- case HAL_PIXEL_FORMAT_RGBA_FP16:
- return AHARDWAREBUFFER_FORMAT_R16G16B16A16_SFLOAT;
- case HAL_PIXEL_FORMAT_RGBA_1010102:
- return AHARDWAREBUFFER_FORMAT_A2R10G10B10_UNORM_PACK32;
- case HAL_PIXEL_FORMAT_BLOB:
- return AHARDWAREBUFFER_FORMAT_BLOB;
- default:
- ALOGE("Unknown pixel format %u", format);
- return 0;
- }
+ return AHardwareBuffer_convertFromPixelFormat(format);
}
uint32_t android_hardware_HardwareBuffer_convertToPixelFormat(uint32_t format) {
- switch (format) {
- case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
- return HAL_PIXEL_FORMAT_RGBA_8888;
- case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
- return HAL_PIXEL_FORMAT_RGBX_8888;
- case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
- return HAL_PIXEL_FORMAT_RGB_565;
- case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
- return HAL_PIXEL_FORMAT_RGB_888;
- case AHARDWAREBUFFER_FORMAT_R16G16B16A16_SFLOAT:
- return HAL_PIXEL_FORMAT_RGBA_FP16;
- case AHARDWAREBUFFER_FORMAT_A2R10G10B10_UNORM_PACK32:
- return HAL_PIXEL_FORMAT_RGBA_1010102;
- case AHARDWAREBUFFER_FORMAT_BLOB:
- return HAL_PIXEL_FORMAT_BLOB;
- default:
- ALOGE("Unknown AHardwareBuffer format %u", format);
- return 0;
- }
+ return AHardwareBuffer_convertToPixelFormat(format);
}
void android_hardware_HardwareBuffer_convertToGrallocUsageBits(uint64_t usage0,
- uint64_t usage1, uint64_t* outProducerUsage,
+ uint64_t /*usage1*/, uint64_t* outProducerUsage,
uint64_t* outConsumerUsage) {
- *outProducerUsage = 0;
- *outConsumerUsage = 0;
- if (containsBits(usage0, AHARDWAREBUFFER_USAGE0_CPU_READ))
- *outConsumerUsage |= GRALLOC1_CONSUMER_USAGE_CPU_READ;
- if (containsBits(usage0, AHARDWAREBUFFER_USAGE0_CPU_READ_OFTEN))
- *outConsumerUsage |= GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN;
- if (containsBits(usage0, AHARDWAREBUFFER_USAGE0_CPU_WRITE))
- *outProducerUsage |= GRALLOC1_PRODUCER_USAGE_CPU_WRITE;
- if (containsBits(usage0, AHARDWAREBUFFER_USAGE0_CPU_WRITE_OFTEN))
- *outProducerUsage |= GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN;
- if (containsBits(usage0, AHARDWAREBUFFER_USAGE0_GPU_SAMPLED_IMAGE))
- *outConsumerUsage |= GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE;
- if (containsBits(usage0, AHARDWAREBUFFER_USAGE0_GPU_COLOR_OUTPUT))
- *outProducerUsage |= GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET;
- // Not sure what this should be.
- //if (containsBits(usage0, AHARDWAREBUFFER_USAGE0_GPU_CUBEMAP)) bits |= 0;
- if (containsBits(usage0, AHARDWAREBUFFER_USAGE0_GPU_DATA_BUFFER))
- *outConsumerUsage |= GRALLOC1_CONSUMER_USAGE_GPU_DATA_BUFFER;
- if (containsBits(usage0, AHARDWAREBUFFER_USAGE0_VIDEO_ENCODE))
- *outConsumerUsage |= GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER;
- if (containsBits(usage0, AHARDWAREBUFFER_USAGE0_PROTECTED_CONTENT))
- *outProducerUsage |= GRALLOC1_PRODUCER_USAGE_PROTECTED;
- if (containsBits(usage0, AHARDWAREBUFFER_USAGE0_SENSOR_DIRECT_DATA))
- *outProducerUsage |= GRALLOC1_PRODUCER_USAGE_SENSOR_DIRECT_DATA;
+ AHardwareBuffer_convertToGrallocUsageBits(usage0, outProducerUsage, outConsumerUsage);
}
uint64_t android_hardware_HardwareBuffer_convertFromGrallocUsageBits(
uint64_t producerUsage, uint64_t consumerUsage) {
- uint64_t bits = 0;
- if (containsBits(consumerUsage, GRALLOC1_CONSUMER_USAGE_CPU_READ))
- bits |= AHARDWAREBUFFER_USAGE0_CPU_READ;
- if (containsBits(consumerUsage, GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN))
- bits |= AHARDWAREBUFFER_USAGE0_CPU_READ_OFTEN;
- if (containsBits(producerUsage, GRALLOC1_PRODUCER_USAGE_CPU_WRITE))
- bits |= AHARDWAREBUFFER_USAGE0_CPU_WRITE;
- if (containsBits(producerUsage, GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN))
- bits |= AHARDWAREBUFFER_USAGE0_CPU_WRITE_OFTEN;
- if (containsBits(consumerUsage, GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE))
- bits |= AHARDWAREBUFFER_USAGE0_GPU_SAMPLED_IMAGE;
- if (containsBits(producerUsage, GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET))
- bits |= AHARDWAREBUFFER_USAGE0_GPU_COLOR_OUTPUT;
- if (containsBits(consumerUsage, GRALLOC1_CONSUMER_USAGE_GPU_DATA_BUFFER))
- bits |= AHARDWAREBUFFER_USAGE0_GPU_DATA_BUFFER;
- if (containsBits(consumerUsage, GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER))
- bits |= AHARDWAREBUFFER_USAGE0_VIDEO_ENCODE;
- if (containsBits(producerUsage, GRALLOC1_PRODUCER_USAGE_PROTECTED))
- bits |= AHARDWAREBUFFER_USAGE0_PROTECTED_CONTENT;
- if (containsBits(producerUsage, GRALLOC1_PRODUCER_USAGE_SENSOR_DIRECT_DATA))
- bits |= AHARDWAREBUFFER_USAGE0_SENSOR_DIRECT_DATA;
-
- return bits;
+ return AHardwareBuffer_convertFromGrallocUsageBits(producerUsage, consumerUsage);
}
} // namespace android
const char* const kClassPathName = "android/hardware/HardwareBuffer";
static const JNINativeMethod gMethods[] = {
- { "nCreateHardwareBuffer", "(IIIIJ)J", (void*) android_hardware_HardwareBuffer_create },
- { "nGetNativeFinalizer", "()J", (void*) android_hardware_HardwareBuffer_getNativeFinalizer },
+ { "nCreateHardwareBuffer", "(IIIIJ)J",
+ (void*) android_hardware_HardwareBuffer_create },
+ { "nGetNativeFinalizer", "()J",
+ (void*) android_hardware_HardwareBuffer_getNativeFinalizer },
{ "nWriteHardwareBufferToParcel", "(JLandroid/os/Parcel;)V",
(void*) android_hardware_HardwareBuffer_write },
{ "nReadHardwareBufferFromParcel", "(Landroid/os/Parcel;)J",
(void*) android_hardware_HardwareBuffer_read },
// --------------- @FastNative ----------------------
- { "nGetWidth", "(J)I", (void*) android_hardware_HardwareBuffer_getWidth },
- { "nGetHeight", "(J)I", (void*) android_hardware_HardwareBuffer_getHeight },
- { "nGetFormat", "(J)I", (void*) android_hardware_HardwareBuffer_getFormat },
- { "nGetLayers", "(J)I", (void*) android_hardware_HardwareBuffer_getLayers },
- { "nGetUsage", "(J)J", (void*) android_hardware_HardwareBuffer_getUsage },
+ { "nGetWidth", "(J)I", (void*) android_hardware_HardwareBuffer_getWidth },
+ { "nGetHeight", "(J)I", (void*) android_hardware_HardwareBuffer_getHeight },
+ { "nGetFormat", "(J)I", (void*) android_hardware_HardwareBuffer_getFormat },
+ { "nGetLayers", "(J)I", (void*) android_hardware_HardwareBuffer_getLayers },
+ { "nGetUsage", "(J)J", (void*) android_hardware_HardwareBuffer_getUsage },
};
int register_android_hardware_HardwareBuffer(JNIEnv* env) {
#include "SkiaProfileRenderer.h"
#include "utils/TraceUtils.h"
-#include <android/native_window.h>
#include <cutils/properties.h>
#include <strings.h>
#include <GrTypes.h>
#include <vk/GrVkTypes.h>
-#include <android/native_window.h>
#include <cutils/properties.h>
#include <strings.h>
#include "renderstate/RenderState.h"
#include "OpenGLReadback.h"
-#include <android/native_window.h>
#include <cutils/properties.h>
#include <strings.h>
libgui \
libui \
libinput \
- libinputflinger
+ libinputflinger \
+ libnativewindow
LOCAL_C_INCLUDES := \
frameworks/native/services
asset_manager.cpp \
choreographer.cpp \
configuration.cpp \
- hardware_buffer.cpp \
hardware_buffer_jni.cpp \
input.cpp \
looper.cpp \
native_activity.cpp \
- native_window.cpp \
native_window_jni.cpp \
net.c \
obb.cpp \
LOCAL_STATIC_LIBRARIES := \
libstorage \
- libarect
+ libarect \
+
+LOCAL_WHOLE_STATIC_LIBRARIES := \
+ libnativewindow
LOCAL_C_INCLUDES += \
frameworks/base/native/include \
bionic/libc/dns/include \
system/netd/include \
-LOCAL_EXPORT_STATIC_LIBRARY_HEADERS := libarect
+LOCAL_EXPORT_STATIC_LIBRARY_HEADERS := \
+ libarect \
+ libnativewindow \
LOCAL_MODULE := libandroid
+++ /dev/null
-/*
- * Copyright (C) 2017 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.
- */
-
-#define LOG_TAG "AHardwareBuffer"
-
-#include <android/hardware_buffer.h>
-
-#include <errno.h>
-#include <sys/socket.h>
-
-#include <memory>
-
-#include <cutils/native_handle.h>
-
-#include <utils/Log.h>
-
-#include <ui/GraphicBuffer.h>
-
-#include <binder/IServiceManager.h>
-#include <gui/ISurfaceComposer.h>
-#include <gui/IGraphicBufferAlloc.h>
-
-#include <android_runtime/android_hardware_HardwareBuffer.h>
-
-
-static constexpr int kDataBufferSize = 64 * sizeof(int); // 64 ints
-
-using namespace android;
-
-static inline const GraphicBuffer* AHardwareBuffer_to_GraphicBuffer(
- const AHardwareBuffer* buffer) {
- return reinterpret_cast<const GraphicBuffer*>(buffer);
-}
-
-static inline GraphicBuffer* AHardwareBuffer_to_GraphicBuffer(
- AHardwareBuffer* buffer) {
- return reinterpret_cast<GraphicBuffer*>(buffer);
-}
-
-static inline AHardwareBuffer* GraphicBuffer_to_AHardwareBuffer(
- GraphicBuffer* buffer) {
- return reinterpret_cast<AHardwareBuffer*>(buffer);
-}
-
-// ----------------------------------------------------------------------------
-// Public functions
-// ----------------------------------------------------------------------------
-
-int AHardwareBuffer_allocate(const AHardwareBuffer_Desc* desc,
- AHardwareBuffer** outBuffer) {
- if (!outBuffer || !desc) return BAD_VALUE;
-
- // The holder is used to destroy the buffer if an error occurs.
- sp<IServiceManager> sm = defaultServiceManager();
- if (sm == nullptr) {
- ALOGE("Unable to connect to ServiceManager");
- return PERMISSION_DENIED;
- }
-
- // Get the SurfaceFlingerService.
- sp<ISurfaceComposer> composer = interface_cast<ISurfaceComposer>(
- sm->getService(String16("SurfaceFlinger")));
- if (composer == nullptr) {
- ALOGE("Unable to connect to surface composer");
- return PERMISSION_DENIED;
- }
- // Get an IGraphicBufferAlloc to create the buffer.
- sp<IGraphicBufferAlloc> allocator = composer->createGraphicBufferAlloc();
- if (allocator == nullptr) {
- ALOGE("Unable to obtain a buffer allocator");
- return PERMISSION_DENIED;
- }
-
- int format = android_hardware_HardwareBuffer_convertToPixelFormat(
- desc->format);
- if (format == 0) {
- ALOGE("Invalid pixel format");
- return BAD_VALUE;
- }
-
- if (desc->format == AHARDWAREBUFFER_FORMAT_BLOB && desc->height != 1) {
- ALOGE("Height must be 1 when using the AHARDWAREBUFFER_FORMAT_BLOB "
- "format");
- return BAD_VALUE;
- }
-
- status_t err;
- uint64_t producerUsage = 0;
- uint64_t consumerUsage = 0;
- android_hardware_HardwareBuffer_convertToGrallocUsageBits(desc->usage0,
- desc->usage1, &producerUsage, &consumerUsage);
- sp<GraphicBuffer> gbuffer = allocator->createGraphicBuffer(desc->width,
- desc->height, format, desc->layers, producerUsage, consumerUsage,
- std::string("AHardwareBuffer pid [") + std::to_string(getpid()) +
- "]", &err);
- if (err != NO_ERROR) {
- return err;
- }
-
- *outBuffer = GraphicBuffer_to_AHardwareBuffer(gbuffer.get());
- // Ensure the buffer doesn't get destroyed with the sp<> goes away.
- AHardwareBuffer_acquire(*outBuffer);
- return NO_ERROR;
-}
-
-void AHardwareBuffer_acquire(AHardwareBuffer* buffer) {
- AHardwareBuffer_to_GraphicBuffer(buffer)->incStrong(
- (void*)AHardwareBuffer_acquire);
-}
-
-void AHardwareBuffer_release(AHardwareBuffer* buffer) {
- AHardwareBuffer_to_GraphicBuffer(buffer)->decStrong(
- (void*)AHardwareBuffer_acquire);
-}
-
-void AHardwareBuffer_describe(const AHardwareBuffer* buffer,
- AHardwareBuffer_Desc* outDesc) {
- if (!buffer || !outDesc) return;
-
- const GraphicBuffer* gbuffer = AHardwareBuffer_to_GraphicBuffer(buffer);
-
- outDesc->width = gbuffer->getWidth();
- outDesc->height = gbuffer->getHeight();
- outDesc->layers = gbuffer->getLayerCount();
- outDesc->usage0 =
- android_hardware_HardwareBuffer_convertFromGrallocUsageBits(
- gbuffer->getUsage(), gbuffer->getUsage());
- outDesc->usage1 = 0;
- outDesc->format = android_hardware_HardwareBuffer_convertFromPixelFormat(
- static_cast<uint32_t>(gbuffer->getPixelFormat()));
-}
-
-int AHardwareBuffer_lock(AHardwareBuffer* buffer, uint64_t usage0,
- int32_t fence, const ARect* rect, void** outVirtualAddress) {
- if (!buffer) return BAD_VALUE;
-
- if (usage0 & ~(AHARDWAREBUFFER_USAGE0_CPU_READ_OFTEN |
- AHARDWAREBUFFER_USAGE0_CPU_WRITE_OFTEN)) {
- ALOGE("Invalid usage flags passed to AHardwareBuffer_lock; only "
- " AHARDWAREBUFFER_USAGE0_CPU_* flags are allowed");
- return BAD_VALUE;
- }
-
- uint64_t producerUsage = 0;
- uint64_t consumerUsage = 0;
- android_hardware_HardwareBuffer_convertToGrallocUsageBits(usage0, 0,
- &producerUsage, &consumerUsage);
- GraphicBuffer* gBuffer = AHardwareBuffer_to_GraphicBuffer(buffer);
- Rect bounds;
- if (!rect) {
- bounds.set(Rect(gBuffer->getWidth(), gBuffer->getHeight()));
- } else {
- bounds.set(Rect(rect->left, rect->top, rect->right, rect->bottom));
- }
- return gBuffer->lockAsync(producerUsage, consumerUsage, bounds,
- outVirtualAddress, fence);
-}
-
-int AHardwareBuffer_unlock(AHardwareBuffer* buffer, int32_t* fence) {
- if (!buffer) return BAD_VALUE;
-
- GraphicBuffer* gBuffer = AHardwareBuffer_to_GraphicBuffer(buffer);
- return gBuffer->unlockAsync(fence);
-}
-
-int AHardwareBuffer_sendHandleToUnixSocket(const AHardwareBuffer* buffer,
- int socketFd) {
- if (!buffer) return BAD_VALUE;
- const GraphicBuffer* gBuffer = AHardwareBuffer_to_GraphicBuffer(buffer);
-
- size_t flattenedSize = gBuffer->getFlattenedSize();
- size_t fdCount = gBuffer->getFdCount();
-
- std::unique_ptr<uint8_t[]> data(new uint8_t[flattenedSize]);
- std::unique_ptr<int[]> fds(new int[fdCount]);
-
- // Make copies of needed items since flatten modifies them, and we don't
- // want to send anything if there's an error during flatten.
- size_t flattenedSizeCopy = flattenedSize;
- size_t fdCountCopy = fdCount;
- void* dataStart = data.get();
- int* fdsStart = fds.get();
- status_t err = gBuffer->flatten(dataStart, flattenedSizeCopy, fdsStart,
- fdCountCopy);
- if (err != NO_ERROR) {
- return err;
- }
-
- struct iovec iov[1];
- iov[0].iov_base = data.get();
- iov[0].iov_len = flattenedSize;
-
- char buf[CMSG_SPACE(kDataBufferSize)];
- struct msghdr msg = {
- .msg_control = buf,
- .msg_controllen = sizeof(buf),
- .msg_iov = &iov[0],
- .msg_iovlen = 1,
- };
-
- struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- cmsg->cmsg_len = CMSG_LEN(sizeof(int) * fdCount);
- int* fdData = reinterpret_cast<int*>(CMSG_DATA(cmsg));
- memcpy(fdData, fds.get(), sizeof(int) * fdCount);
- msg.msg_controllen = cmsg->cmsg_len;
-
- int result = sendmsg(socketFd, &msg, 0);
- if (result <= 0) {
- ALOGE("Error writing AHardwareBuffer to socket: error %#x (%s)",
- result, strerror(errno));
- return result;
- }
- return NO_ERROR;
-}
-
-int AHardwareBuffer_recvHandleFromUnixSocket(int socketFd,
- AHardwareBuffer** outBuffer) {
- if (!outBuffer) return BAD_VALUE;
-
- char dataBuf[CMSG_SPACE(kDataBufferSize)];
- char fdBuf[CMSG_SPACE(kDataBufferSize)];
- struct iovec iov[1];
- iov[0].iov_base = dataBuf;
- iov[0].iov_len = sizeof(dataBuf);
-
- struct msghdr msg = {
- .msg_control = fdBuf,
- .msg_controllen = sizeof(fdBuf),
- .msg_iov = &iov[0],
- .msg_iovlen = 1,
- };
-
- int result = recvmsg(socketFd, &msg, 0);
- if (result <= 0) {
- ALOGE("Error reading AHardwareBuffer from socket: error %#x (%s)",
- result, strerror(errno));
- return result;
- }
-
- if (msg.msg_iovlen != 1) {
- ALOGE("Error reading AHardwareBuffer from socket: bad data length");
- return INVALID_OPERATION;
- }
-
- if (msg.msg_controllen % sizeof(int) != 0) {
- ALOGE("Error reading AHardwareBuffer from socket: bad fd length");
- return INVALID_OPERATION;
- }
-
- size_t dataLen = msg.msg_iov[0].iov_len;
- const void* data = static_cast<const void*>(msg.msg_iov[0].iov_base);
- if (!data) {
- ALOGE("Error reading AHardwareBuffer from socket: no buffer data");
- return INVALID_OPERATION;
- }
-
- struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg);
- if (!cmsg) {
- ALOGE("Error reading AHardwareBuffer from socket: no fd header");
- return INVALID_OPERATION;
- }
-
- size_t fdCount = msg.msg_controllen >> 2;
- const int* fdData = reinterpret_cast<const int*>(CMSG_DATA(cmsg));
- if (!fdData) {
- ALOGE("Error reading AHardwareBuffer from socket: no fd data");
- return INVALID_OPERATION;
- }
-
- GraphicBuffer* gBuffer = new GraphicBuffer();
- status_t err = gBuffer->unflatten(data, dataLen, fdData, fdCount);
- if (err != NO_ERROR) {
- return err;
- }
- *outBuffer = GraphicBuffer_to_AHardwareBuffer(gBuffer);
- // Ensure the buffer has a positive ref-count.
- AHardwareBuffer_acquire(*outBuffer);
-
- return NO_ERROR;
-}
-
-const struct native_handle* AHardwareBuffer_getNativeHandle(
- const AHardwareBuffer* buffer) {
- if (!buffer) return nullptr;
- const GraphicBuffer* gbuffer = AHardwareBuffer_to_GraphicBuffer(buffer);
- return gbuffer->handle;
-}
+++ /dev/null
-/*
- * Copyright (C) 2010 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.
- */
-
-#define LOG_TAG "Surface"
-
-#include <android/native_window.h>
-#include <system/window.h>
-
-void ANativeWindow_acquire(ANativeWindow* window) {
- window->incStrong((void*)ANativeWindow_acquire);
-}
-
-void ANativeWindow_release(ANativeWindow* window) {
- window->decStrong((void*)ANativeWindow_acquire);
-}
-
-static int32_t getWindowProp(ANativeWindow* window, int what) {
- int value;
- int res = window->query(window, what, &value);
- return res < 0 ? res : value;
-}
-
-int32_t ANativeWindow_getWidth(ANativeWindow* window) {
- return getWindowProp(window, NATIVE_WINDOW_WIDTH);
-}
-
-int32_t ANativeWindow_getHeight(ANativeWindow* window) {
- return getWindowProp(window, NATIVE_WINDOW_HEIGHT);
-}
-
-int32_t ANativeWindow_getFormat(ANativeWindow* window) {
- return getWindowProp(window, NATIVE_WINDOW_FORMAT);
-}
-
-int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, int32_t width,
- int32_t height, int32_t format) {
- int32_t err = native_window_set_buffers_format(window, format);
- if (!err) {
- err = native_window_set_buffers_user_dimensions(window, width, height);
- if (!err) {
- int mode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
- if (width && height) {
- mode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW;
- }
- err = native_window_set_scaling_mode(window, mode);
- }
- }
- return err;
-}
-
-int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
- ARect* inOutDirtyBounds) {
- return window->perform(window, NATIVE_WINDOW_LOCK, outBuffer, inOutDirtyBounds);
-}
-
-int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) {
- return window->perform(window, NATIVE_WINDOW_UNLOCK_AND_POST);
-}