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

Commit 106d17f6 authored by Vishnu Nair's avatar Vishnu Nair Committed by Android (Google) Code Review
Browse files

Merge "SF: Make ExternalTexture mockable"

parents 338ee42d dbbe3854
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -14,30 +14,32 @@
 * limitations under the License.
 */

#include <renderengine/ExternalTexture.h>
#include <renderengine/RenderEngine.h>
#include <renderengine/impl/ExternalTexture.h>
#include <ui/GraphicBuffer.h>

#include "log/log_main.h"

namespace android::renderengine {
namespace android::renderengine::impl {

ExternalTexture::ExternalTexture(const sp<GraphicBuffer>& buffer, RenderEngine& renderEngine,
                                 uint32_t usage)
ExternalTexture::ExternalTexture(const sp<GraphicBuffer>& buffer,
                                 renderengine::RenderEngine& renderEngine, uint32_t usage)
      : mBuffer(buffer), mRenderEngine(renderEngine) {
    LOG_ALWAYS_FATAL_IF(buffer == nullptr,
                        "Attempted to bind a null buffer to an external texture!");
    // GLESRenderEngine has a separate texture cache for output buffers,
    if (usage == Usage::WRITEABLE &&
        (mRenderEngine.getRenderEngineType() == RenderEngine::RenderEngineType::GLES ||
         mRenderEngine.getRenderEngineType() == RenderEngine::RenderEngineType::THREADED)) {
    if (usage == WRITEABLE &&
        (mRenderEngine.getRenderEngineType() ==
                 renderengine::RenderEngine::RenderEngineType::GLES ||
         mRenderEngine.getRenderEngineType() ==
                 renderengine::RenderEngine::RenderEngineType::THREADED)) {
        return;
    }
    mRenderEngine.mapExternalTextureBuffer(mBuffer, usage & Usage::WRITEABLE);
    mRenderEngine.mapExternalTextureBuffer(mBuffer, usage & WRITEABLE);
}

ExternalTexture::~ExternalTexture() {
    mRenderEngine.unmapExternalTextureBuffer(mBuffer);
}

} // namespace android::renderengine
} // namespace android::renderengine::impl
+10 −9
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <renderengine/ExternalTexture.h>
#include <renderengine/LayerSettings.h>
#include <renderengine/RenderEngine.h>
#include <renderengine/impl/ExternalTexture.h>

#include <mutex>

@@ -115,15 +116,15 @@ static std::shared_ptr<ExternalTexture> allocateBuffer(RenderEngine& re, uint32_
                                                       uint32_t height,
                                                       uint64_t extraUsageFlags = 0,
                                                       std::string name = "output") {
    return std::make_shared<ExternalTexture>(new GraphicBuffer(width, height,
                                                               HAL_PIXEL_FORMAT_RGBA_8888, 1,
    return std::make_shared<
            impl::ExternalTexture>(new GraphicBuffer(width, height, HAL_PIXEL_FORMAT_RGBA_8888, 1,
                                                     GRALLOC_USAGE_HW_RENDER |
                                                             GRALLOC_USAGE_HW_TEXTURE |
                                                             extraUsageFlags,
                                                     std::move(name)),
                                   re,
                                             ExternalTexture::Usage::READABLE |
                                                     ExternalTexture::Usage::WRITEABLE);
                                   impl::ExternalTexture::Usage::READABLE |
                                           impl::ExternalTexture::Usage::WRITEABLE);
}

static std::shared_ptr<ExternalTexture> copyBuffer(RenderEngine& re,
+13 −19
Original line number Diff line number Diff line
@@ -33,28 +33,22 @@ class RenderEngine;
 */
class ExternalTexture {
public:
    // Usage specifies the rendering intent for the buffer.
    enum Usage : uint32_t {
        // When a buffer is not READABLE but is WRITEABLE, then GLESRenderEngine will use that as a
        // hint to load the buffer into a separate cache
        READABLE = 1 << 0,

        // The buffer needs to be mapped as a 2D texture if set, otherwise must be mapped as an
        // external texture
        WRITEABLE = 1 << 1,
    };
    // Creates an ExternalTexture for the provided buffer and RenderEngine instance, with the given
    // usage hint of type Usage.
    ExternalTexture(const sp<GraphicBuffer>& buffer, RenderEngine& renderEngine, uint32_t usage);
    ExternalTexture() = default;
    virtual ~ExternalTexture() = default;

    ~ExternalTexture();
    virtual bool hasSameBuffer(const ExternalTexture& other) const = 0;
    virtual uint32_t getWidth() const = 0;
    virtual uint32_t getHeight() const = 0;
    virtual uint64_t getId() const = 0;
    virtual PixelFormat getPixelFormat() const = 0;
    virtual uint64_t getUsage() const = 0;

    // Retrieves the buffer that is bound to this texture.
    const sp<GraphicBuffer>& getBuffer() const { return mBuffer; }
    virtual const sp<GraphicBuffer>& getBuffer() const = 0;

private:
    sp<GraphicBuffer> mBuffer;
    RenderEngine& mRenderEngine;
    Rect getBounds() const {
        return {0, 0, static_cast<int32_t>(getWidth()), static_cast<int32_t>(getHeight())};
    }
    DISALLOW_COPY_AND_ASSIGN(ExternalTexture);
};

+2 −1
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ class RenderEngineThreaded;

namespace impl {
class RenderEngine;
class ExternalTexture;
}

enum class Protection {
@@ -228,7 +229,7 @@ protected:
    // avoid any thread synchronization that may be required by directly calling postRenderCleanup.
    virtual bool canSkipPostRenderCleanup() const = 0;

    friend class ExternalTexture;
    friend class impl::ExternalTexture;
    friend class threaded::RenderEngineThreaded;
    friend class RenderEngineTest_cleanupPostRender_cleansUpOnce_Test;
    const RenderEngineType mRenderEngineType;
+60 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 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.
 */

#pragma once

#include <android-base/macros.h>
#include <renderengine/ExternalTexture.h>
#include <ui/GraphicBuffer.h>

namespace android::renderengine::impl {

class RenderEngine;

class ExternalTexture : public android::renderengine::ExternalTexture {
public:
    // Usage specifies the rendering intent for the buffer.
    enum Usage : uint32_t {
        // When a buffer is not READABLE but is WRITEABLE, then GLESRenderEngine will use that as a
        // hint to load the buffer into a separate cache
        READABLE = 1 << 0,

        // The buffer needs to be mapped as a 2D texture if set, otherwise must be mapped as an
        // external texture
        WRITEABLE = 1 << 1,
    };

    // Creates an ExternalTexture for the provided buffer and RenderEngine instance, with the given
    // usage hint of type Usage.
    ExternalTexture(const sp<GraphicBuffer>& buffer,
                    android::renderengine::RenderEngine& renderEngine, uint32_t usage);
    ~ExternalTexture();
    const sp<GraphicBuffer>& getBuffer() const override { return mBuffer; };
    uint32_t getWidth() const override { return getBuffer()->getWidth(); }
    uint32_t getHeight() const override { return getBuffer()->getHeight(); }
    uint64_t getId() const override { return getBuffer()->getId(); }
    PixelFormat getPixelFormat() const override { return getBuffer()->getPixelFormat(); }
    uint64_t getUsage() const override { return getBuffer()->getUsage(); }
    bool hasSameBuffer(const renderengine::ExternalTexture& other) const override {
        return getBuffer() == other.getBuffer();
    }

private:
    sp<GraphicBuffer> mBuffer;
    android::renderengine::RenderEngine& mRenderEngine;
};

} // namespace android::renderengine::impl
Loading