summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Foss <robert.foss@collabora.com>2016-11-10 22:16:28 -0500
committerRobert Foss <robert.foss@collabora.com>2017-03-22 14:38:44 -0400
commitca5f7d4da0fbd4edce0f6a9a92c504a29e468414 (patch)
tree8367e678370494f3a57db8ffc9a08833f30540b2
parent2128d10775f4a08fd9ea05674420b7caf3d078e4 (diff)
downloaddrm_hwcomposer-ca5f7d4da0fbd4edce0f6a9a92c504a29e468414.tar.gz
drm_hwcomposer-ca5f7d4da0fbd4edce0f6a9a92c504a29e468414.tar.xz
drm_hwcomposer: Make GLWorkerCompositor a subclass of Worker
Since compositions need to be executed on a seperate thread, make GLWorkerCompositor its own thread. Change-Id: I07a0fc7be1b549354158c6df4c5841ba8750c730 Sign-off-by: Robert Foss <robert.foss@collabora.com>
-rw-r--r--glworker.cpp68
-rw-r--r--glworker.h20
2 files changed, 83 insertions, 5 deletions
diff --git a/glworker.cpp b/glworker.cpp
index 00a4ceb..683fd0f 100644
--- a/glworker.cpp
+++ b/glworker.cpp
@@ -36,6 +36,7 @@
#include "drmdisplaycomposition.h"
#include "platform.h"
+#include "worker.h"
#include "glworker.h"
@@ -470,11 +471,51 @@ static int CreateTextureFromHandle(EGLDisplay egl_display,
}
GLWorkerCompositor::GLWorkerCompositor()
- : egl_display_(EGL_NO_DISPLAY), egl_ctx_(EGL_NO_CONTEXT) {
+ : Worker("gl-worker-compositor", HAL_PRIORITY_URGENT_DISPLAY),
+ egl_display_(EGL_NO_DISPLAY),
+ egl_ctx_(EGL_NO_CONTEXT) {
+}
+
+void GLWorkerCompositor::InitRoutine() {
+ _Init();
+}
+
+
+void GLWorkerCompositor::Routine() {
+ int ret = 0;
+
+ ret = Lock();
+ if (ret) {
+ ALOGE("Failed to lock worker, %d", ret);
+ return;
+ }
+
+ WaitForSignalOrExitLocked();
+
+ _Composite(composite_.layers,
+ composite_.regions,
+ composite_.num_regions,
+ composite_.framebuffer->buffer(),
+ composite_.importer);
+
+ ret = Unlock();
+ if (ret) {
+ ALOGE("Failed to unlock worker, %d", ret);
+ return;
+ }
}
int GLWorkerCompositor::Init() {
int ret = 0;
+
+ ret = InitWorker();
+// _Init();
+
+ return ret;
+}
+
+int GLWorkerCompositor::_Init() {
+ int ret = 0;
const char *egl_extensions;
const char *gl_extensions;
EGLint num_configs;
@@ -583,8 +624,29 @@ int GLWorkerCompositor::Composite(DrmHwcLayer *layers,
size_t num_regions,
DrmFramebuffer *framebuffer,
Importer *importer) {
- return _Composite(layers, regions, num_regions,
- framebuffer->buffer(), importer);
+ int ret = 0;
+
+ ret = Lock();
+ if (ret) {
+ ALOGE("Failed to lock worker, %d", ret);
+ return ret;
+ }
+
+ composite_.layers = layers;
+ composite_.regions = regions;
+ composite_.num_regions = num_regions;
+ composite_.framebuffer = framebuffer;
+ composite_.importer = importer;
+
+ SignalLocked();
+
+ ret = Unlock();
+ if (ret) {
+ ALOGE("Failed to lock worker, %d", ret);
+ return ret;
+ }
+
+ return ret;
}
int GLWorkerCompositor::_Composite(DrmHwcLayer *layers,
diff --git a/glworker.h b/glworker.h
index 190ab3f..5aeefac 100644
--- a/glworker.h
+++ b/glworker.h
@@ -31,16 +31,17 @@
#include "autogl.h"
#include "drmframebuffer.h"
+#include "worker.h"
namespace android {
struct DrmHwcLayer;
struct DrmCompositionRegion;
-class GLWorkerCompositor {
+class GLWorkerCompositor : public Worker {
public:
GLWorkerCompositor();
- ~GLWorkerCompositor();
+ ~GLWorkerCompositor() override;
int Init();
int Composite(DrmHwcLayer *layers, DrmCompositionRegion *regions,
@@ -49,6 +50,10 @@ class GLWorkerCompositor {
void Finish();
private:
+ pthread_t thread_;
+ pthread_mutex_t lock_;
+ pthread_cond_t cond_;
+
struct CachedFramebuffer {
// If the strong_framebuffer is non-NULL, we are holding a strong reference
// until we are sure rendering is done. The weak reference will be equal in
@@ -72,6 +77,17 @@ class GLWorkerCompositor {
EGLSurface saved_egl_draw = EGL_NO_SURFACE;
} private_;
+ struct {
+ DrmHwcLayer *layers;
+ DrmCompositionRegion *regions;
+ size_t num_regions;
+ DrmFramebuffer *framebuffer;
+ Importer *importer;
+ } composite_;
+
+ void InitRoutine() override;
+ void Routine() override;
+ int _Init();
int _Composite(DrmHwcLayer *layers,
DrmCompositionRegion *regions,
size_t num_regions,