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

Commit 25d63287 authored by Chavi Weingarten's avatar Chavi Weingarten Committed by android-build-merger
Browse files

Merge "Disconnect from surface when the RenderSurface object is removed." into qt-dev

am: 27e6f2b5

Change-Id: I78d81f03d804afa9fc8ee21347fc1980b6bdd6b9
parents d792f838 27e6f2b5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ cc_library {
        "mock/DisplaySurface.cpp",
        "mock/Layer.cpp",
        "mock/LayerFE.cpp",
        "mock/NativeWindow.cpp",
        "mock/Output.cpp",
        "mock/OutputLayer.cpp",
        "mock/RenderSurface.cpp",
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 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 <gmock/gmock.h>
#include <system/window.h>
#include <ui/ANativeObjectBase.h>
#include <ui/GraphicTypes.h>
#include <ui/PixelFormat.h>

namespace android::compositionengine::mock {

/* ------------------------------------------------------------------------
 * Mock NativeWindow
 *
 * An intentionally simplified Mock which implements a minimal subset of the full
 * ANativeWindow interface.
 */
class NativeWindow : public ANativeObjectBase<ANativeWindow, NativeWindow, RefBase> {
public:
    NativeWindow();
    ~NativeWindow();

    MOCK_METHOD1(setSwapInterval, int(int));
    MOCK_METHOD2(dequeueBuffer, int(struct ANativeWindowBuffer**, int*));
    MOCK_METHOD2(cancelBuffer, int(struct ANativeWindowBuffer*, int));
    MOCK_METHOD2(queueBuffer, int(struct ANativeWindowBuffer*, int));
    MOCK_CONST_METHOD2(query, int(int, int*));
    MOCK_METHOD1(connect, int(int));
    MOCK_METHOD1(disconnect, int(int));
    MOCK_METHOD1(lockBuffer_DEPRECATED, int(struct ANativeWindowBuffer*));
    MOCK_METHOD1(setBuffersFormat, int(PixelFormat));
    MOCK_METHOD1(setBuffersDataSpace, int(ui::Dataspace));
    MOCK_METHOD1(setUsage, int(uint64_t));
};

} // namespace android::compositionengine::mock
+121 −0
Original line number Diff line number Diff line

/*
 * Copyright 2019 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.
 */

#include "compositionengine/mock/NativeWindow.h"
#include <log/log.h>

namespace android::compositionengine::mock {

static int forwardSetSwapInterval(ANativeWindow* window, int interval) {
    return static_cast<NativeWindow*>(window)->setSwapInterval(interval);
}

static int forwardDequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer, int* fenceFd) {
    return static_cast<NativeWindow*>(window)->dequeueBuffer(buffer, fenceFd);
}

static int forwardCancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) {
    return static_cast<NativeWindow*>(window)->cancelBuffer(buffer, fenceFd);
}

static int forwardQueueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd) {
    return static_cast<NativeWindow*>(window)->queueBuffer(buffer, fenceFd);
}

static int forwardQuery(const ANativeWindow* window, int what, int* value) {
    return static_cast<const NativeWindow*>(window)->query(what, value);
}

static int forwardPerform(ANativeWindow* window, int operation, ...) {
    va_list args;
    va_start(args, operation);
    int result = NO_ERROR;
    switch (operation) {
        case NATIVE_WINDOW_API_CONNECT: {
            int api = va_arg(args, int);
            result = static_cast<NativeWindow*>(window)->connect(api);
            break;
        }
        case NATIVE_WINDOW_SET_BUFFERS_FORMAT: {
            PixelFormat format = va_arg(args, PixelFormat);
            result = static_cast<NativeWindow*>(window)->setBuffersFormat(format);
            break;
        }
        case NATIVE_WINDOW_SET_BUFFERS_DATASPACE: {
            ui::Dataspace dataspace = static_cast<ui::Dataspace>(va_arg(args, int));
            result = static_cast<NativeWindow*>(window)->setBuffersDataSpace(dataspace);
            break;
        }
        case NATIVE_WINDOW_SET_USAGE: {
            // Note: Intentionally widens usage from 32 to 64 bits so we
            // just have one implementation.
            uint64_t usage = va_arg(args, uint32_t);
            result = static_cast<NativeWindow*>(window)->setUsage(usage);
            break;
        }
        case NATIVE_WINDOW_SET_USAGE64: {
            uint64_t usage = va_arg(args, uint64_t);
            result = static_cast<NativeWindow*>(window)->setUsage(usage);
            break;
        }
        case NATIVE_WINDOW_API_DISCONNECT: {
            int api = va_arg(args, int);
            result = static_cast<NativeWindow*>(window)->disconnect(api);
            break;
        }
        default:
            LOG_ALWAYS_FATAL("Unexpected operation %d", operation);
            break;
    }

    va_end(args);
    return result;
}

