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

Commit fda42697 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "virtual-display-alloc-sc-dev" into sc-dev

* changes:
  SF: Remove composer sequence IDs
  SF: Extract virtual display allocation from CE
  SF: Use RenderSurfaceCreationArgsBuilder
  SF: Parametrize display lookup
parents 3acce53a ebc8d3aa
Loading
Loading
Loading
Loading
+9 −36
Original line number Original line Diff line number Diff line
@@ -21,13 +21,10 @@
#include <string>
#include <string>


#include <ui/DisplayId.h>
#include <ui/DisplayId.h>
#include <ui/PixelFormat.h>
#include <ui/Size.h>
#include <ui/Size.h>
#include <ui/StaticDisplayInfo.h>
#include <ui/StaticDisplayInfo.h>


#include "DisplayHardware/DisplayIdentification.h"
#include "DisplayHardware/PowerAdvisor.h"
#include "DisplayHardware/PowerAdvisor.h"
#include "DisplayIdGenerator.h"


namespace android::compositionengine {
namespace android::compositionengine {


@@ -37,24 +34,14 @@ class CompositionEngine;
 * A parameter object for creating Display instances
 * A parameter object for creating Display instances
 */
 */
struct DisplayCreationArgs {
struct DisplayCreationArgs {
    struct Physical {
    DisplayId id;
    DisplayId id;
        ui::DisplayConnectionType type;
    };


    // Required for physical displays. Gives the HWC display id for the existing
    // Unset for virtual displays
    // display along with the connection type.
    std::optional<ui::DisplayConnectionType> connectionType;
    std::optional<Physical> physical;


    // Size of the display in pixels
    // Size of the display in pixels
    ui::Size pixels = ui::Size::INVALID;
    ui::Size pixels = ui::Size::INVALID;


    // Pixel format of the display
    ui::PixelFormat pixelFormat = static_cast<ui::PixelFormat>(PIXEL_FORMAT_UNKNOWN);

    // True if virtual displays should be created with the HWC API if possible
    bool useHwcVirtualDisplays = false;

    // True if this display should be considered secure
    // True if this display should be considered secure
    bool isSecure = false;
    bool isSecure = false;


@@ -67,9 +54,6 @@ struct DisplayCreationArgs {


    // Debugging. Human readable name for the display.
    // Debugging. Human readable name for the display.
    std::string name;
    std::string name;

    // Generator for IDs of virtual displays, which are backed by the GPU.
    DisplayIdGenerator<GpuVirtualDisplayId>* gpuVirtualDisplayIdGenerator;
};
};


/**
/**
@@ -80,29 +64,18 @@ class DisplayCreationArgsBuilder {
public:
public:
    DisplayCreationArgs build() { return std::move(mArgs); }
    DisplayCreationArgs build() { return std::move(mArgs); }


    DisplayCreationArgsBuilder& setPhysical(DisplayCreationArgs::Physical physical) {
    DisplayCreationArgsBuilder& setId(DisplayId id) {
        mArgs.physical = physical;
        mArgs.id = id;
        return *this;
    }

    DisplayCreationArgsBuilder& setPixels(ui::Size pixels) {
        mArgs.pixels = pixels;
        return *this;
        return *this;
    }
    }


    DisplayCreationArgsBuilder& setPixelFormat(ui::PixelFormat pixelFormat) {
    DisplayCreationArgsBuilder& setConnectionType(ui::DisplayConnectionType connectionType) {
        mArgs.pixelFormat = pixelFormat;
        mArgs.connectionType = connectionType;
        return *this;
        return *this;
    }
    }


    DisplayCreationArgsBuilder& setUseHwcVirtualDisplays(bool useHwcVirtualDisplays) {
    DisplayCreationArgsBuilder& setPixels(ui::Size pixels) {
        mArgs.useHwcVirtualDisplays = useHwcVirtualDisplays;
        mArgs.pixels = pixels;
        return *this;
    }

    DisplayCreationArgsBuilder& setGpuVirtualDisplayIdGenerator(
            DisplayIdGenerator<GpuVirtualDisplayId>& generator) {
        mArgs.gpuVirtualDisplayIdGenerator = &generator;
        return *this;
        return *this;
    }
    }


+14 −25
Original line number Original line Diff line number Diff line
@@ -24,21 +24,17 @@


struct ANativeWindow;
struct ANativeWindow;


namespace android {
namespace android::compositionengine {

namespace compositionengine {

class Display;


/**
/**
 * A parameter object for creating RenderSurface instances
 * A parameter object for creating RenderSurface instances
 */
 */
struct RenderSurfaceCreationArgs {
struct RenderSurfaceCreationArgs {
    // The initial width of the surface
    // The initial width of the surface
    int32_t displayWidth;
    int32_t displayWidth = -1;


