diff options
Diffstat (limited to 'libs/hwui/renderthread/RenderThread.cpp')
-rw-r--r-- | libs/hwui/renderthread/RenderThread.cpp | 100 |
1 files changed, 55 insertions, 45 deletions
diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp index 6a2a025da121..207673c1c8dd 100644 --- a/libs/hwui/renderthread/RenderThread.cpp +++ b/libs/hwui/renderthread/RenderThread.cpp @@ -19,19 +19,23 @@ #include "CanvasContext.h" #include "DeviceInfo.h" #include "EglManager.h" -#include "OpenGLReadback.h" +#include "Readback.h" #include "RenderProxy.h" #include "VulkanManager.h" #include "hwui/Bitmap.h" #include "pipeline/skia/SkiaOpenGLPipeline.h" -#include "pipeline/skia/SkiaOpenGLReadback.h" -#include "pipeline/skia/SkiaVulkanReadback.h" #include "pipeline/skia/SkiaVulkanPipeline.h" #include "renderstate/RenderState.h" -#include "renderthread/OpenGLPipeline.h" #include "utils/FatVector.h" #include "utils/TimeUtils.h" +#ifdef HWUI_GLES_WRAP_ENABLED +#include "debug/GlesDriver.h" +#endif + +#include <GrContextOptions.h> +#include <gl/GrGLInterface.h> + #include <gui/DisplayEventReceiver.h> #include <sys/resource.h> #include <utils/Condition.h> @@ -93,14 +97,11 @@ public: DummyVsyncSource(RenderThread* renderThread) : mRenderThread(renderThread) {} virtual void requestNextVsync() override { - mRenderThread->queue().postDelayed(16_ms, [this]() { - mRenderThread->drainDisplayEventQueue(); - }); + mRenderThread->queue().postDelayed(16_ms, + [this]() { mRenderThread->drainDisplayEventQueue(); }); } - virtual nsecs_t latestVsyncEvent() override { - return systemTime(CLOCK_MONOTONIC); - } + virtual nsecs_t latestVsyncEvent() override { return systemTime(CLOCK_MONOTONIC); } private: RenderThread* mRenderThread; @@ -147,13 +148,13 @@ void RenderThread::initializeDisplayEventReceiver() { auto receiver = std::make_unique<DisplayEventReceiver>(); status_t status = receiver->initCheck(); LOG_ALWAYS_FATAL_IF(status != NO_ERROR, - "Initialization of DisplayEventReceiver " - "failed with status: %d", - status); + "Initialization of DisplayEventReceiver " + "failed with status: %d", + status); // Register the FD mLooper->addFd(receiver->getFd(), 0, Looper::EVENT_INPUT, - RenderThread::displayEventReceiverCallback, this); + RenderThread::displayEventReceiverCallback, this); mVsyncSource = new DisplayEventReceiverWrapper(std::move(receiver)); } else { mVsyncSource = new DummyVsyncSource(this); @@ -161,16 +162,48 @@ void RenderThread::initializeDisplayEventReceiver() { } void RenderThread::initThreadLocals() { - mDisplayInfo = DeviceInfo::queryDisplayInfo(); + mDisplayInfo = DeviceInfo::get()->displayInfo(); nsecs_t frameIntervalNanos = static_cast<nsecs_t>(1000000000 / mDisplayInfo.fps); mTimeLord.setFrameInterval(frameIntervalNanos); initializeDisplayEventReceiver(); - mEglManager = new EglManager(*this); + mEglManager = new EglManager(); mRenderState = new RenderState(*this); mVkManager = new VulkanManager(*this); mCacheManager = new CacheManager(mDisplayInfo); } +void RenderThread::requireGlContext() { + if (mEglManager->hasEglContext()) { + return; + } + mEglManager->initialize(); + +#ifdef HWUI_GLES_WRAP_ENABLED + debug::GlesDriver* driver = debug::GlesDriver::get(); + sk_sp<const GrGLInterface> glInterface(driver->getSkiaInterface()); +#else + sk_sp<const GrGLInterface> glInterface(GrGLCreateNativeInterface()); +#endif + LOG_ALWAYS_FATAL_IF(!glInterface.get()); + + GrContextOptions options; + options.fPreferExternalImagesOverES3 = true; + options.fDisableDistanceFieldPaths = true; + auto glesVersion = reinterpret_cast<const char*>(glGetString(GL_VERSION)); + auto size = glesVersion ? strlen(glesVersion) : -1; + cacheManager().configureContext(&options, glesVersion, size); + sk_sp<GrContext> grContext(GrContext::MakeGL(std::move(glInterface), options)); + LOG_ALWAYS_FATAL_IF(!grContext.get()); + setGrContext(grContext); +} + +void RenderThread::destroyGlContext() { + if (mEglManager->hasEglContext()) { + setGrContext(nullptr); + mEglManager->destroy(); + } +} + void RenderThread::dumpGraphicsMemory(int fd) { globalProfileData()->dump(fd); @@ -178,16 +211,6 @@ void RenderThread::dumpGraphicsMemory(int fd) { String8 pipeline; auto renderType = Properties::getRenderPipelineType(); switch (renderType) { - case RenderPipelineType::OpenGL: { - if (Caches::hasInstance()) { - cachesOutput.appendFormat("Caches:\n"); - Caches::getInstance().dumpMemoryUsage(cachesOutput); - } else { - cachesOutput.appendFormat("No caches instance."); - } - pipeline.appendFormat("FrameBuilder"); - break; - } case RenderPipelineType::SkiaGL: { mCacheManager->dumpMemoryUsage(cachesOutput, mRenderState); pipeline.appendFormat("Skia (OpenGL)"); @@ -209,21 +232,7 @@ void RenderThread::dumpGraphicsMemory(int fd) { Readback& RenderThread::readback() { if (!mReadback) { - auto renderType = Properties::getRenderPipelineType(); - switch (renderType) { - case RenderPipelineType::OpenGL: - mReadback = new OpenGLReadbackImpl(*this); - break; - case RenderPipelineType::SkiaGL: - mReadback = new skiapipeline::SkiaOpenGLReadback(*this); - break; - case RenderPipelineType::SkiaVulkan: - mReadback = new skiapipeline::SkiaVulkanReadback(*this); - break; - default: - LOG_ALWAYS_FATAL("canvas context type %d not supported", (int32_t)renderType); - break; - } + mReadback = new Readback(*this); } return *mReadback; @@ -232,9 +241,14 @@ Readback& RenderThread::readback() { void RenderThread::setGrContext(sk_sp<GrContext> context) { mCacheManager->reset(context); if (mGrContext) { + mRenderState->onContextDestroyed(); mGrContext->releaseResourcesAndAbandonContext(); } mGrContext = std::move(context); + if (mGrContext) { + mRenderState->onContextCreated(); + DeviceInfo::setMaxTextureSize(mGrContext->maxRenderTargetSize()); + } } int RenderThread::displayEventReceiverCallback(int fd, int events, void* data) { @@ -347,10 +361,6 @@ void RenderThread::pushBackFrameCallback(IFrameCallback* callback) { sk_sp<Bitmap> RenderThread::allocateHardwareBitmap(SkBitmap& skBitmap) { auto renderType = Properties::getRenderPipelineType(); switch (renderType) { - case RenderPipelineType::OpenGL: - return OpenGLPipeline::allocateHardwareBitmap(*this, skBitmap); - case RenderPipelineType::SkiaGL: - return skiapipeline::SkiaOpenGLPipeline::allocateHardwareBitmap(*this, skBitmap); case RenderPipelineType::SkiaVulkan: return skiapipeline::SkiaVulkanPipeline::allocateHardwareBitmap(*this, skBitmap); default: |