Android-x86
Fork

  • R/O
  • HTTP
  • SSH
  • HTTPS

device-generic-goldfish-opengl: コミット

device/generic/goldfish-opengl


コミットメタ情報

リビジョンdcacca1449afecd0604a16c8dc97e2a67c47ce56 (tree)
日時2017-06-24 05:45:05
作者bohu <bohu@goog...>
コミッターandroid-build-team Robot

ログメッセージ

Emulator: update opengl to bb8d138b

Bug: 37302997

Test: Build and run sdk_google_aw_x86-userdebug emulator

To commit
bb8d138b3e83567d68810d059d69654fa5e8a303
Merge: 7c53152 bb1f88a
Author: Josh Gao <jmgao@google.com>
Date: Fri Apr 14 23:08:26 2017 +0000
Rename socket_loopback_server to _socket_loopback_server.

Change-Id: Id602f0c1df3be423e37af5f6c91d037d713c3b7a
(cherry picked from commit 588c0a94e384e07c8d38185710a1a968823594ba)
(cherry picked from commit 1b5d5a70fe49f2826a225878ddcd8d6ad561c886)

変更サマリ

差分

--- a/shared/OpenglCodecCommon/TcpStream.cpp
+++ b/shared/OpenglCodecCommon/TcpStream.cpp
@@ -28,6 +28,38 @@
2828 #include <ws2tcpip.h>
2929 #endif
3030
31+static int _socket_loopback_server(int port, int type)
32+{
33+ struct sockaddr_in addr;
34+
35+ memset(&addr, 0, sizeof(addr));
36+ addr.sin_family = AF_INET;
37+ addr.sin_port = htons(port);
38+ addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
39+
40+
41+ int s = socket(AF_INET, type, 0);
42+ if (s < 0)
43+ return -1;
44+
45+ int n = 1;
46+ setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *) &n, sizeof(n));
47+
48+ if (bind(s, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) < 0) {
49+ close(s);
50+ return -1;
51+ }
52+
53+ if (type == SOCK_STREAM) {
54+ if (listen(s, 4) < 0) {
55+ close(s);
56+ return -1;
57+ }
58+ }
59+
60+ return s;
61+}
62+
3163 TcpStream::TcpStream(size_t bufSize) :
3264 SocketStream(bufSize)
3365 {
@@ -49,7 +81,7 @@ TcpStream::TcpStream(int sock, size_t bufSize) :
4981
5082 int TcpStream::listen(unsigned short port)
5183 {
52- m_sock = socket_loopback_server(port, SOCK_STREAM);
84+ m_sock = _socket_loopback_server(port, SOCK_STREAM);
5385 if (!valid()) return int(ERR_INVALID_SOCKET);
5486
5587 return 0;
--- a/system/OpenglSystemCommon/HostConnection.cpp
+++ b/system/OpenglSystemCommon/HostConnection.cpp
@@ -50,12 +50,15 @@ HostConnection::~HostConnection()
5050 }
5151
5252 HostConnection *HostConnection::get() {
53+ return getWithThreadInfo(getEGLThreadInfo());
54+}
55+
56+HostConnection *HostConnection::getWithThreadInfo(EGLThreadInfo* tinfo) {
5357
5458 /* TODO: Make this configurable with a system property */
5559 const int useQemuPipe = USE_QEMU_PIPE;
5660
5761 // Get thread info
58- EGLThreadInfo *tinfo = getEGLThreadInfo();
5962 if (!tinfo) {
6063 return NULL;
6164 }
--- a/system/OpenglSystemCommon/HostConnection.h
+++ b/system/OpenglSystemCommon/HostConnection.h
@@ -107,10 +107,13 @@ private:
107107 GLESMaxVersion m_glesMaxVersion;
108108 };
109109
110+struct EGLThreadInfo;
111+
110112 class HostConnection
111113 {
112114 public:
113115 static HostConnection *get();
116+ static HostConnection *getWithThreadInfo(EGLThreadInfo* tInfo);
114117 static void exit();
115118 ~HostConnection();
116119
--- a/system/OpenglSystemCommon/ThreadInfo.cpp
+++ b/system/OpenglSystemCommon/ThreadInfo.cpp
@@ -18,19 +18,30 @@
1818
1919 thread_store_t s_tls = THREAD_STORE_INITIALIZER;
2020
21+static bool sDefaultTlsDestructorCallback(void* ptr) { return true; }
22+static bool (*sTlsDestructorCallback)(void*) = sDefaultTlsDestructorCallback;
23+
2124 static void tlsDestruct(void *ptr)
2225 {
26+ sTlsDestructorCallback(ptr);
2327 if (ptr) {
2428 EGLThreadInfo *ti = (EGLThreadInfo *)ptr;
2529 delete ti->hostConn;
2630 delete ti;
31+#ifdef __ANDROID__
2732 ((void **)__get_tls())[TLS_SLOT_OPENGL] = NULL;
33+#endif
2834 }
2935 }
3036
31-EGLThreadInfo *slow_getEGLThreadInfo()
37+void setTlsDestructor(tlsDtorCallback func) {
38+ sTlsDestructorCallback = func;
39+}
40+
41+EGLThreadInfo *goldfish_get_egl_tls()
3242 {
33- EGLThreadInfo *ti = (EGLThreadInfo *)thread_store_get(&s_tls);
43+ EGLThreadInfo* ti = (EGLThreadInfo*)thread_store_get(&s_tls);
44+
3445 if (ti) return ti;
3546
3647 ti = new EGLThreadInfo();
--- a/system/OpenglSystemCommon/ThreadInfo.h
+++ b/system/OpenglSystemCommon/ThreadInfo.h
@@ -18,15 +18,14 @@
1818
1919 #include "HostConnection.h"
2020 #include <pthread.h>
21-#ifdef __ANDROID__
22-#include <bionic_tls.h>
23-#endif
2421
22+#include <bionic_tls.h>
2523 struct EGLContext_t;
24+struct HostConnection;
2625
2726 struct EGLThreadInfo
2827 {
29- EGLThreadInfo() : currentContext(NULL), hostConn(NULL), eglError(EGL_SUCCESS) {}
28+ EGLThreadInfo() : currentContext(NULL), hostConn(NULL), eglError(EGL_SUCCESS) { }
3029
3130 EGLContext_t *currentContext;
3231 HostConnection *hostConn;
@@ -34,26 +33,23 @@ struct EGLThreadInfo
3433 };
3534
3635
37-EGLThreadInfo *slow_getEGLThreadInfo();
36+typedef bool (*tlsDtorCallback)(void*);
37+void setTlsDestructor(tlsDtorCallback);
38+
39+extern "C" __attribute__((visibility("default"))) EGLThreadInfo *goldfish_get_egl_tls();
3840
41+inline EGLThreadInfo* getEGLThreadInfo() {
3942 #ifdef __ANDROID__
40- // We have a dedicated TLS slot in bionic
41- inline EGLThreadInfo* getEGLThreadInfo() {
42- EGLThreadInfo *tInfo =
43- (EGLThreadInfo *)(((uintptr_t *)__get_tls())[TLS_SLOT_OPENGL]);
44- if (!tInfo) {
45- tInfo = slow_getEGLThreadInfo();
46- ((uintptr_t *)__get_tls())[TLS_SLOT_OPENGL] = (uintptr_t)tInfo;
47- }
48- return tInfo;
43+ EGLThreadInfo *tInfo =
44+ (EGLThreadInfo *)(((uintptr_t *)__get_tls())[TLS_SLOT_OPENGL]);
45+ if (!tInfo) {
46+ tInfo = goldfish_get_egl_tls();
47+ ((uintptr_t *)__get_tls())[TLS_SLOT_OPENGL] = (uintptr_t)tInfo;
4948 }
49+ return tInfo;
5050 #else
51- inline EGLThreadInfo* getEGLThreadInfo() {
52- return slow_getEGLThreadInfo();
53- }
51+ return goldfish_get_egl_tls();
5452 #endif
55-
56-
57-
53+}
5854
5955 #endif // of _THREAD_INFO_H
--- a/system/egl/egl.cpp
+++ b/system/egl/egl.cpp
@@ -144,6 +144,18 @@ const char * eglStrError(EGLint err)
144144 return ret; \
145145 }
146146
147+#define DEFINE_AND_VALIDATE_HOST_CONNECTION_FOR_TLS(ret, tls) \
148+ HostConnection *hostCon = HostConnection::getWithThreadInfo(tls); \
149+ if (!hostCon) { \
150+ ALOGE("egl: Failed to get host connection\n"); \
151+ return ret; \
152+ } \
153+ ExtendedRCEncoderContext *rcEnc = hostCon->rcEncoder(); \
154+ if (!rcEnc) { \
155+ ALOGE("egl: Failed to get renderControl encoder context\n"); \
156+ return ret; \
157+ }
158+
147159 #define VALIDATE_CONTEXT_RETURN(context,ret) \
148160 if (!(context)) { \
149161 RETURN_ERROR(ret,EGL_BAD_CONTEXT); \
@@ -1112,41 +1124,40 @@ EGLBoolean eglWaitClient()
11121124 return eglWaitGL();
11131125 }
11141126
1115-EGLBoolean eglReleaseThread()
1116-{
1117- EGLThreadInfo *tInfo = getEGLThreadInfo();
1118- if (tInfo) {
1119- tInfo->eglError = EGL_SUCCESS;
1120- EGLContext_t* context = tInfo->currentContext;
1121- if (context) {
1122- // The following code is doing pretty much the same thing as
1123- // eglMakeCurrent(&s_display, EGL_NO_CONTEXT, EGL_NO_SURFACE, EGL_NO_SURFACE)
1124- // with the only issue that we do not require a valid display here.
1125- DEFINE_AND_VALIDATE_HOST_CONNECTION(EGL_FALSE);
1126- rcEnc->rcMakeCurrent(rcEnc, 0, 0, 0);
1127- if (context->majorVersion > 1) {
1128- hostCon->gl2Encoder()->setClientState(NULL);
1129- hostCon->gl2Encoder()->setSharedGroup(GLSharedGroupPtr());
1130- }
1131- else {
1132- hostCon->glEncoder()->setClientState(NULL);
1133- hostCon->glEncoder()->setSharedGroup(GLSharedGroupPtr());
1134- }
1135- context->flags &= ~EGLContext_t::IS_CURRENT;
1127+// We may need to trigger this directly from the TLS destructor.
1128+static EGLBoolean s_eglReleaseThreadImpl(EGLThreadInfo* tInfo) {
1129+ if (!tInfo) return EGL_TRUE;
11361130
1137- if (context->deletePending) {
1138- if (context->rcContext) {
1139- rcEnc->rcDestroyContext(rcEnc, context->rcContext);
1140- context->rcContext = 0;
1141- }
1142- delete context;
1143- }
1144- tInfo->currentContext = 0;
1131+ tInfo->eglError = EGL_SUCCESS;
1132+ EGLContext_t* context = tInfo->currentContext;
1133+
1134+ if (!context) return EGL_TRUE;
1135+
1136+ // The following code is doing pretty much the same thing as
1137+ // eglMakeCurrent(&s_display, EGL_NO_CONTEXT, EGL_NO_SURFACE, EGL_NO_SURFACE)
1138+ // with the only issue that we do not require a valid display here.
1139+ DEFINE_AND_VALIDATE_HOST_CONNECTION_FOR_TLS(EGL_FALSE, tInfo);
1140+ // We are going to call makeCurrent on the null context and surface
1141+ // anyway once we are on the host, so skip rcMakeCurrent here.
1142+ // rcEnc->rcMakeCurrent(rcEnc, 0, 0, 0);
1143+ context->flags &= ~EGLContext_t::IS_CURRENT;
1144+ if (context->deletePending) {
1145+ if (context->rcContext) {
1146+ rcEnc->rcDestroyContext(rcEnc, context->rcContext);
1147+ context->rcContext = 0;
11451148 }
1149+ delete context;
11461150 }
1151+ tInfo->currentContext = 0;
1152+
11471153 return EGL_TRUE;
11481154 }
11491155
1156+EGLBoolean eglReleaseThread()
1157+{
1158+ return s_eglReleaseThreadImpl(getEGLThreadInfo());
1159+}
1160+
11501161 EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, EGLConfig config, const EGLint *attrib_list)
11511162 {
11521163 //TODO
@@ -1464,6 +1475,10 @@ EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLC
14641475 VALIDATE_SURFACE_RETURN(draw, EGL_FALSE);
14651476 VALIDATE_SURFACE_RETURN(read, EGL_FALSE);
14661477
1478+ // Only place to initialize the TLS destructor; any
1479+ // thread can suddenly jump in any eglMakeCurrent
1480+ setTlsDestructor((tlsDtorCallback)s_eglReleaseThreadImpl);
1481+
14671482 if ((read == EGL_NO_SURFACE && draw == EGL_NO_SURFACE) && (ctx != EGL_NO_CONTEXT))
14681483 setErrorReturn(EGL_BAD_MATCH, EGL_FALSE);
14691484 if ((read != EGL_NO_SURFACE || draw != EGL_NO_SURFACE) && (ctx == EGL_NO_CONTEXT))
@@ -1496,7 +1511,8 @@ EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLC
14961511 }
14971512
14981513 if (context && (context->flags & EGLContext_t::IS_CURRENT) && (context != tInfo->currentContext)) {
1499- //context is current to another thread
1514+ // context is current to another thread
1515+ ALOGE("%s: error: EGL_BAD_ACCESS: context %p current to another thread!\n", __FUNCTION__, context);
15001516 setErrorReturn(EGL_BAD_ACCESS, EGL_FALSE);
15011517 }
15021518
@@ -1509,7 +1525,7 @@ EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLC
15091525 //Now make the local bind
15101526 if (context) {
15111527
1512- ALOGD("%s: %p: ver %d %d", __FUNCTION__, context, context->majorVersion, context->minorVersion);
1528+ ALOGD("%s: %p: ver %d %d (tinfo %p)", __FUNCTION__, context, context->majorVersion, context->minorVersion, tInfo);
15131529 // This is a nontrivial context.
15141530 // The thread cannot be gralloc-only anymore.
15151531 hostCon->setGrallocOnly(false);
--- a/system/egl/eglDisplay.cpp
+++ b/system/egl/eglDisplay.cpp
@@ -430,6 +430,9 @@ EGLBoolean eglDisplay::getAttribValue(EGLConfig config, EGLint attribIdx, EGLint
430430 return EGL_TRUE;
431431 }
432432
433+#define EGL_COLOR_COMPONENT_TYPE_EXT 0x3339
434+#define EGL_COLOR_COMPONENT_TYPE_FIXED_EXT 0x333A
435+
433436 EGLBoolean eglDisplay::getConfigAttrib(EGLConfig config, EGLint attrib, EGLint * value)
434437 {
435438 if (attrib == EGL_FRAMEBUFFER_TARGET_ANDROID) {
@@ -445,6 +448,10 @@ EGLBoolean eglDisplay::getConfigAttrib(EGLConfig config, EGLint attrib, EGLint *
445448 *value = EGL_DEPTH_ENCODING_NONE_NV;
446449 return EGL_TRUE;
447450 }
451+ if (attrib == EGL_COLOR_COMPONENT_TYPE_EXT) {
452+ *value = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
453+ return EGL_TRUE;
454+ }
448455 //Though it seems that valueFor() is thread-safe, we don't take chanses
449456 pthread_mutex_lock(&m_lock);
450457 EGLBoolean ret = getAttribValue(config, m_attribs.valueFor(attrib), value);
--- a/system/gralloc/gralloc.cpp
+++ b/system/gralloc/gralloc.cpp
@@ -30,6 +30,10 @@
3030 #include <cutils/log.h>
3131 #include <cutils/properties.h>
3232
33+#include <set>
34+#include <string>
35+#include <sstream>
36+
3337 /* Set to 1 or 2 to enable debug traces */
3438 #define DEBUG 0
3539
@@ -63,13 +67,26 @@ static pthread_once_t sFallbackOnce = PTHREAD_ONCE_INIT;
6367
6468 static void fallback_init(void); // forward
6569
66-
6770 typedef struct _alloc_list_node {
6871 buffer_handle_t handle;
6972 _alloc_list_node *next;
7073 _alloc_list_node *prev;
7174 } AllocListNode;
7275
76+struct MemRegionInfo {
77+ void* ashmemBase;
78+ mutable uint32_t refCount;
79+};
80+
81+struct MemRegionInfoCmp {
82+ bool operator()(const MemRegionInfo& a, const MemRegionInfo& b) const {
83+ return a.ashmemBase < b.ashmemBase;
84+ }
85+};
86+
87+typedef std::set<MemRegionInfo, MemRegionInfoCmp> MemRegionSet;
88+typedef MemRegionSet::iterator mem_region_handle_t;
89+
7390 //
7491 // Our gralloc device structure (alloc interface)
7592 //
@@ -77,9 +94,161 @@ struct gralloc_device_t {
7794 alloc_device_t device;
7895
7996 AllocListNode *allocListHead; // double linked list of allocated buffers
97+ MemRegionSet ashmemRegions; // to track allocations of each ashmem region
8098 pthread_mutex_t lock;
8199 };
82100
101+struct gralloc_memregions_t {
102+ MemRegionSet ashmemRegions;
103+};
104+
105+#define INITIAL_DMA_REGION_SIZE 4096
106+struct gralloc_dmaregion_t {
107+ goldfish_dma_context goldfish_dma;
108+ uint32_t sz;
109+ uint32_t refcount;
110+ pthread_mutex_t lock;
111+};
112+
113+// global device instance
114+static gralloc_memregions_t* s_grdev = NULL;
115+static gralloc_dmaregion_t* s_grdma = NULL;
116+
117+void init_gralloc_memregions() {
118+ if (s_grdev) return;
119+ s_grdev = new gralloc_memregions_t;
120+}
121+
122+void init_gralloc_dmaregion() {
123+ D("%s: call\n", __FUNCTION__);
124+ if (s_grdma) return;
125+
126+ s_grdma = new gralloc_dmaregion_t;
127+ s_grdma->sz = INITIAL_DMA_REGION_SIZE;
128+ s_grdma->refcount = 0;
129+
130+ pthread_mutex_init(&s_grdma->lock, NULL);
131+ pthread_mutex_lock(&s_grdma->lock);
132+ goldfish_dma_create_region(s_grdma->sz, &s_grdma->goldfish_dma);
133+ pthread_mutex_unlock(&s_grdma->lock);
134+}
135+
136+void get_gralloc_dmaregion() {
137+ if (!s_grdma) return;
138+ pthread_mutex_lock(&s_grdma->lock);
139+ s_grdma->refcount++;
140+ D("%s: call. refcount: %u\n", __FUNCTION__, s_grdma->refcount);
141+ pthread_mutex_unlock(&s_grdma->lock);
142+}
143+
144+static void resize_gralloc_dmaregion_locked(uint32_t new_sz) {
145+ if (!s_grdma) return;
146+ if (s_grdma->goldfish_dma.mapped) {
147+ goldfish_dma_unmap(&s_grdma->goldfish_dma);
148+ }
149+ close(s_grdma->goldfish_dma.fd);
150+ goldfish_dma_create_region(new_sz, &s_grdma->goldfish_dma);
151+ s_grdma->sz = new_sz;
152+}
153+
154+bool put_gralloc_dmaregion() {
155+ if (!s_grdma) return false;
156+ pthread_mutex_lock(&s_grdma->lock);
157+ D("%s: call. refcount before: %u\n", __FUNCTION__, s_grdma->refcount);
158+ s_grdma->refcount--;
159+ bool shouldDelete = !s_grdma->refcount;
160+ if (shouldDelete) {
161+ D("%s: should delete!\n", __FUNCTION__);
162+ resize_gralloc_dmaregion_locked(INITIAL_DMA_REGION_SIZE);
163+ D("%s: done\n", __FUNCTION__);
164+ }
165+ pthread_mutex_unlock(&s_grdma->lock);
166+ D("%s: exit\n", __FUNCTION__);
167+ return shouldDelete;
168+}
169+
170+void gralloc_dmaregion_register_ashmem(uint32_t sz) {
171+ if (!s_grdma) return;
172+ pthread_mutex_lock(&s_grdma->lock);
173+ D("%s: for sz %u, refcount %u", __FUNCTION__, sz, s_grdma->refcount);
174+ uint32_t new_sz = std::max(s_grdma->sz, sz);
175+ if (new_sz != s_grdma->sz) {
176+ D("%s: change sz from %u to %u", __FUNCTION__, s_grdma->sz, sz);
177+ resize_gralloc_dmaregion_locked(new_sz);
178+ }
179+ if (!s_grdma->goldfish_dma.mapped) {
180+ goldfish_dma_map(&s_grdma->goldfish_dma);
181+ }
182+ pthread_mutex_unlock(&s_grdma->lock);
183+}
184+
185+void get_mem_region(void* ashmemBase) {
186+ init_gralloc_memregions();
187+ D("%s: call for %p", __FUNCTION__, ashmemBase);
188+ MemRegionInfo lookup;
189+ lookup.ashmemBase = ashmemBase;
190+ mem_region_handle_t handle = s_grdev->ashmemRegions.find(lookup);
191+ if (handle == s_grdev->ashmemRegions.end()) {
192+ MemRegionInfo newRegion;
193+ newRegion.ashmemBase = ashmemBase;
194+ newRegion.refCount = 1;
195+ s_grdev->ashmemRegions.insert(newRegion);
196+ } else {
197+ handle->refCount++;
198+ }
199+}
200+
201+bool put_mem_region(void* ashmemBase) {
202+ init_gralloc_memregions();
203+ D("%s: call for %p", __FUNCTION__, ashmemBase);
204+ MemRegionInfo lookup;
205+ lookup.ashmemBase = ashmemBase;
206+ mem_region_handle_t handle = s_grdev->ashmemRegions.find(lookup);
207+ if (handle == s_grdev->ashmemRegions.end()) {
208+ ALOGE("%s: error: tried to put nonexistent mem region!", __FUNCTION__);
209+ return true;
210+ } else {
211+ handle->refCount--;
212+ bool shouldRemove = !handle->refCount;
213+ if (shouldRemove) {
214+ s_grdev->ashmemRegions.erase(lookup);
215+ }
216+ return shouldRemove;
217+ }
218+}
219+
220+void dump_regions() {
221+ init_gralloc_memregions();
222+ mem_region_handle_t curr = s_grdev->ashmemRegions.begin();
223+ std::stringstream res;
224+ for (; curr != s_grdev->ashmemRegions.end(); curr++) {
225+ res << "\tashmem base " << curr->ashmemBase << " refcount " << curr->refCount << "\n";
226+ }
227+ ALOGD("ashmem region dump [\n%s]", res.str().c_str());
228+}
229+
230+#if DEBUG
231+
232+#define GET_ASHMEM_REGION(cb) \
233+ dump_regions(); \
234+ get_mem_region((void*)cb->ashmemBase); \
235+ dump_regions(); \
236+
237+#define PUT_ASHMEM_REGION(cb) \
238+ dump_regions(); \
239+ bool SHOULD_UNMAP = put_mem_region((void*)cb->ashmemBase); \
240+ dump_regions(); \
241+
242+#else
243+
244+#define GET_ASHMEM_REGION(cb) \
245+ get_mem_region((void*)cb->ashmemBase); \
246+
247+#define PUT_ASHMEM_REGION(cb) \
248+ bool SHOULD_UNMAP = put_mem_region((void*)cb->ashmemBase); \
249+
250+#endif
251+
83252 //
84253 // Our framebuffer device structure
85254 //
@@ -102,6 +271,8 @@ static int map_buffer(cb_handle_t *cb, void **vaddr)
102271
103272 cb->ashmemBase = intptr_t(addr);
104273 cb->ashmemBasePid = getpid();
274+ D("%s: %p mapped ashmem base %p size %d\n", __FUNCTION__,
275+ cb, cb->ashmemBase, cb->ashmemSize);
105276
106277 *vaddr = addr;
107278 return 0;
@@ -148,7 +319,7 @@ static void updateHostColorBuffer(cb_handle_t* cb,
148319
149320 char* convertedBuf = NULL;
150321 if ((doLocked && is_rgb_format) ||
151- (cb->goldfish_dma.fd < 0 &&
322+ (!s_grdma &&
152323 (doLocked || !is_rgb_format))) {
153324 convertedBuf = new char[rgbSz];
154325 to_send = convertedBuf;
@@ -162,7 +333,7 @@ static void updateHostColorBuffer(cb_handle_t* cb,
162333 width, height, top, left, bpp);
163334 }
164335
165- if (cb->goldfish_dma.fd > 0) {
336+ if (s_grdma) {
166337 if (cb->frameworkFormat == HAL_PIXEL_FORMAT_YV12) {
167338 get_yv12_offsets(width, height, NULL, NULL,
168339 &send_buffer_size);
@@ -172,12 +343,14 @@ static void updateHostColorBuffer(cb_handle_t* cb,
172343 &send_buffer_size);
173344 }
174345
175- rcEnc->bindDmaContext(&cb->goldfish_dma);
346+ rcEnc->bindDmaContext(&s_grdma->goldfish_dma);
176347 D("%s: call. dma update with sz=%u", __FUNCTION__, send_buffer_size);
348+ pthread_mutex_lock(&s_grdma->lock);
177349 rcEnc->rcUpdateColorBufferDMA(rcEnc, cb->hostHandle,
178350 left, top, width, height,
179351 cb->glFormat, cb->glType,
180352 to_send, send_buffer_size);
353+ pthread_mutex_unlock(&s_grdma->lock);
181354 } else {
182355 if (cb->frameworkFormat == HAL_PIXEL_FORMAT_YV12) {
183356 yv12_to_rgb888(to_send, pixels,
@@ -340,8 +513,6 @@ static int gralloc_alloc(alloc_device_t* dev,
340513 selectedEmuFrameworkFormat = FRAMEWORK_FORMAT_YV12;
341514 break;
342515 case HAL_PIXEL_FORMAT_YCbCr_420_888:
343- ALOGD("%s: 420_888 format experimental path. "
344- "Initialize rgb565 gl format\n", __FUNCTION__);
345516 align = 1;
346517 bpp = 1; // per-channel bpp
347518 yuv_format = true;
@@ -418,14 +589,8 @@ static int gralloc_alloc(alloc_device_t* dev,
418589
419590 if (rcEnc->getDmaVersion() > 0) {
420591 D("%s: creating goldfish dma region of size %lu (cb fd %d)\n", __FUNCTION__, ashmem_size, cb->fd);
421- err = goldfish_dma_create_region(ashmem_size, &cb->goldfish_dma);
422- if (err) {
423- ALOGE("%s: Failed to create goldfish DMA region", __FUNCTION__);
424- } else {
425- goldfish_dma_map(&cb->goldfish_dma);
426- cb->setDmaFd(cb->goldfish_dma.fd);
427- D("%s: done, cbfd %d dmafd1 %d dmafd2 %d", __FUNCTION__, cb->fd, cb->goldfish_dma.fd, cb->dmafd);
428- }
592+ init_gralloc_dmaregion();
593+ get_gralloc_dmaregion();
429594 } else {
430595 cb->goldfish_dma.fd = -1;
431596 }
@@ -454,7 +619,7 @@ static int gralloc_alloc(alloc_device_t* dev,
454619 GRALLOC_USAGE_HW_FB | GRALLOC_USAGE_SW_READ_MASK) ) {
455620 #endif // PLATFORM_SDK_VERSION
456621 if (hostCon && rcEnc) {
457- if (cb->goldfish_dma.fd > 0) {
622+ if (s_grdma) {
458623 cb->hostHandle = rcEnc->rcCreateColorBufferDMA(rcEnc, w, h, glFormat, cb->emuFrameworkFormat);
459624 } else {
460625 cb->hostHandle = rcEnc->rcCreateColorBuffer(rcEnc, w, h, glFormat);
@@ -487,6 +652,8 @@ static int gralloc_alloc(alloc_device_t* dev,
487652 pthread_mutex_unlock(&grdev->lock);
488653
489654 *pHandle = cb;
655+ D("%s: alloc succeded, new ashmem base and size: %p %d handle: %p",
656+ __FUNCTION__, cb->ashmemBase, cb->ashmemSize, cb);
490657 switch (frameworkFormat) {
491658 case HAL_PIXEL_FORMAT_YCbCr_420_888:
492659 *pStride = 0;
@@ -501,14 +668,16 @@ static int gralloc_alloc(alloc_device_t* dev,
501668 static int gralloc_free(alloc_device_t* dev,
502669 buffer_handle_t handle)
503670 {
504- D("%s: start", __FUNCTION__);
505671 cb_handle_t *cb = (cb_handle_t *)handle;
506672 if (!cb_handle_t::validate((cb_handle_t*)cb)) {
507673 ERR("gralloc_free: invalid handle");
508674 return -EINVAL;
509675 }
510676
511- if (cb->hostHandle != 0) {
677+ D("%s: for buf %p ptr %p size %d\n",
678+ __FUNCTION__, handle, cb->ashmemBase, cb->ashmemSize);
679+
680+ if (cb->hostHandle) {
512681 DEFINE_AND_VALIDATE_HOST_CONNECTION;
513682 D("Closing host ColorBuffer 0x%x\n", cb->hostHandle);
514683 rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle);
@@ -519,19 +688,12 @@ static int gralloc_free(alloc_device_t* dev,
519688 //
520689 if (cb->fd > 0) {
521690 if (cb->ashmemSize > 0 && cb->ashmemBase) {
691+ D("%s: unmapped %p", __FUNCTION__, cb->ashmemBase);
522692 munmap((void *)cb->ashmemBase, cb->ashmemSize);
693+ put_gralloc_dmaregion();
523694 }
524695 close(cb->fd);
525696 }
526- if (cb->dmafd > 0) {
527- D("%s: unmap and free dma fd %d\n", __FUNCTION__, cb->dmafd);
528- cb->goldfish_dma.fd = cb->dmafd;
529- if (cb->ashmemSize > 0 && cb->ashmemBase) {
530- goldfish_dma_unmap(&cb->goldfish_dma);
531- }
532- goldfish_dma_free(&cb->goldfish_dma);
533- D("%s: closed dma fd %d\n", __FUNCTION__, cb->dmafd);
534- }
535697
536698 D("%s: done", __FUNCTION__);
537699 // remove it from the allocated list
@@ -675,6 +837,7 @@ static int fb_close(struct hw_device_t *dev)
675837 static int gralloc_register_buffer(gralloc_module_t const* module,
676838 buffer_handle_t handle)
677839 {
840+
678841 D("%s: start", __FUNCTION__);
679842 pthread_once(&sFallbackOnce, fallback_init);
680843 if (sFallback != NULL) {
@@ -685,6 +848,7 @@ static int gralloc_register_buffer(gralloc_module_t const* module,
685848
686849 private_module_t *gr = (private_module_t *)module;
687850 cb_handle_t *cb = (cb_handle_t *)handle;
851+
688852 if (!gr || !cb_handle_t::validate(cb)) {
689853 ERR("gralloc_register_buffer(%p): invalid buffer", cb);
690854 return -EINVAL;
@@ -708,18 +872,18 @@ static int gralloc_register_buffer(gralloc_module_t const* module,
708872 return -err;
709873 }
710874 cb->mappedPid = getpid();
711- D("%s: checking to map goldfish dma", __FUNCTION__);
712- if (cb->dmafd > 0) {
713- D("%s: attempting to goldfish dma mmap. cbfd %d dmafd1 %d dmafd2 %d", __FUNCTION__, cb->fd, cb->goldfish_dma.fd, cb->dmafd);
714- D("cxt=%p curr pid %d mapped pid %d",
715- &cb->goldfish_dma,
716- (int)getpid(),
717- cb->mappedPid);
718- if (cb->goldfish_dma.fd != cb->dmafd) {
719- cb->goldfish_dma.fd = cb->dmafd;
720- }
721- goldfish_dma_map(&cb->goldfish_dma);
875+
876+ DEFINE_AND_VALIDATE_HOST_CONNECTION;
877+ if (rcEnc->getDmaVersion() > 0) {
878+ init_gralloc_dmaregion();
879+ gralloc_dmaregion_register_ashmem(cb->ashmemSize);
722880 }
881+
882+ }
883+
884+ if (cb->ashmemSize > 0) {
885+ GET_ASHMEM_REGION(cb);
886+ get_gralloc_dmaregion();
723887 }
724888
725889 return 0;
@@ -728,21 +892,22 @@ static int gralloc_register_buffer(gralloc_module_t const* module,
728892 static int gralloc_unregister_buffer(gralloc_module_t const* module,
729893 buffer_handle_t handle)
730894 {
731- D("%s: call", __FUNCTION__);
732895 if (sFallback != NULL) {
733896 return sFallback->unregisterBuffer(sFallback, handle);
734897 }
735898
736899 private_module_t *gr = (private_module_t *)module;
737900 cb_handle_t *cb = (cb_handle_t *)handle;
901+
738902 if (!gr || !cb_handle_t::validate(cb)) {
739903 ERR("gralloc_unregister_buffer(%p): invalid buffer", cb);
740904 return -EINVAL;
741905 }
742906
743- if (cb->hostHandle != 0) {
744- DEFINE_AND_VALIDATE_HOST_CONNECTION;
907+
908+ if (cb->hostHandle) {
745909 D("Closing host ColorBuffer 0x%x\n", cb->hostHandle);
910+ DEFINE_AND_VALIDATE_HOST_CONNECTION;
746911 rcEnc->rcCloseColorBuffer(rcEnc, cb->hostHandle);
747912 }
748913
@@ -751,7 +916,14 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module,
751916 // (through register_buffer)
752917 //
753918 if (cb->ashmemSize > 0 && cb->mappedPid == getpid()) {
919+
920+ PUT_ASHMEM_REGION(cb);
921+ put_gralloc_dmaregion();
922+
923+ if (!SHOULD_UNMAP) goto done;
924+
754925 DEFINE_AND_VALIDATE_HOST_CONNECTION;
926+
755927 void *vaddr;
756928 int err = munmap((void *)cb->ashmemBase, cb->ashmemSize);
757929 if (err) {
@@ -761,14 +933,9 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module,
761933 cb->ashmemBase = 0;
762934 cb->mappedPid = 0;
763935 D("%s: Unregister buffer previous mapped to pid %d", __FUNCTION__, getpid());
764- if (cb->dmafd > 0) {
765- cb->goldfish_dma.fd = cb->dmafd;
766- D("%s: Unmap dma fd %d (%d)", __FUNCTION__, cb->dmafd, cb->goldfish_dma.fd);
767- goldfish_dma_unmap(&cb->goldfish_dma);
768- }
769936 }
770937
771-
938+done:
772939 D("gralloc_unregister_buffer(%p) done\n", cb);
773940 return 0;
774941 }
@@ -786,6 +953,7 @@ static int gralloc_lock(gralloc_module_t const* module,
786953
787954 private_module_t *gr = (private_module_t *)module;
788955 cb_handle_t *cb = (cb_handle_t *)handle;
956+
789957 if (!gr || !cb_handle_t::validate(cb)) {
790958 ALOGE("gralloc_lock bad handle\n");
791959 return -EINVAL;
@@ -883,11 +1051,12 @@ static int gralloc_lock(gralloc_module_t const* module,
8831051 char* tmpBuf = 0;
8841052 if (cb->frameworkFormat == HAL_PIXEL_FORMAT_YV12 ||
8851053 cb->frameworkFormat == HAL_PIXEL_FORMAT_YCbCr_420_888) {
886- // We are using RGB88
1054+ // We are using RGB888
8871055 tmpBuf = new char[cb->width * cb->height * 3];
8881056 rgb_addr = tmpBuf;
8891057 }
890- D("gralloc_lock read back color buffer %d %d\n", cb->width, cb->height);
1058+ D("gralloc_lock read back color buffer %d %d ashmem base %p sz %d\n",
1059+ cb->width, cb->height, cb->ashmemBase, cb->ashmemSize);
8911060 rcEnc->rcReadColorBuffer(rcEnc, cb->hostHandle,
8921061 0, 0, cb->width, cb->height, cb->glFormat, cb->glType, rgb_addr);
8931062 if (tmpBuf) {
@@ -933,6 +1102,7 @@ static int gralloc_unlock(gralloc_module_t const* module,
9331102
9341103 private_module_t *gr = (private_module_t *)module;
9351104 cb_handle_t *cb = (cb_handle_t *)handle;
1105+
9361106 if (!gr || !cb_handle_t::validate(cb)) {
9371107 ALOGD("%s: invalid gr or cb handle. -EINVAL", __FUNCTION__);
9381108 return -EINVAL;
@@ -1121,6 +1291,7 @@ static int gralloc_device_open(const hw_module_t* module,
11211291 if (NULL == dev) {
11221292 return -ENOMEM;
11231293 }
1294+ memset(dev, 0, sizeof(gralloc_device_t));
11241295
11251296 // Initialize our device structure
11261297 //
旧リポジトリブラウザで表示