static int forwardDequeueBufferDeprecated(ANativeWindow* window, ANativeWindowBuffer** buffer) {
    int ignoredFenceFd = -1;
    return static_cast<NativeWindow*>(window)->dequeueBuffer(buffer, &ignoredFenceFd);
}

static int forwardCancelBufferDeprecated(ANativeWindow* window, ANativeWindowBuffer* buffer) {
    return static_cast<NativeWindow*>(window)->cancelBuffer(buffer, -1);
}

static int forwardLockBufferDeprecated(ANativeWindow* window, ANativeWindowBuffer* buffer) {
    return static_cast<NativeWindow*>(window)->lockBuffer_DEPRECATED(buffer);
}

static int forwardQueueBufferDeprecated(ANativeWindow* window, ANativeWindowBuffer* buffer) {
    return static_cast<NativeWindow*>(window)->queueBuffer(buffer, -1);
}

NativeWindow::NativeWindow() {
    ANativeWindow::setSwapInterval = &forwardSetSwapInterval;
    ANativeWindow::dequeueBuffer = &forwardDequeueBuffer;
    ANativeWindow::cancelBuffer = &forwardCancelBuffer;
    ANativeWindow::queueBuffer = &forwardQueueBuffer;
    ANativeWindow::query = &forwardQuery;
    ANativeWindow::perform = &forwardPerform;

    ANativeWindow::dequeueBuffer_DEPRECATED = &forwardDequeueBufferDeprecated;
    ANativeWindow::cancelBuffer_DEPRECATED = &forwardCancelBufferDeprecated;
    ANativeWindow::lockBuffer_DEPRECATED = &forwardLockBufferDeprecated;
    ANativeWindow::queueBuffer_DEPRECATED = &forwardQueueBufferDeprecated;
}
NativeWindow::~NativeWindow() = default;

} // namespace android::compositionengine::mock
+7 −2
Original line number Diff line number Diff line
@@ -52,9 +52,14 @@ RenderSurface::RenderSurface(const CompositionEngine& compositionEngine, Display
        mDisplay(display),
        mNativeWindow(args.nativeWindow),
        mDisplaySurface(args.displaySurface),
        mSize(args.displayWidth, args.displayHeight) {}
        mSize(args.displayWidth, args.displayHeight) {
    LOG_ALWAYS_FATAL_IF(!mNativeWindow);
}

RenderSurface::~RenderSurface() = default;
RenderSurface::~RenderSurface() {
    ANativeWindow* const window = mNativeWindow.get();
    native_window_api_disconnect(window, NATIVE_WINDOW_API_EGL);
}

bool RenderSurface::isValid() const {
    return mSize.isValid();
+4 −2
Original line number Diff line number Diff line
@@ -22,9 +22,9 @@
#include <compositionengine/RenderSurfaceCreationArgs.h>
#include <compositionengine/impl/Display.h>
#include <compositionengine/mock/CompositionEngine.h>
#include <compositionengine/mock/NativeWindow.h>
#include <compositionengine/mock/RenderSurface.h>
#include <gtest/gtest.h>
#include <system/window.h>

#include "MockHWComposer.h"

@@ -43,6 +43,7 @@ public:

    StrictMock<android::mock::HWComposer> mHwComposer;
    StrictMock<mock::CompositionEngine> mCompositionEngine;
    sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
    impl::Display mDisplay{mCompositionEngine,
                           DisplayCreationArgsBuilder().setDisplayId(DEFAULT_DISPLAY_ID).build()};
};
@@ -199,8 +200,9 @@ TEST_F(DisplayTest, createDisplayColorProfileSetsDisplayColorProfile) {
 */

TEST_F(DisplayTest, createRenderSurfaceSetsRenderSurface) {
    EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
    EXPECT_TRUE(mDisplay.getRenderSurface() == nullptr);
    mDisplay.createRenderSurface(RenderSurfaceCreationArgs{640, 480, nullptr, nullptr});
    mDisplay.createRenderSurface(RenderSurfaceCreationArgs{640, 480, mNativeWindow, nullptr});
    EXPECT_TRUE(mDisplay.getRenderSurface() != nullptr);
}

Loading