Add invokeFunctor
Change-Id: I09e675d3e02e3e528642175ada00b2b17fab7652
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index 017fb56..fa82627 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -82,6 +82,8 @@
// Returns true on success, false on failure
void initialize();
+ bool hasContext();
+
void usePBufferSurface();
EGLSurface createSurface(EGLNativeWindowType window);
void destroySurface(EGLSurface surface);
@@ -138,7 +140,7 @@
}
void GlobalContext::initialize() {
- if (mEglDisplay != EGL_NO_DISPLAY) return;
+ if (hasContext()) return;
mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
LOG_ALWAYS_FATAL_IF(mEglDisplay == EGL_NO_DISPLAY,
@@ -157,6 +159,10 @@
initAtlas();
}
+bool GlobalContext::hasContext() {
+ return mEglDisplay != EGL_NO_DISPLAY;
+}
+
void GlobalContext::loadConfig() {
EGLint swapBehavior = mCanSetDirtyRegions ? EGL_SWAP_BEHAVIOR_PRESERVED_BIT : 0;
EGLint attribs[] = {
@@ -440,6 +446,15 @@
mCanvas->detachFunctor(functor);
}
+void CanvasContext::invokeFunctor(Functor* functor) {
+ DrawGlInfo::Mode mode = DrawGlInfo::kModeProcessNoContext;
+ if (mGlobalContext->hasContext()) {
+ requireGlContext();
+ mode = DrawGlInfo::kModeProcess;
+ }
+ (*functor)(mode, NULL);
+}
+
void CanvasContext::invokeFunctors() {
mInvokeFunctorsPending = false;
diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h
index 746c1bf..eb9096d 100644
--- a/libs/hwui/renderthread/CanvasContext.h
+++ b/libs/hwui/renderthread/CanvasContext.h
@@ -72,6 +72,7 @@
void attachFunctor(Functor* functor);
void detachFunctor(Functor* functor);
+ void invokeFunctor(Functor* functor);
void runWithGlContext(RenderTask* task);
diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp
index 16b93c3..cd711b0 100644
--- a/libs/hwui/renderthread/RenderProxy.cpp
+++ b/libs/hwui/renderthread/RenderProxy.cpp
@@ -167,6 +167,22 @@
post(task);
}
+CREATE_BRIDGE2(invokeFunctor, CanvasContext* context, Functor* functor) {
+ args->context->invokeFunctor(args->functor);
+ return NULL;
+}
+
+void RenderProxy::invokeFunctor(Functor* functor, bool waitForCompletion) {
+ SETUP_TASK(invokeFunctor);
+ args->context = mContext;
+ args->functor = functor;
+ if (waitForCompletion) {
+ postAndWait(task);
+ } else {
+ post(task);
+ }
+}
+
CREATE_BRIDGE2(runWithGlContext, CanvasContext* context, RenderTask* task) {
args->context->runWithGlContext(args->task);
return NULL;
diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h
index ee7a4c7..f1ca534 100644
--- a/libs/hwui/renderthread/RenderProxy.h
+++ b/libs/hwui/renderthread/RenderProxy.h
@@ -69,6 +69,7 @@
ANDROID_API void attachFunctor(Functor* functor);
ANDROID_API void detachFunctor(Functor* functor);
+ ANDROID_API void invokeFunctor(Functor* functor, bool waitForCompletion);
ANDROID_API void runWithGlContext(RenderTask* task);