    // The initial height of the surface
    // The initial height of the surface
    int32_t displayHeight;
    int32_t displayHeight = -1;


    // The ANativeWindow for the buffer queue for this surface
    // The ANativeWindow for the buffer queue for this surface
    sp<ANativeWindow> nativeWindow;
    sp<ANativeWindow> nativeWindow;
@@ -46,22 +42,16 @@ struct RenderSurfaceCreationArgs {
    // The DisplaySurface for this surface
    // The DisplaySurface for this surface
    sp<DisplaySurface> displaySurface;
    sp<DisplaySurface> displaySurface;


    size_t maxTextureCacheSize;
    // The maximum size of the renderengine::ExternalTexture cache
    size_t maxTextureCacheSize = 0;

private:
    friend class RenderSurfaceCreationArgsBuilder;

    // Not defaulted to disable aggregate initialization.
    RenderSurfaceCreationArgs() {}
};
};


/**
 * A helper for setting up a RenderSurfaceCreationArgs value in-line.
 * Prefer this builder over raw structure initialization.
 *
 * Instead of:
 *
 *   RenderSurfaceCreationArgs{1000, 1000, nativeWindow, displaySurface}
 *
 * Prefer:
 *
 *  RenderSurfaceCreationArgsBuilder().setDisplayWidth(1000).setDisplayHeight(1000)
 *      .setNativeWindow(nativeWindow).setDisplaySurface(displaySurface).Build();
 */
class RenderSurfaceCreationArgsBuilder {
class RenderSurfaceCreationArgsBuilder {
public:
public:
    RenderSurfaceCreationArgs build() { return std::move(mArgs); }
    RenderSurfaceCreationArgs build() { return std::move(mArgs); }
@@ -75,11 +65,11 @@ public:
        return *this;
        return *this;
    }
    }
    RenderSurfaceCreationArgsBuilder& setNativeWindow(sp<ANativeWindow> nativeWindow) {
    RenderSurfaceCreationArgsBuilder& setNativeWindow(sp<ANativeWindow> nativeWindow) {
        mArgs.nativeWindow = nativeWindow;
        mArgs.nativeWindow = std::move(nativeWindow);
        return *this;
        return *this;
    }
    }
    RenderSurfaceCreationArgsBuilder& setDisplaySurface(sp<DisplaySurface> displaySurface) {
    RenderSurfaceCreationArgsBuilder& setDisplaySurface(sp<DisplaySurface> displaySurface) {
        mArgs.displaySurface = displaySurface;
        mArgs.displaySurface = std::move(displaySurface);
        return *this;
        return *this;
    }
    }


@@ -92,5 +82,4 @@ private:
    RenderSurfaceCreationArgs mArgs;
    RenderSurfaceCreationArgs mArgs;
};
};


} // namespace compositionengine
} // namespace android::compositionengine
} // namespace android
+0 −6
Original line number Original line Diff line number Diff line
@@ -80,19 +80,13 @@ public:


    // Internal
    // Internal
    virtual void setConfiguration(const compositionengine::DisplayCreationArgs&);
    virtual void setConfiguration(const compositionengine::DisplayCreationArgs&);
    virtual std::optional<DisplayId> maybeAllocateDisplayIdForVirtualDisplay(ui::Size,
                                                                             ui::PixelFormat) const;
    std::unique_ptr<compositionengine::OutputLayer> createOutputLayer(const sp<LayerFE>&) const;
    std::unique_ptr<compositionengine::OutputLayer> createOutputLayer(const sp<LayerFE>&) const;


    // Testing
    void setDisplayIdForTesting(DisplayId displayId);

