aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYilong Li <liyl@google.com>2020-07-14 07:38:27 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-07-14 07:38:27 +0000
commit2926fe3d1788fbac93a25e15cdf94d38112aa07e (patch)
tree67e1a8f0c877098b8162dd4855ef477285bae867
parent63cbce5226db4a063c6fc4ce9ab3da5f1887aad3 (diff)
parent06a207999c4dad637df1604f540c3d72543f5581 (diff)
downloaddevice_generic_goldfish-opengl-2926fe3d1788fbac93a25e15cdf94d38112aa07e.tar.gz
device_generic_goldfish-opengl-2926fe3d1788fbac93a25e15cdf94d38112aa07e.tar.bz2
device_generic_goldfish-opengl-2926fe3d1788fbac93a25e15cdf94d38112aa07e.zip
Merge changes I7b8a2794,I42b46ee4 am: baa1b0342e am: 06a207999c
Original change: https://android-review.googlesource.com/c/device/generic/goldfish-opengl/+/1361108 Change-Id: I4d809b26b974894f9854aa5f27c2dca3abd24d53
-rw-r--r--system/OpenglSystemCommon/HostConnection.cpp168
-rw-r--r--system/OpenglSystemCommon/HostConnection.h23
-rw-r--r--system/OpenglSystemCommon/ThreadInfo.cpp1
-rw-r--r--system/OpenglSystemCommon/ThreadInfo.h4
-rw-r--r--system/gralloc/gralloc_30.cpp4
-rw-r--r--system/gralloc/gralloc_old.cpp2
-rw-r--r--system/hwc2/EmuHWC2.cpp4
-rw-r--r--system/vulkan_enc/VkEncoder.cpp2
8 files changed, 93 insertions, 115 deletions
diff --git a/system/OpenglSystemCommon/HostConnection.cpp b/system/OpenglSystemCommon/HostConnection.cpp
index f3084759..7829545d 100644
--- a/system/OpenglSystemCommon/HostConnection.cpp
+++ b/system/OpenglSystemCommon/HostConnection.cpp
@@ -352,11 +352,6 @@ static GoldfishGralloc m_goldfishGralloc;
static GoldfishProcessPipe m_goldfishProcessPipe;
HostConnection::HostConnection() :
- m_stream(NULL),
- m_glEnc(NULL),
- m_gl2Enc(NULL),
- m_vkEnc(NULL),
- m_rcEnc(NULL),
m_checksumHelper(),
m_glExtensions(),
m_grallocOnly(true),
@@ -369,15 +364,11 @@ HostConnection::~HostConnection()
// round-trip to ensure that queued commands have been processed
// before process pipe closure is detected.
if (m_rcEnc) {
- (void) m_rcEnc->rcGetRendererVersion(m_rcEnc);
+ (void)m_rcEnc->rcGetRendererVersion(m_rcEnc.get());
}
if (m_grallocType == GRALLOC_TYPE_MINIGBM) {
delete m_grallocHelper;
}
- delete m_stream;
- delete m_glEnc;
- delete m_gl2Enc;
- delete m_rcEnc;
if (m_rendernodeFdOwned) {
close(m_rendernodeFd);
@@ -385,43 +376,40 @@ HostConnection::~HostConnection()
}
// static
-HostConnection* HostConnection::connect(HostConnection* con) {
- if (!con) return con;
-
+std::unique_ptr<HostConnection> HostConnection::connect() {
const enum HostConnectionType connType = getConnectionTypeFromProperty();
// const enum HostConnectionType connType = HOST_CONNECTION_VIRTIO_GPU;
+ // Use "new" to access a non-public constructor.
+ auto con = std::unique_ptr<HostConnection>(new HostConnection);
switch (connType) {
case HOST_CONNECTION_ADDRESS_SPACE: {
- AddressSpaceStream *stream = createAddressSpaceStream(STREAM_BUFFER_SIZE);
+ auto stream = std::unique_ptr<AddressSpaceStream>(
+ createAddressSpaceStream(STREAM_BUFFER_SIZE));
if (!stream) {
ALOGE("Failed to create AddressSpaceStream for host connection!!!\n");
- delete con;
- return NULL;
+ return nullptr;
}
con->m_connectionType = HOST_CONNECTION_ADDRESS_SPACE;
con->m_grallocType = GRALLOC_TYPE_RANCHU;
- con->m_stream = stream;
+ con->m_stream = std::move(stream);
con->m_grallocHelper = &m_goldfishGralloc;
con->m_processPipe = &m_goldfishProcessPipe;
break;
}
case HOST_CONNECTION_QEMU_PIPE: {
- QemuPipeStream *stream = new QemuPipeStream(STREAM_BUFFER_SIZE);
+ auto stream = std::make_unique<QemuPipeStream>(STREAM_BUFFER_SIZE);
if (!stream) {
ALOGE("Failed to create QemuPipeStream for host connection!!!\n");
- delete con;
- return NULL;
+ return nullptr;
}
if (stream->connect() < 0) {
ALOGE("Failed to connect to host (QemuPipeStream)!!!\n");
- delete stream;
- delete con;
- return NULL;
+ return nullptr;
}
con->m_connectionType = HOST_CONNECTION_QEMU_PIPE;
con->m_grallocType = GRALLOC_TYPE_RANCHU;
- con->m_stream = stream;
+ con->m_stream = std::move(stream);
con->m_grallocHelper = &m_goldfishGralloc;
con->m_processPipe = &m_goldfishProcessPipe;
break;
@@ -429,26 +417,22 @@ HostConnection* HostConnection::connect(HostConnection* con) {
case HOST_CONNECTION_TCP: {
#ifdef __Fuchsia__
ALOGE("Fuchsia doesn't support HOST_CONNECTION_TCP!!!\n");
- delete con;
- return NULL;
+ return nullptr;
break;
#else
- TcpStream *stream = new TcpStream(STREAM_BUFFER_SIZE);
+ auto stream = std::make_unique<TcpStream>(STREAM_BUFFER_SIZE);
if (!stream) {
ALOGE("Failed to create TcpStream for host connection!!!\n");
- delete con;
- return NULL;
+ return nullptr;
}
if (stream->connect("10.0.2.2", STREAM_PORT_NUM) < 0) {
ALOGE("Failed to connect to host (TcpStream)!!!\n");
- delete stream;
- delete con;
- return NULL;
+ return nullptr;
}
con->m_connectionType = HOST_CONNECTION_TCP;
con->m_grallocType = GRALLOC_TYPE_RANCHU;
- con->m_stream = stream;
+ con->m_stream = std::move(stream);
con->m_grallocHelper = &m_goldfishGralloc;
con->m_processPipe = &m_goldfishProcessPipe;
break;
@@ -456,21 +440,18 @@ HostConnection* HostConnection::connect(HostConnection* con) {
}
#ifdef VIRTIO_GPU
case HOST_CONNECTION_VIRTIO_GPU: {
- VirtioGpuStream *stream = new VirtioGpuStream(STREAM_BUFFER_SIZE);
+ auto stream = std::make_unique<VirtioGpuStream>(STREAM_BUFFER_SIZE);
if (!stream) {
ALOGE("Failed to create VirtioGpu for host connection!!!\n");
- delete con;
- return NULL;
+ return nullptr;
}
if (stream->connect() < 0) {
ALOGE("Failed to connect to host (VirtioGpu)!!!\n");
- delete stream;
- delete con;
- return NULL;
+ return nullptr;
}
con->m_connectionType = HOST_CONNECTION_VIRTIO_GPU;
con->m_grallocType = GRALLOC_TYPE_MINIGBM;
- con->m_stream = stream;
+ con->m_stream = std::move(stream);
con->m_rendernodeFdOwned = false;
con->m_rendernodeFdOwned = stream->getRendernodeFd();
MinigbmGralloc* m = new MinigbmGralloc;
@@ -480,21 +461,19 @@ HostConnection* HostConnection::connect(HostConnection* con) {
break;
}
case HOST_CONNECTION_VIRTIO_GPU_PIPE: {
- VirtioGpuPipeStream *stream = new VirtioGpuPipeStream(STREAM_BUFFER_SIZE);
+ auto stream =
+ std::make_unique<VirtioGpuPipeStream>(STREAM_BUFFER_SIZE);
if (!stream) {
ALOGE("Failed to create VirtioGpu for host connection!!!\n");
- delete con;
- return NULL;
+ return nullptr;
}
if (stream->connect() < 0) {
ALOGE("Failed to connect to host (VirtioGpu)!!!\n");
- delete stream;
- delete con;
- return NULL;
+ return nullptr;
}
con->m_connectionType = HOST_CONNECTION_VIRTIO_GPU_PIPE;
con->m_grallocType = getGrallocTypeFromProperty();
- con->m_stream = stream;
+ con->m_stream = std::move(stream);
con->m_rendernodeFdOwned = false;
con->m_rendernodeFd = stream->getRendernodeFd();
switch (con->m_grallocType) {
@@ -516,15 +495,15 @@ HostConnection* HostConnection::connect(HostConnection* con) {
}
#ifndef HOST_BUILD
case HOST_CONNECTION_VIRTIO_GPU_ADDRESS_SPACE: {
- AddressSpaceStream *stream = createVirtioGpuAddressSpaceStream(STREAM_BUFFER_SIZE);
+ auto stream = std::unique_ptr<AddressSpaceStream>(
+ createVirtioGpuAddressSpaceStream(STREAM_BUFFER_SIZE));
if (!stream) {
ALOGE("Failed to create virtgpu AddressSpaceStream for host connection!!!\n");
- delete con;
- return NULL;
+ return nullptr;
}
con->m_connectionType = HOST_CONNECTION_VIRTIO_GPU_ADDRESS_SPACE;
con->m_grallocType = getGrallocTypeFromProperty();
- con->m_stream = stream;
+ con->m_stream = std::move(stream);
con->m_rendernodeFdOwned = false;
con->m_rendernodeFd = stream->getRendernodeFd();
switch (con->m_grallocType) {
@@ -558,7 +537,7 @@ HostConnection* HostConnection::connect(HostConnection* con) {
con->m_stream->commitBuffer(sizeof(unsigned int));
ALOGD("HostConnection::get() New Host Connection established %p, tid %d\n",
- con, getCurrentThreadId());
+ con.get(), getCurrentThreadId());
// ALOGD("Address space echo latency check done\n");
return con;
@@ -575,13 +554,10 @@ HostConnection *HostConnection::getWithThreadInfo(EGLThreadInfo* tinfo) {
}
if (tinfo->hostConn == NULL) {
- HostConnection *con = new HostConnection();
- con = connect(con);
-
- tinfo->hostConn = con;
+ tinfo->hostConn = HostConnection::createUnique();
}
- return tinfo->hostConn;
+ return tinfo->hostConn.get();
}
void HostConnection::exit() {
@@ -590,38 +566,31 @@ void HostConnection::exit() {
return;
}
- if (tinfo->hostConn) {
- delete tinfo->hostConn;
- tinfo->hostConn = NULL;
- }
+ tinfo->hostConn.reset();
}
// static
-HostConnection *HostConnection::createUnique() {
+std::unique_ptr<HostConnection> HostConnection::createUnique() {
ALOGD("%s: call\n", __func__);
- return connect(new HostConnection());
-}
-
-// static
-void HostConnection::teardownUnique(HostConnection* con) {
- delete con;
+ return connect();
}
GLEncoder *HostConnection::glEncoder()
{
if (!m_glEnc) {
- m_glEnc = new GLEncoder(m_stream, checksumHelper());
+ m_glEnc = std::make_unique<GLEncoder>(m_stream.get(), checksumHelper());
DBG("HostConnection::glEncoder new encoder %p, tid %d",
m_glEnc, getCurrentThreadId());
m_glEnc->setContextAccessor(s_getGLContext);
}
- return m_glEnc;
+ return m_glEnc.get();
}
GL2Encoder *HostConnection::gl2Encoder()
{
if (!m_gl2Enc) {
- m_gl2Enc = new GL2Encoder(m_stream, checksumHelper());
+ m_gl2Enc =
+ std::make_unique<GL2Encoder>(m_stream.get(), checksumHelper());
DBG("HostConnection::gl2Encoder new encoder %p, tid %d",
m_gl2Enc, getCurrentThreadId());
m_gl2Enc->setContextAccessor(s_getGL2Context);
@@ -630,45 +599,48 @@ GL2Encoder *HostConnection::gl2Encoder()
getDrawCallFlushIntervalFromProperty());
m_gl2Enc->setHasAsyncUnmapBuffer(m_rcEnc->hasAsyncUnmapBuffer());
}
- return m_gl2Enc;
+ return m_gl2Enc.get();
}
VkEncoder *HostConnection::vkEncoder()
{
if (!m_vkEnc) {
- m_vkEnc = new VkEncoder(m_stream);
+ m_vkEnc = std::make_unique<VkEncoder>(m_stream.get());
}
- return m_vkEnc;
+ return m_vkEnc.get();
}
ExtendedRCEncoderContext *HostConnection::rcEncoder()
{
if (!m_rcEnc) {
- m_rcEnc = new ExtendedRCEncoderContext(m_stream, checksumHelper());
- setChecksumHelper(m_rcEnc);
- queryAndSetSyncImpl(m_rcEnc);
- queryAndSetDmaImpl(m_rcEnc);
- queryAndSetGLESMaxVersion(m_rcEnc);
- queryAndSetNoErrorState(m_rcEnc);
- queryAndSetHostCompositionImpl(m_rcEnc);
- queryAndSetDirectMemSupport(m_rcEnc);
- queryAndSetVulkanSupport(m_rcEnc);
- queryAndSetDeferredVulkanCommandsSupport(m_rcEnc);
- queryAndSetVulkanNullOptionalStringsSupport(m_rcEnc);
- queryAndSetVulkanCreateResourcesWithRequirementsSupport(m_rcEnc);
- queryAndSetVulkanIgnoredHandles(m_rcEnc);
- queryAndSetYUVCache(m_rcEnc);
- queryAndSetAsyncUnmapBuffer(m_rcEnc);
- queryAndSetVirtioGpuNext(m_rcEnc);
- queryHasSharedSlotsHostMemoryAllocator(m_rcEnc);
- queryAndSetVulkanFreeMemorySync(m_rcEnc);
- queryAndSetVirtioGpuNativeSync(m_rcEnc);
- queryAndSetVulkanShaderFloat16Int8Support(m_rcEnc);
+ m_rcEnc = std::make_unique<ExtendedRCEncoderContext>(m_stream.get(),
+ checksumHelper());
+
+ ExtendedRCEncoderContext* rcEnc = m_rcEnc.get();
+ setChecksumHelper(rcEnc);
+ queryAndSetSyncImpl(rcEnc);
+ queryAndSetDmaImpl(rcEnc);
+ queryAndSetGLESMaxVersion(rcEnc);
+ queryAndSetNoErrorState(rcEnc);
+ queryAndSetHostCompositionImpl(rcEnc);
+ queryAndSetDirectMemSupport(rcEnc);
+ queryAndSetVulkanSupport(rcEnc);
+ queryAndSetDeferredVulkanCommandsSupport(rcEnc);
+ queryAndSetVulkanNullOptionalStringsSupport(rcEnc);
+ queryAndSetVulkanCreateResourcesWithRequirementsSupport(rcEnc);
+ queryAndSetVulkanIgnoredHandles(rcEnc);
+ queryAndSetYUVCache(rcEnc);
+ queryAndSetAsyncUnmapBuffer(rcEnc);
+ queryAndSetVirtioGpuNext(rcEnc);
+ queryHasSharedSlotsHostMemoryAllocator(rcEnc);
+ queryAndSetVulkanFreeMemorySync(rcEnc);
+ queryAndSetVirtioGpuNativeSync(rcEnc);
+ queryAndSetVulkanShaderFloat16Int8Support(rcEnc);
if (m_processPipe) {
- m_processPipe->processPipeInit(m_connectionType, m_rcEnc);
+ m_processPipe->processPipeInit(m_connectionType, rcEnc);
}
}
- return m_rcEnc;
+ return m_rcEnc.get();
}
int HostConnection::getOrCreateRendernodeFd() {
@@ -699,7 +671,7 @@ gl_client_context_t *HostConnection::s_getGLContext()
{
EGLThreadInfo *ti = getEGLThreadInfo();
if (ti->hostConn) {
- return ti->hostConn->m_glEnc;
+ return ti->hostConn->m_glEnc.get();
}
return NULL;
}
@@ -708,7 +680,7 @@ gl2_client_context_t *HostConnection::s_getGL2Context()
{
EGLThreadInfo *ti = getEGLThreadInfo();
if (ti->hostConn) {
- return ti->hostConn->m_gl2Enc;
+ return ti->hostConn->m_gl2Enc.get();
}
return NULL;
}
diff --git a/system/OpenglSystemCommon/HostConnection.h b/system/OpenglSystemCommon/HostConnection.h
index 3b4772a5..4ccd5a77 100644
--- a/system/OpenglSystemCommon/HostConnection.h
+++ b/system/OpenglSystemCommon/HostConnection.h
@@ -30,6 +30,7 @@
#include <utils/threads.h>
#endif
+#include <memory>
#include <string>
class GLEncoder;
@@ -140,8 +141,8 @@ public:
static HostConnection *getWithThreadInfo(EGLThreadInfo* tInfo);
static void exit();
- static HostConnection *createUnique();
- static void teardownUnique(HostConnection* con);
+ static std::unique_ptr<HostConnection> createUnique();
+ HostConnection(const HostConnection&) = delete;
~HostConnection();
@@ -187,7 +188,7 @@ public:
private:
// If the connection failed, |conn| is deleted.
// Returns NULL if connection failed.
- static HostConnection* connect(HostConnection* con);
+ static std::unique_ptr<HostConnection> connect();
HostConnection();
static gl_client_context_t *s_getGLContext();
@@ -219,14 +220,16 @@ private:
private:
HostConnectionType m_connectionType;
GrallocType m_grallocType;
- IOStream *m_stream;
- GLEncoder *m_glEnc;
- GL2Encoder *m_gl2Enc;
- goldfish_vk::VkEncoder *m_vkEnc;
- ExtendedRCEncoderContext *m_rcEnc;
+
+ std::unique_ptr<IOStream> m_stream;
+ std::unique_ptr<GLEncoder> m_glEnc;
+ std::unique_ptr<GL2Encoder> m_gl2Enc;
+ std::unique_ptr<goldfish_vk::VkEncoder> m_vkEnc;
+ std::unique_ptr<ExtendedRCEncoderContext> m_rcEnc;
+
ChecksumCalculator m_checksumHelper;
- Gralloc *m_grallocHelper;
- ProcessPipe *m_processPipe;
+ Gralloc* m_grallocHelper = nullptr;
+ ProcessPipe* m_processPipe = nullptr;
std::string m_glExtensions;
bool m_grallocOnly;
bool m_noHostError;
diff --git a/system/OpenglSystemCommon/ThreadInfo.cpp b/system/OpenglSystemCommon/ThreadInfo.cpp
index fea6cb73..99b0b9b5 100644
--- a/system/OpenglSystemCommon/ThreadInfo.cpp
+++ b/system/OpenglSystemCommon/ThreadInfo.cpp
@@ -45,7 +45,6 @@ static void tlsDestruct(void *ptr)
#endif
) {
EGLThreadInfo *ti = (EGLThreadInfo *)ptr;
- delete ti->hostConn;
delete ti;
#ifdef __ANDROID__
((void **)__get_tls())[TLS_SLOT_OPENGL] = NULL;
diff --git a/system/OpenglSystemCommon/ThreadInfo.h b/system/OpenglSystemCommon/ThreadInfo.h
index 7d2260a2..fa6b44bc 100644
--- a/system/OpenglSystemCommon/ThreadInfo.h
+++ b/system/OpenglSystemCommon/ThreadInfo.h
@@ -24,10 +24,10 @@ struct EGLContext_t;
struct EGLThreadInfo
{
- EGLThreadInfo() : currentContext(NULL), hostConn(NULL), eglError(EGL_SUCCESS) { }
+ EGLThreadInfo() : currentContext(NULL), eglError(EGL_SUCCESS) {}
EGLContext_t *currentContext;
- HostConnection *hostConn;
+ std::unique_ptr<HostConnection> hostConn;
int eglError;
};
diff --git a/system/gralloc/gralloc_30.cpp b/system/gralloc/gralloc_30.cpp
index b67f4c57..c012908e 100644
--- a/system/gralloc/gralloc_30.cpp
+++ b/system/gralloc/gralloc_30.cpp
@@ -149,7 +149,9 @@ std::unique_ptr<buffer_manager_t> create_buffer_manager(goldfish_gralloc30_modul
class goldfish_gralloc30_module_t {
public:
- goldfish_gralloc30_module_t(): m_hostConn(HostConnection::createUnique()) {
+ // TODO(b/142677230): Use unique pointers instead.
+ goldfish_gralloc30_module_t()
+ : m_hostConn(HostConnection::createUnique().release()) {
CRASH_IF(!m_hostConn, "m_hostConn cannot be nullptr");
m_bufferManager = create_buffer_manager(this);
CRASH_IF(!m_bufferManager, "m_bufferManager cannot be nullptr");
diff --git a/system/gralloc/gralloc_old.cpp b/system/gralloc/gralloc_old.cpp
index 7af9dfe9..40f6b6c5 100644
--- a/system/gralloc/gralloc_old.cpp
+++ b/system/gralloc/gralloc_old.cpp
@@ -446,7 +446,7 @@ static HostConnection* sHostCon = NULL;
static HostConnection* createOrGetHostConnection() {
if (!sHostCon) {
- sHostCon = HostConnection::createUnique();
+ sHostCon = HostConnection::createUnique().release();
}
return sHostCon;
}
diff --git a/system/hwc2/EmuHWC2.cpp b/system/hwc2/EmuHWC2.cpp
index e77e27df..7cdbd60d 100644
--- a/system/hwc2/EmuHWC2.cpp
+++ b/system/hwc2/EmuHWC2.cpp
@@ -47,13 +47,13 @@ static hwc2_function_pointer_t asFP(T function)
return reinterpret_cast<hwc2_function_pointer_t>(function);
}
-static HostConnection *sHostCon = nullptr;
+static std::unique_ptr<HostConnection> sHostCon;
static HostConnection* createOrGetHostConnection() {
if (!sHostCon) {
sHostCon = HostConnection::createUnique();
}
- return sHostCon;
+ return sHostCon.get();
}
#define DEFINE_AND_VALIDATE_HOST_CONNECTION \
diff --git a/system/vulkan_enc/VkEncoder.cpp b/system/vulkan_enc/VkEncoder.cpp
index 9fdbe842..8a76c927 100644
--- a/system/vulkan_enc/VkEncoder.cpp
+++ b/system/vulkan_enc/VkEncoder.cpp
@@ -121,6 +121,8 @@ private:
VkEncoder::VkEncoder(IOStream *stream) :
mImpl(new VkEncoder::Impl(stream)) { }
+VkEncoder::~VkEncoder() = default;
+
void VkEncoder::flush() {
mImpl->flush();
}