summaryrefslogtreecommitdiff
path: root/libs/hwui/renderthread
diff options
context:
space:
mode:
authorStan Iliev <stani@google.com>2019-09-17 14:07:23 -0400
committerStan Iliev <stani@google.com>2019-11-08 15:37:17 +0000
commitaaa9e834d443a56671eccbe97c755c253fa94afe (patch)
treee67daf0782137e572f6be35e9a24b146c4fd4b57 /libs/hwui/renderthread
parent707ba29a6621220c2713468bf095178dcc1e376e (diff)
downloadbase-aaa9e834d443a56671eccbe97c755c253fa94afe.tar.gz
Decouple SurfaceTexture from HWUI
Remove all Skia and HWUI types from SurfaceTexture implementation. Move SurfaceTexture to libgui (ag/9578265). Define private C++ API for SurfaceTexture, which is consumed by DeferredLayerUpdater. Move AutoBackendTextureRelease/Skia code from SurfaceTexture to HWUI. Test: pass CtsUiRenderingTestCases and CtsViewTestCases Bug: 136263580 Change-Id: I3f971bb490f64a3ac0b2a66a89ba935bf7f08213
Diffstat (limited to 'libs/hwui/renderthread')
-rw-r--r--libs/hwui/renderthread/EglManager.cpp44
-rw-r--r--libs/hwui/renderthread/EglManager.h6
-rw-r--r--libs/hwui/renderthread/RenderThread.h23
-rw-r--r--libs/hwui/renderthread/VulkanManager.cpp46
-rw-r--r--libs/hwui/renderthread/VulkanManager.h9
5 files changed, 69 insertions, 59 deletions
diff --git a/libs/hwui/renderthread/EglManager.cpp b/libs/hwui/renderthread/EglManager.cpp
index 12021641518c..eb469a810358 100644
--- a/libs/hwui/renderthread/EglManager.cpp
+++ b/libs/hwui/renderthread/EglManager.cpp
@@ -16,23 +16,23 @@
#include "EglManager.h"
+#include <EGL/eglext.h>
+#include <GLES/gl.h>
#include <cutils/properties.h>
#include <log/log.h>
#include <private/gui/SyncFeatures.h>
+#include <sync/sync.h>
+#include <system/window.h>
#include <utils/Trace.h>
-#include "utils/Color.h"
-#include "utils/StringUtils.h"
-
-#include "Frame.h"
-#include "Properties.h"
-
-#include <EGL/eglext.h>
-#include <GLES/gl.h>
-#include <system/window.h>
#include <string>
#include <vector>
+#include "Frame.h"
+#include "Properties.h"
+#include "utils/Color.h"
+#include "utils/StringUtils.h"
+
#define GLES_VERSION 2
// Android-specific addition that is used to show when frames began in systrace
@@ -508,7 +508,21 @@ bool EglManager::setPreserveBuffer(EGLSurface surface, bool preserve) {
return preserved;
}
-status_t EglManager::fenceWait(sp<Fence>& fence) {
+static status_t waitForeverOnFence(int fence, const char* logname) {
+ ATRACE_CALL();
+ if (fence == -1) {
+ return NO_ERROR;
+ }
+ constexpr int warningTimeout = 3000;
+ int err = sync_wait(fence, warningTimeout);
+ if (err < 0 && errno == ETIME) {
+ ALOGE("%s: fence %d didn't signal in %d ms", logname, fence, warningTimeout);
+ err = sync_wait(fence, -1);
+ }
+ return err < 0 ? -errno : status_t(NO_ERROR);
+}
+
+status_t EglManager::fenceWait(int fence) {
if (!hasEglContext()) {
ALOGE("EglManager::fenceWait: EGLDisplay not initialized");
return INVALID_OPERATION;
@@ -518,7 +532,7 @@ status_t EglManager::fenceWait(sp<Fence>& fence) {
SyncFeatures::getInstance().useNativeFenceSync()) {
// Block GPU on the fence.
// Create an EGLSyncKHR from the current fence.
- int fenceFd = fence->dup();
+ int fenceFd = ::dup(fence);
if (fenceFd == -1) {
ALOGE("EglManager::fenceWait: error dup'ing fence fd: %d", errno);
return -errno;
@@ -543,7 +557,7 @@ status_t EglManager::fenceWait(sp<Fence>& fence) {
}
} else {
// Block CPU on the fence.
- status_t err = fence->waitForever("EglManager::fenceWait");
+ status_t err = waitForeverOnFence(fence, "EglManager::fenceWait");
if (err != NO_ERROR) {
ALOGE("EglManager::fenceWait: error waiting for fence: %d", err);
return err;
@@ -552,8 +566,8 @@ status_t EglManager::fenceWait(sp<Fence>& fence) {
return OK;
}
-status_t EglManager::createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence,
- sp<Fence>& nativeFence) {
+status_t EglManager::createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence, int* nativeFence) {
+ *nativeFence = -1;
if (!hasEglContext()) {
ALOGE("EglManager::createReleaseFence: EGLDisplay not initialized");
return INVALID_OPERATION;
@@ -574,7 +588,7 @@ status_t EglManager::createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence,
eglGetError());
return UNKNOWN_ERROR;
}
- nativeFence = new Fence(fenceFd);
+ *nativeFence = fenceFd;
*eglFence = EGL_NO_SYNC_KHR;
} else if (useFenceSync && SyncFeatures::getInstance().useFenceSync()) {
if (*eglFence != EGL_NO_SYNC_KHR) {
diff --git a/libs/hwui/renderthread/EglManager.h b/libs/hwui/renderthread/EglManager.h
index 27d41d26a73a..a893e245b214 100644
--- a/libs/hwui/renderthread/EglManager.h
+++ b/libs/hwui/renderthread/EglManager.h
@@ -21,9 +21,9 @@
#include <SkImageInfo.h>
#include <SkRect.h>
#include <cutils/compiler.h>
-#include <ui/Fence.h>
#include <ui/GraphicBuffer.h>
#include <utils/StrongPointer.h>
+
#include "IRenderPipeline.h"
#include "utils/Result.h"
@@ -74,11 +74,11 @@ public:
// Inserts a wait on fence command into the OpenGL ES command stream. If EGL extension
// support is missing, block the CPU on the fence.
- status_t fenceWait(sp<Fence>& fence);
+ status_t fenceWait(int fence);
// Creates a fence that is signaled, when all the pending GL commands are flushed.
// Depending on installed extensions, the result is either Android native fence or EGL fence.
- status_t createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence, sp<Fence>& nativeFence);
+ status_t createReleaseFence(bool useFenceSync, EGLSyncKHR* eglFence, int* nativeFence);
private:
enum class SwapBehavior {
diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h
index bdd80721c4f3..da79e97a6ceb 100644
--- a/libs/hwui/renderthread/RenderThread.h
+++ b/libs/hwui/renderthread/RenderThread.h
@@ -17,33 +17,32 @@
#ifndef RENDERTHREAD_H_
#define RENDERTHREAD_H_
-#include "RenderTask.h"
-
-#include "CacheManager.h"
-#include "ProfileDataContainer.h"
-#include "TimeLord.h"
-#include "WebViewFunctorManager.h"
-#include "thread/ThreadBase.h"
-#include "utils/TimeUtils.h"
-
#include <GrContext.h>
#include <SkBitmap.h>
#include <cutils/compiler.h>
+#include <thread/ThreadBase.h>
#include <utils/Looper.h>
#include <utils/Thread.h>
-#include <thread/ThreadBase.h>
#include <memory>
#include <mutex>
#include <set>
+#include "CacheManager.h"
+#include "ProfileDataContainer.h"
+#include "RenderTask.h"
+#include "TimeLord.h"
+#include "WebViewFunctorManager.h"
+#include "thread/ThreadBase.h"
+#include "utils/TimeUtils.h"
+
namespace android {
class Bitmap;
-class AutoBackendTextureRelease;
namespace uirenderer {
+class AutoBackendTextureRelease;
class Readback;
class RenderState;
class TestUtils;
@@ -137,7 +136,7 @@ private:
friend class DispatchFrameCallbacks;
friend class RenderProxy;
friend class DummyVsyncSource;
- friend class android::AutoBackendTextureRelease;
+ friend class android::uirenderer::AutoBackendTextureRelease;
friend class android::uirenderer::TestUtils;
friend class android::uirenderer::WebViewFunctor;
friend class android::uirenderer::skiapipeline::VkFunctorDrawHandler;
diff --git a/libs/hwui/renderthread/VulkanManager.cpp b/libs/hwui/renderthread/VulkanManager.cpp
index 35abc57fbe57..a5355fc3499d 100644
--- a/libs/hwui/renderthread/VulkanManager.cpp
+++ b/libs/hwui/renderthread/VulkanManager.cpp
@@ -16,23 +16,22 @@
#include "VulkanManager.h"
-#include <android/sync.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
-
-#include "Properties.h"
-#include "RenderThread.h"
-#include "renderstate/RenderState.h"
-#include "utils/FatVector.h"
-#include "utils/TraceUtils.h"
-
#include <GrBackendSemaphore.h>
#include <GrBackendSurface.h>
#include <GrContext.h>
#include <GrTypes.h>
+#include <android/sync.h>
#include <vk/GrVkExtensions.h>
#include <vk/GrVkTypes.h>
+#include "Properties.h"
+#include "RenderThread.h"
+#include "renderstate/RenderState.h"
+#include "utils/FatVector.h"
+#include "utils/TraceUtils.h"
+
namespace android {
namespace uirenderer {
namespace renderthread {
@@ -482,7 +481,7 @@ struct DestroySemaphoreInfo {
int mRefs = 2;
DestroySemaphoreInfo(PFN_vkDestroySemaphore destroyFunction, VkDevice device,
- VkSemaphore semaphore)
+ VkSemaphore semaphore)
: mDestroyFunction(destroyFunction), mDevice(device), mSemaphore(semaphore) {}
};
@@ -524,12 +523,11 @@ void VulkanManager::swapBuffers(VulkanSurface* surface, const SkRect& dirtyRect)
backendSemaphore.initVulkan(semaphore);
int fenceFd = -1;
- DestroySemaphoreInfo* destroyInfo = new DestroySemaphoreInfo(mDestroySemaphore, mDevice,
- semaphore);
- GrSemaphoresSubmitted submitted =
- bufferInfo->skSurface->flush(SkSurface::BackendSurfaceAccess::kPresent,
- kNone_GrFlushFlags, 1, &backendSemaphore,
- destroy_semaphore, destroyInfo);
+ DestroySemaphoreInfo* destroyInfo =
+ new DestroySemaphoreInfo(mDestroySemaphore, mDevice, semaphore);
+ GrSemaphoresSubmitted submitted = bufferInfo->skSurface->flush(
+ SkSurface::BackendSurfaceAccess::kPresent, kNone_GrFlushFlags, 1, &backendSemaphore,
+ destroy_semaphore, destroyInfo);
if (submitted == GrSemaphoresSubmitted::kYes) {
VkSemaphoreGetFdInfoKHR getFdInfo;
getFdInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR;
@@ -571,14 +569,14 @@ VulkanSurface* VulkanManager::createSurface(ANativeWindow* window, ColorMode col
*this, extraBuffers);
}
-status_t VulkanManager::fenceWait(sp<Fence>& fence, GrContext* grContext) {
+status_t VulkanManager::fenceWait(int fence, GrContext* grContext) {
if (!hasVkContext()) {
ALOGE("VulkanManager::fenceWait: VkDevice not initialized");
return INVALID_OPERATION;
}
// Block GPU on the fence.
- int fenceFd = fence->dup();
+ int fenceFd = ::dup(fence);
if (fenceFd == -1) {
ALOGE("VulkanManager::fenceWait: error dup'ing fence fd: %d", errno);
return -errno;
@@ -619,7 +617,8 @@ status_t VulkanManager::fenceWait(sp<Fence>& fence, GrContext* grContext) {
return OK;
}
-status_t VulkanManager::createReleaseFence(sp<Fence>& nativeFence, GrContext* grContext) {
+status_t VulkanManager::createReleaseFence(int* nativeFence, GrContext* grContext) {
+ *nativeFence = -1;
if (!hasVkContext()) {
ALOGE("VulkanManager::createReleaseFence: VkDevice not initialized");
return INVALID_OPERATION;
@@ -644,14 +643,13 @@ status_t VulkanManager::createReleaseFence(sp<Fence>& nativeFence, GrContext* gr
GrBackendSemaphore backendSemaphore;
backendSemaphore.initVulkan(semaphore);
- DestroySemaphoreInfo* destroyInfo = new DestroySemaphoreInfo(mDestroySemaphore, mDevice,
- semaphore);
+ DestroySemaphoreInfo* destroyInfo =
+ new DestroySemaphoreInfo(mDestroySemaphore, mDevice, semaphore);
// Even if Skia fails to submit the semaphore, it will still call the destroy_semaphore callback
// which will remove its ref to the semaphore. The VulkanManager must still release its ref,
// when it is done with the semaphore.
- GrSemaphoresSubmitted submitted =
- grContext->flush(kNone_GrFlushFlags, 1, &backendSemaphore,
- destroy_semaphore, destroyInfo);
+ GrSemaphoresSubmitted submitted = grContext->flush(kNone_GrFlushFlags, 1, &backendSemaphore,
+ destroy_semaphore, destroyInfo);
if (submitted == GrSemaphoresSubmitted::kNo) {
ALOGE("VulkanManager::createReleaseFence: Failed to submit semaphore");
@@ -673,7 +671,7 @@ status_t VulkanManager::createReleaseFence(sp<Fence>& nativeFence, GrContext* gr
ALOGE("VulkanManager::createReleaseFence: Failed to get semaphore Fd");
return INVALID_OPERATION;
}
- nativeFence = new Fence(fenceFd);
+ *nativeFence = fenceFd;
return OK;
}
diff --git a/libs/hwui/renderthread/VulkanManager.h b/libs/hwui/renderthread/VulkanManager.h
index 4c6a75504cd0..8b19f13fdfb9 100644
--- a/libs/hwui/renderthread/VulkanManager.h
+++ b/libs/hwui/renderthread/VulkanManager.h
@@ -20,14 +20,13 @@
#if !defined(VK_USE_PLATFORM_ANDROID_KHR)
#define VK_USE_PLATFORM_ANDROID_KHR
#endif
-#include <vulkan/vulkan.h>
-
#include <GrContextOptions.h>
#include <SkSurface.h>
-#include <ui/Fence.h>
#include <utils/StrongPointer.h>
#include <vk/GrVkBackendContext.h>
#include <vk/GrVkExtensions.h>
+#include <vulkan/vulkan.h>
+
#include "Frame.h"
#include "IRenderPipeline.h"
#include "VulkanSurface.h"
@@ -71,11 +70,11 @@ public:
void destroy();
// Inserts a wait on fence command into the Vulkan command buffer.
- status_t fenceWait(sp<Fence>& fence, GrContext* grContext);
+ status_t fenceWait(int fence, GrContext* grContext);
// Creates a fence that is signaled when all the pending Vulkan commands are finished on the
// GPU.
- status_t createReleaseFence(sp<Fence>& nativeFence, GrContext* grContext);
+ status_t createReleaseFence(int* nativeFence, GrContext* grContext);
// Returned pointers are owned by VulkanManager.
// An instance of VkFunctorInitParams returned from getVkFunctorInitParams refers to