private:
private:
    bool mIsVirtual = false;
    bool mIsVirtual = false;
    bool mIsDisconnected = false;
    bool mIsDisconnected = false;
    DisplayId mId;
    DisplayId mId;
    Hwc2::PowerAdvisor* mPowerAdvisor = nullptr;
    Hwc2::PowerAdvisor* mPowerAdvisor = nullptr;
    DisplayIdGenerator<GpuVirtualDisplayId>* mGpuVirtualDisplayIdGenerator;
};
};


// This template factory function standardizes the implementation details of the
// This template factory function standardizes the implementation details of the
+6 −35
Original line number Original line Diff line number Diff line
@@ -50,36 +50,14 @@ std::shared_ptr<Display> createDisplay(
Display::~Display() = default;
Display::~Display() = default;


void Display::setConfiguration(const compositionengine::DisplayCreationArgs& args) {
void Display::setConfiguration(const compositionengine::DisplayCreationArgs& args) {
    mIsVirtual = !args.physical;
    mId = args.id;
    mIsVirtual = !args.connectionType;
    mPowerAdvisor = args.powerAdvisor;
    mPowerAdvisor = args.powerAdvisor;
    editState().isSecure = args.isSecure;
    editState().isSecure = args.isSecure;
    editState().displaySpace.bounds = Rect(args.pixels);
    editState().displaySpace.bounds = Rect(args.pixels);
    setLayerStackFilter(args.layerStackId,
    setLayerStackFilter(args.layerStackId,
                        args.physical &&
                        args.connectionType == ui::DisplayConnectionType::Internal);
                                args.physical->type == ui::DisplayConnectionType::Internal);
    setName(args.name);
    setName(args.name);
    mGpuVirtualDisplayIdGenerator = args.gpuVirtualDisplayIdGenerator;

    if (args.physical) {
        mId = args.physical->id;
    } else {
        std::optional<DisplayId> id;
        if (args.useHwcVirtualDisplays) {
            id = maybeAllocateDisplayIdForVirtualDisplay(args.pixels, args.pixelFormat);
        }
        if (!id) {
            id = mGpuVirtualDisplayIdGenerator->nextId();
        }
        LOG_ALWAYS_FATAL_IF(!id, "Failed to generate display ID");
        mId = *id;
    }
}

std::optional<DisplayId> Display::maybeAllocateDisplayIdForVirtualDisplay(
        ui::Size pixels, ui::PixelFormat pixelFormat) const {
    auto& hwc = getCompositionEngine().getHwComposer();
    return hwc.allocateVirtualDisplay(static_cast<uint32_t>(pixels.width),
                                      static_cast<uint32_t>(pixels.height), &pixelFormat);
}
}


bool Display::isValid() const {
bool Display::isValid() const {
@@ -102,23 +80,16 @@ std::optional<DisplayId> Display::getDisplayId() const {
    return mId;
    return mId;
}
}


void Display::setDisplayIdForTesting(DisplayId displayId) {
    mId = displayId;
}

void Display::disconnect() {
void Display::disconnect() {
    if (mIsDisconnected) {
    if (mIsDisconnected) {
        return;
        return;
    }
    }


    mIsDisconnected = true;
    mIsDisconnected = true;
    if (const auto id = GpuVirtualDisplayId::tryCast(mId)) {

        mGpuVirtualDisplayIdGenerator->markUnused(*id);
    if (const auto id = HalDisplayId::tryCast(mId)) {
        return;
        getCompositionEngine().getHwComposer().disconnectDisplay(*id);
    }
    }
    const auto halDisplayId = HalDisplayId::tryCast(mId);
    LOG_FATAL_IF(!halDisplayId);
    getCompositionEngine().getHwComposer().disconnectDisplay(*halDisplayId);
}
}


void Display::setColorTransform(const compositionengine::CompositionRefreshArgs& args) {
void Display::setColorTransform(const compositionengine::CompositionRefreshArgs& args) {
+121 −168

File changed.

Preview size limit exceeded, changes collapsed.

Loading