Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17662389 authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

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
parent bd2d5f7e
Loading
Loading
Loading
Loading
+25 −35
Original line number Original line Diff line number Diff line
@@ -26,8 +26,6 @@


#include <log/log.h>
#include <log/log.h>


#include <GLES2/gl2.h>

namespace android {
namespace android {
namespace uirenderer {
namespace uirenderer {


@@ -46,39 +44,12 @@ static constexpr android::DisplayInfo sDummyDisplay{
        1920,   // viewportH
        1920,   // viewportH
};
};


static DeviceInfo* sDeviceInfo = nullptr;
static std::once_flag sInitializedFlag;

const DeviceInfo* DeviceInfo::get() {
const DeviceInfo* DeviceInfo::get() {
    LOG_ALWAYS_FATAL_IF(!sDeviceInfo, "DeviceInfo not yet initialized.");
        static DeviceInfo sDeviceInfo;
    return sDeviceInfo;
        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);
}
}


DisplayInfo DeviceInfo::queryDisplayInfo() {
DisplayInfo QueryDisplayInfo() {
    if (Properties::isolatedProcess) {
    if (Properties::isolatedProcess) {
        return sDummyDisplay;
        return sDummyDisplay;
    }
    }
@@ -90,7 +61,7 @@ DisplayInfo DeviceInfo::queryDisplayInfo() {
    return displayInfo;
    return displayInfo;
}
}


void DeviceInfo::queryCompositionPreference(ui::Dataspace* dataSpace,
void QueryCompositionPreference(ui::Dataspace* dataSpace,
                                ui::PixelFormat* pixelFormat) {
                                ui::PixelFormat* pixelFormat) {
    if (Properties::isolatedProcess) {
    if (Properties::isolatedProcess) {
        *dataSpace = ui::Dataspace::V0_SRGB;
        *dataSpace = ui::Dataspace::V0_SRGB;
@@ -102,5 +73,24 @@ void DeviceInfo::queryCompositionPreference(ui::Dataspace* dataSpace,
    LOG_ALWAYS_FATAL_IF(status, "Failed to get composition preference, error %d", status);
    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 uirenderer */
} /* namespace android */
} /* namespace android */
+11 −24
Original line number Original line Diff line number Diff line
@@ -19,51 +19,38 @@
#include <ui/DisplayInfo.h>
#include <ui/DisplayInfo.h>
#include <ui/GraphicTypes.h>
#include <ui/GraphicTypes.h>


#include "Extensions.h"
#include "utils/Macros.h"
#include "utils/Macros.h"


namespace android {
namespace android {
namespace uirenderer {
namespace uirenderer {


namespace renderthread {
    class RenderThread;
}

class DeviceInfo {
class DeviceInfo {
    PREVENT_COPY_AND_ASSIGN(DeviceInfo);
    PREVENT_COPY_AND_ASSIGN(DeviceInfo);


public:
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();
    static const DeviceInfo* get();


    // only call this after GL has been initialized, or at any point if compiled
    // this value is only valid after the GPU has been initialized and there is a valid graphics
    // with HWUI_NULL_GPU
    // context or if you are using the HWUI_NULL_GPU
    static void initialize();
    int maxTextureSize() const;
    static void initialize(int maxTextureSize);


    int maxTextureSize() const { return mMaxTextureSize; }
    ui::Dataspace getTargetDataSpace() const { return mTargetDataSpace; }
    ui::Dataspace getTargetDataSpace() const { return mTargetDataSpace; }
    ui::PixelFormat getTargetPixelFormat() const { return mTargetPixelFormat; }
    ui::PixelFormat getTargetPixelFormat() const { return mTargetPixelFormat; }
    const DisplayInfo& displayInfo() const { return mDisplayInfo; }
    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:
private:
    static void queryCompositionPreference(ui::Dataspace* dataSpace,
    friend class renderthread::RenderThread;
                                           ui::PixelFormat* pixelFormat);
    static void setMaxTextureSize(int maxTextureSize);

    DeviceInfo() {}
    ~DeviceInfo() {}


    void load();
    DeviceInfo();


    int mMaxTextureSize;
    int mMaxTextureSize;
    DisplayInfo mDisplayInfo;
    DisplayInfo mDisplayInfo;
    Extensions mExtensions;

    // TODO(lpy) Replace below with android_ prefix types.
    // TODO(lpy) Replace below with android_ prefix types.
    ui::Dataspace mTargetDataSpace;
    ui::Dataspace mTargetDataSpace;
    ui::PixelFormat mTargetPixelFormat;
    ui::PixelFormat mTargetPixelFormat;

libs/hwui/Extensions.h

deleted100644 → 0
+0 −59
Original line number Original line Diff line number Diff line
/*
 * 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
+3 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,9 @@
#include <GLES3/gl31.h>
#include <GLES3/gl31.h>
#include <GLES3/gl32.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
// Generate stubs that route all the calls to our function table
#include "gles_redefine.h"
#include "gles_redefine.h"


+0 −2
Original line number Original line Diff line number Diff line
@@ -23,7 +23,6 @@
#include "utils/Color.h"
#include "utils/Color.h"
#include "utils/StringUtils.h"
#include "utils/StringUtils.h"


#include "DeviceInfo.h"
#include "Frame.h"
#include "Frame.h"
#include "Properties.h"
#include "Properties.h"


@@ -127,7 +126,6 @@ void EglManager::initialize() {
    createContext();
    createContext();
    createPBufferSurface();
    createPBufferSurface();
    makeCurrent(mPBufferSurface, nullptr, /* force */ true);
    makeCurrent(mPBufferSurface, nullptr, /* force */ true);
    DeviceInfo::initialize();


    mSurfaceColorGamut = DataSpaceToColorGamut(
    mSurfaceColorGamut = DataSpaceToColorGamut(
        static_cast<android_dataspace>(DeviceInfo::get()->getTargetDataSpace()));
        static_cast<android_dataspace>(DeviceInfo::get()->getTargetDataSpace()));
Loading