diff options
author | 2018-09-13 14:14:00 -0400 | |
---|---|---|
committer | 2018-09-18 09:30:13 -0400 | |
commit | 17662389b970e8c710f146c15d5b78a767a251d3 (patch) | |
tree | 97a6da7a569f956c61d1d2c341c9857997f45e3f | |
parent | bd2d5f7e37a9d4fba09b2e3df0d891af1f192247 (diff) |
Refactor DeviceInfo in HWUI
Remove the need for both Vulkan and EGL managers to initialize
it. Also remove unused code paths.
Test: hwui_unit_tests
Change-Id: I33ad881468eddbf91ec63207f0d82bed8d97f5ad
-rw-r--r-- | libs/hwui/DeviceInfo.cpp | 60 | ||||
-rw-r--r-- | libs/hwui/DeviceInfo.h | 35 | ||||
-rw-r--r-- | libs/hwui/Extensions.h | 59 | ||||
-rw-r--r-- | libs/hwui/debug/wrap_gles.h | 3 | ||||
-rw-r--r-- | libs/hwui/renderthread/EglManager.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderThread.cpp | 5 | ||||
-rw-r--r-- | libs/hwui/renderthread/VulkanManager.cpp | 3 | ||||
-rw-r--r-- | libs/hwui/tests/common/TestUtils.h | 18 | ||||
-rw-r--r-- | libs/hwui/tests/unit/RenderPropertiesTests.cpp | 2 |
9 files changed, 43 insertions, 144 deletions
diff --git a/libs/hwui/DeviceInfo.cpp b/libs/hwui/DeviceInfo.cpp index b5b87d516ff7..21fbbdca7ad0 100644 --- a/libs/hwui/DeviceInfo.cpp +++ b/libs/hwui/DeviceInfo.cpp @@ -26,8 +26,6 @@ #include <log/log.h> -#include <GLES2/gl2.h> - namespace android { namespace uirenderer { @@ -46,39 +44,12 @@ static constexpr android::DisplayInfo sDummyDisplay{ 1920, // viewportH }; -static DeviceInfo* sDeviceInfo = nullptr; -static std::once_flag sInitializedFlag; - const DeviceInfo* DeviceInfo::get() { - LOG_ALWAYS_FATAL_IF(!sDeviceInfo, "DeviceInfo not yet initialized."); - return sDeviceInfo; -} - -void DeviceInfo::initialize() { - std::call_once(sInitializedFlag, []() { - sDeviceInfo = new DeviceInfo(); - sDeviceInfo->load(); - }); -} - -void DeviceInfo::initialize(int maxTextureSize) { - std::call_once(sInitializedFlag, [maxTextureSize]() { - sDeviceInfo = new DeviceInfo(); - sDeviceInfo->mDisplayInfo = DeviceInfo::queryDisplayInfo(); - sDeviceInfo->mMaxTextureSize = maxTextureSize; - sDeviceInfo->queryCompositionPreference(&sDeviceInfo->mTargetDataSpace, - &sDeviceInfo->mTargetPixelFormat); - }); -} - -void DeviceInfo::load() { - mDisplayInfo = queryDisplayInfo(); - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize); - sDeviceInfo->queryCompositionPreference(&sDeviceInfo->mTargetDataSpace, - &sDeviceInfo->mTargetPixelFormat); + static DeviceInfo sDeviceInfo; + return &sDeviceInfo; } -DisplayInfo DeviceInfo::queryDisplayInfo() { +DisplayInfo QueryDisplayInfo() { if (Properties::isolatedProcess) { return sDummyDisplay; } @@ -90,17 +61,36 @@ DisplayInfo DeviceInfo::queryDisplayInfo() { return displayInfo; } -void DeviceInfo::queryCompositionPreference(ui::Dataspace* dataSpace, - ui::PixelFormat* pixelFormat) { +void QueryCompositionPreference(ui::Dataspace* dataSpace, + ui::PixelFormat* pixelFormat) { if (Properties::isolatedProcess) { *dataSpace = ui::Dataspace::V0_SRGB; *pixelFormat = ui::PixelFormat::RGBA_8888; } status_t status = - SurfaceComposerClient::getCompositionPreference(dataSpace, pixelFormat); + SurfaceComposerClient::getCompositionPreference(dataSpace, pixelFormat); LOG_ALWAYS_FATAL_IF(status, "Failed to get composition preference, error %d", status); } +DeviceInfo::DeviceInfo() { +#if HWUI_NULL_GPU + mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE; +#else + mMaxTextureSize = -1; +#endif + mDisplayInfo = QueryDisplayInfo(); + QueryCompositionPreference(&mTargetDataSpace, &mTargetPixelFormat); +} + +int DeviceInfo::maxTextureSize() const { + LOG_ALWAYS_FATAL_IF(mMaxTextureSize < 0, "MaxTextureSize has not been initialized yet."); + return mMaxTextureSize; +} + +void DeviceInfo::setMaxTextureSize(int maxTextureSize) { + const_cast<DeviceInfo*>(DeviceInfo::get())->mMaxTextureSize = maxTextureSize; +} + } /* namespace uirenderer */ } /* namespace android */ diff --git a/libs/hwui/DeviceInfo.h b/libs/hwui/DeviceInfo.h index 416af179eb21..1d7477416077 100644 --- a/libs/hwui/DeviceInfo.h +++ b/libs/hwui/DeviceInfo.h @@ -19,51 +19,38 @@ #include <ui/DisplayInfo.h> #include <ui/GraphicTypes.h> -#include "Extensions.h" #include "utils/Macros.h" namespace android { namespace uirenderer { +namespace renderthread { + class RenderThread; +} + class DeviceInfo { PREVENT_COPY_AND_ASSIGN(DeviceInfo); public: - // returns nullptr if DeviceInfo is not initialized yet - // Note this does not have a memory fence so it's up to the caller - // to use one if required. Normally this should not be necessary static const DeviceInfo* get(); - // only call this after GL has been initialized, or at any point if compiled - // with HWUI_NULL_GPU - static void initialize(); - static void initialize(int maxTextureSize); + // this value is only valid after the GPU has been initialized and there is a valid graphics + // context or if you are using the HWUI_NULL_GPU + int maxTextureSize() const; - int maxTextureSize() const { return mMaxTextureSize; } ui::Dataspace getTargetDataSpace() const { return mTargetDataSpace; } ui::PixelFormat getTargetPixelFormat() const { return mTargetPixelFormat; } const DisplayInfo& displayInfo() const { return mDisplayInfo; } - const Extensions& extensions() const { return mExtensions; } - - static uint32_t multiplyByResolution(uint32_t in) { - auto di = DeviceInfo::get()->displayInfo(); - return di.w * di.h * in; - } - - static DisplayInfo queryDisplayInfo(); private: - static void queryCompositionPreference(ui::Dataspace* dataSpace, - ui::PixelFormat* pixelFormat); + friend class renderthread::RenderThread; + static void setMaxTextureSize(int maxTextureSize); - DeviceInfo() {} - ~DeviceInfo() {} - - void load(); + DeviceInfo(); int mMaxTextureSize; DisplayInfo mDisplayInfo; - Extensions mExtensions; + // TODO(lpy) Replace below with android_ prefix types. ui::Dataspace mTargetDataSpace; ui::PixelFormat mTargetPixelFormat; diff --git a/libs/hwui/Extensions.h b/libs/hwui/Extensions.h deleted file mode 100644 index e90f40c1c979..000000000000 --- a/libs/hwui/Extensions.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ANDROID_HWUI_EXTENSIONS_H -#define ANDROID_HWUI_EXTENSIONS_H - -namespace android { -namespace uirenderer { - -/////////////////////////////////////////////////////////////////////////////// -// Classes -/////////////////////////////////////////////////////////////////////////////// - -class Extensions { -public: - Extensions() {} - - inline bool hasNPot() const { return false; } - inline bool hasFramebufferFetch() const { return false; } - inline bool hasDiscardFramebuffer() const { return false; } - inline bool hasDebugMarker() const { return false; } - inline bool has1BitStencil() const { return false; } - inline bool has4BitStencil() const { return false; } - inline bool hasUnpackRowLength() const { return mVersionMajor >= 3; } - inline bool hasPixelBufferObjects() const { return mVersionMajor >= 3; } - inline bool hasOcclusionQueries() const { return mVersionMajor >= 3; } - inline bool hasFloatTextures() const { return mVersionMajor >= 3; } - inline bool hasRenderableFloatTextures() const { - return (mVersionMajor >= 3 && mVersionMinor >= 2); - } - inline bool hasSRGB() const { return false; } - inline bool hasSRGBWriteControl() const { return hasSRGB() && false; } - inline bool hasLinearBlending() const { return hasSRGB() && false; } - - inline int getMajorGlVersion() const { return mVersionMajor; } - inline int getMinorGlVersion() const { return mVersionMinor; } - -private: - int mVersionMajor = 2; - int mVersionMinor = 0; -}; // class Extensions - -}; // namespace uirenderer -}; // namespace android - -#endif // ANDROID_HWUI_EXTENSIONS_H diff --git a/libs/hwui/debug/wrap_gles.h b/libs/hwui/debug/wrap_gles.h index 27a29aa0a6b2..3da6e802d178 100644 --- a/libs/hwui/debug/wrap_gles.h +++ b/libs/hwui/debug/wrap_gles.h @@ -28,6 +28,9 @@ #include <GLES3/gl31.h> #include <GLES3/gl32.h> +// constant used by the NULL GPU implementation as well as HWUI's unit tests +constexpr int NULL_GPU_MAX_TEXTURE_SIZE = 2048; + // Generate stubs that route all the calls to our function table #include "gles_redefine.h" diff --git a/libs/hwui/renderthread/EglManager.cpp b/libs/hwui/renderthread/EglManager.cpp index 675df4118876..0cb23e532064 100644 --- a/libs/hwui/renderthread/EglManager.cpp +++ b/libs/hwui/renderthread/EglManager.cpp @@ -23,7 +23,6 @@ #include "utils/Color.h" #include "utils/StringUtils.h" -#include "DeviceInfo.h" #include "Frame.h" #include "Properties.h" @@ -127,7 +126,6 @@ void EglManager::initialize() { createContext(); createPBufferSurface(); makeCurrent(mPBufferSurface, nullptr, /* force */ true); - DeviceInfo::initialize(); mSurfaceColorGamut = DataSpaceToColorGamut( static_cast<android_dataspace>(DeviceInfo::get()->getTargetDataSpace())); diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp index 7258a0aa4f02..a5dcc72636d1 100644 --- a/libs/hwui/renderthread/RenderThread.cpp +++ b/libs/hwui/renderthread/RenderThread.cpp @@ -162,7 +162,7 @@ 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(); @@ -246,6 +246,9 @@ void RenderThread::setGrContext(sk_sp<GrContext> context) { mGrContext->releaseResourcesAndAbandonContext(); } mGrContext = std::move(context); + if (mGrContext) { + DeviceInfo::setMaxTextureSize(mGrContext->maxRenderTargetSize()); + } } int RenderThread::displayEventReceiverCallback(int fd, int events, void* data) { diff --git a/libs/hwui/renderthread/VulkanManager.cpp b/libs/hwui/renderthread/VulkanManager.cpp index 038e13c513fd..488117253e7a 100644 --- a/libs/hwui/renderthread/VulkanManager.cpp +++ b/libs/hwui/renderthread/VulkanManager.cpp @@ -16,7 +16,6 @@ #include "VulkanManager.h" -#include "DeviceInfo.h" #include "Properties.h" #include "RenderThread.h" #include "renderstate/RenderState.h" @@ -399,8 +398,6 @@ void VulkanManager::initialize() { free_features_extensions_structs(features); - DeviceInfo::initialize(mRenderThread.getGrContext()->maxRenderTargetSize()); - if (Properties::enablePartialUpdates && Properties::useBufferAge) { mSwapBehavior = SwapBehavior::BufferAge; } diff --git a/libs/hwui/tests/common/TestUtils.h b/libs/hwui/tests/common/TestUtils.h index 0e6582c59a36..c35f512553d8 100644 --- a/libs/hwui/tests/common/TestUtils.h +++ b/libs/hwui/tests/common/TestUtils.h @@ -16,7 +16,6 @@ #pragma once -#include <DeviceInfo.h> #include <DisplayList.h> #include <Matrix.h> #include <Properties.h> @@ -179,12 +178,6 @@ public: static sp<RenderNode> createNode( int left, int top, int right, int bottom, std::function<void(RenderProperties& props, Canvas& canvas)> setup) { -#if HWUI_NULL_GPU - // if RenderNodes are being sync'd/used, device info will be needed, since - // DeviceInfo::maxTextureSize() affects layer property - DeviceInfo::initialize(); -#endif - sp<RenderNode> node = new RenderNode(); RenderProperties& props = node->mutateStagingProperties(); props.setLeftTopRightBottom(left, top, right, bottom); @@ -202,12 +195,6 @@ public: static sp<RenderNode> createNode( int left, int top, int right, int bottom, std::function<void(RenderProperties& props, RecordingCanvasType& canvas)> setup) { -#if HWUI_NULL_GPU - // if RenderNodes are being sync'd/used, device info will be needed, since - // DeviceInfo::maxTextureSize() affects layer property - DeviceInfo::initialize(); -#endif - sp<RenderNode> node = new RenderNode(); RenderProperties& props = node->mutateStagingProperties(); props.setLeftTopRightBottom(left, top, right, bottom); @@ -233,11 +220,6 @@ public: std::function<void(RenderProperties& props, skiapipeline::SkiaRecordingCanvas& canvas)> setup, const char* name = nullptr, skiapipeline::SkiaDisplayList* displayList = nullptr) { -#if HWUI_NULL_GPU - // if RenderNodes are being sync'd/used, device info will be needed, since - // DeviceInfo::maxTextureSize() affects layer property - DeviceInfo::initialize(); -#endif sp<RenderNode> node = new RenderNode(); if (name) { node->setName(name); diff --git a/libs/hwui/tests/unit/RenderPropertiesTests.cpp b/libs/hwui/tests/unit/RenderPropertiesTests.cpp index 85655fc2728a..3e8e0576bf49 100644 --- a/libs/hwui/tests/unit/RenderPropertiesTests.cpp +++ b/libs/hwui/tests/unit/RenderPropertiesTests.cpp @@ -22,8 +22,6 @@ using namespace android; using namespace android::uirenderer; TEST(RenderProperties, layerValidity) { - DeviceInfo::initialize(); - const int maxTextureSize = DeviceInfo::get()->maxTextureSize(); ASSERT_LE(2048, maxTextureSize); ASSERT_GT(100000, maxTextureSize); |