blob: 59ed72e928f41b81f8816d501ab56bfec911c843 [file] [log] [blame]
/*
* 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 <cmath>
#include <android-base/stringprintf.h>
#include <compositionengine/LayerFECompositionState.h>
#include <compositionengine/impl/Output.h>
#include <compositionengine/impl/OutputCompositionState.h>
#include <compositionengine/impl/OutputLayerCompositionState.h>
#include <compositionengine/mock/CompositionEngine.h>
#include <compositionengine/mock/DisplayColorProfile.h>
#include <compositionengine/mock/LayerFE.h>
#include <compositionengine/mock/OutputLayer.h>
#include <compositionengine/mock/RenderSurface.h>
#include <gtest/gtest.h>
#include <renderengine/mock/RenderEngine.h>
#include <ui/Rect.h>
#include <ui/Region.h>
#include "CallOrderStateMachineHelper.h"
#include "MockHWC2.h"
#include "RegionMatcher.h"
namespace android::compositionengine {
namespace {
using testing::_;
using testing::ByMove;
using testing::ByRef;
using testing::DoAll;
using testing::ElementsAre;
using testing::ElementsAreArray;
using testing::Eq;
using testing::InSequence;
using testing::Invoke;
using testing::IsEmpty;
using testing::Mock;
using testing::Pointee;
using testing::Property;
using testing::Ref;
using testing::Return;
using testing::ReturnRef;
using testing::SetArgPointee;
using testing::StrictMock;
constexpr auto TR_IDENT = 0u;
constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
constexpr auto MAX_CLIENT_COMPOSITION_CACHE_SIZE = 3;
const mat4 kIdentity;
const mat4 kNonIdentityHalf = mat4() * 0.5f;
const mat4 kNonIdentityQuarter = mat4() * 0.25f;
constexpr OutputColorSetting kVendorSpecifiedOutputColorSetting =
static_cast<OutputColorSetting>(0x100);
struct OutputPartialMockBase : public impl::Output {
// compositionengine::Output overrides
const OutputCompositionState& getState() const override { return mState; }
OutputCompositionState& editState() override { return mState; }
// Use mocks for all the remaining virtual functions
// not implemented by the base implementation class.
MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, compositionengine::OutputLayer*(size_t));
MOCK_METHOD2(ensureOutputLayer,
compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
MOCK_METHOD0(finalizePendingOutputLayers, void());
MOCK_METHOD0(clearOutputLayers, void());
MOCK_CONST_METHOD1(dumpState, void(std::string&));
MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&());
MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
impl::OutputCompositionState mState;
};
struct InjectedLayer {
InjectedLayer() {
EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get()));
EXPECT_CALL(*outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
EXPECT_CALL(*outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
}
mock::OutputLayer* outputLayer = {new StrictMock<mock::OutputLayer>};
sp<StrictMock<mock::LayerFE>> layerFE = new StrictMock<mock::LayerFE>();
LayerFECompositionState layerFEState;
impl::OutputLayerCompositionState outputLayerState;
};
struct NonInjectedLayer {
NonInjectedLayer() {
EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get()));
EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
}
mock::OutputLayer outputLayer;
sp<StrictMock<mock::LayerFE>> layerFE = new StrictMock<mock::LayerFE>();
LayerFECompositionState layerFEState;
impl::OutputLayerCompositionState outputLayerState;
};
struct OutputTest : public testing::Test {
class Output : public impl::Output {
public:
using impl::Output::injectOutputLayerForTest;
virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
};
static std::shared_ptr<Output> createOutput(
const compositionengine::CompositionEngine& compositionEngine) {
return impl::createOutputTemplated<Output>(compositionEngine);
}
OutputTest() {
mOutput->setDisplayColorProfileForTest(
std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
mOutput->editState().bounds = kDefaultDisplaySize;
}
void injectOutputLayer(InjectedLayer& layer) {
mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(layer.outputLayer));
}
void injectNullOutputLayer() {
mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(nullptr));
}
static const Rect kDefaultDisplaySize;
StrictMock<mock::CompositionEngine> mCompositionEngine;
mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
std::shared_ptr<Output> mOutput = createOutput(mCompositionEngine);
};
const Rect OutputTest::kDefaultDisplaySize{100, 200};
using ColorProfile = compositionengine::Output::ColorProfile;
void dumpColorProfile(ColorProfile profile, std::string& result, const char* name) {
android::base::StringAppendF(&result, "%s (%s[%d] %s[%d] %s[%d] %s[%d]) ", name,
toString(profile.mode).c_str(), profile.mode,
toString(profile.dataspace).c_str(), profile.dataspace,
toString(profile.renderIntent).c_str(), profile.renderIntent,
toString(profile.colorSpaceAgnosticDataspace).c_str(),
profile.colorSpaceAgnosticDataspace);
}
// Checks for a ColorProfile match
MATCHER_P(ColorProfileEq, expected, "") {
std::string buf;
buf.append("ColorProfiles are not equal\n");
dumpColorProfile(expected, buf, "expected value");
dumpColorProfile(arg, buf, "actual value");
*result_listener << buf;
return (expected.mode == arg.mode) && (expected.dataspace == arg.dataspace) &&
(expected.renderIntent == arg.renderIntent) &&
(expected.colorSpaceAgnosticDataspace == arg.colorSpaceAgnosticDataspace);
}
/*
* Basic construction
*/
TEST_F(OutputTest, canInstantiateOutput) {
// The validation check checks each required component.
EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true));
EXPECT_TRUE(mOutput->isValid());
// If we take away the required components, it is no longer valid.
mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>());
EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
EXPECT_FALSE(mOutput->isValid());
}
/*
* Output::setCompositionEnabled()
*/
TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) {
mOutput->editState().isEnabled = true;
mOutput->setCompositionEnabled(true);
EXPECT_TRUE(mOutput->getState().isEnabled);
EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
}
TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) {
mOutput->editState().isEnabled = false;
mOutput->setCompositionEnabled(true);
EXPECT_TRUE(mOutput->getState().isEnabled);
EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
}
TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) {
mOutput->editState().isEnabled = true;
mOutput->setCompositionEnabled(false);
EXPECT_FALSE(mOutput->getState().isEnabled);
EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
}
/*
* Output::setProjection()
*/
TEST_F(OutputTest, setProjectionTriviallyWorks) {
const ui::Transform transform{ui::Transform::ROT_180};
const int32_t orientation = 123;
const Rect frame{1, 2, 3, 4};
const Rect viewport{5, 6, 7, 8};
const Rect sourceClip{9, 10, 11, 12};
const Rect destinationClip{13, 14, 15, 16};
const bool needsFiltering = true;
mOutput->setProjection(transform, orientation, frame, viewport, sourceClip, destinationClip,
needsFiltering);
EXPECT_THAT(mOutput->getState().transform, transform);
EXPECT_EQ(orientation, mOutput->getState().orientation);
EXPECT_EQ(frame, mOutput->getState().frame);
EXPECT_EQ(viewport, mOutput->getState().viewport);
EXPECT_EQ(sourceClip, mOutput->getState().sourceClip);
EXPECT_EQ(destinationClip, mOutput->getState().destinationClip);
EXPECT_EQ(needsFiltering, mOutput->getState().needsFiltering);
}
/*
* Output::setBounds()
*/
TEST_F(OutputTest, setBoundsSetsSizeAndDirtiesEntireOutput) {
const ui::Size displaySize{200, 400};
EXPECT_CALL(*mRenderSurface, setDisplaySize(displaySize)).Times(1);
EXPECT_CALL(*mRenderSurface, getSize()).WillOnce(ReturnRef(displaySize));
mOutput->setBounds(displaySize);
EXPECT_EQ(Rect(displaySize), mOutput->getState().bounds);
EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(Rect(displaySize))));
}
/*
* Output::setLayerStackFilter()
*/
TEST_F(OutputTest, setLayerStackFilterSetsFilterAndDirtiesEntireOutput) {
const uint32_t layerStack = 123u;
mOutput->setLayerStackFilter(layerStack, true);
EXPECT_TRUE(mOutput->getState().layerStackInternal);
EXPECT_EQ(layerStack, mOutput->getState().layerStackId);
EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
}
/*
* Output::setColorTransform
*/
TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) {
mOutput->editState().colorTransformMatrix = kIdentity;
// If no colorTransformMatrix is set the update should be skipped.
CompositionRefreshArgs refreshArgs;
refreshArgs.colorTransformMatrix = std::nullopt;
mOutput->setColorTransform(refreshArgs);
// The internal state should be unchanged
EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
// No dirty region should be set
EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
}
TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) {
mOutput->editState().colorTransformMatrix = kIdentity;
// Attempting to set the same colorTransformMatrix that is already set should
// also skip the update.
CompositionRefreshArgs refreshArgs;
refreshArgs.colorTransformMatrix = kIdentity;
mOutput->setColorTransform(refreshArgs);
// The internal state should be unchanged
EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
// No dirty region should be set
EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
}
TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) {
mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
// Setting a different colorTransformMatrix should perform the update.
CompositionRefreshArgs refreshArgs;
refreshArgs.colorTransformMatrix = kIdentity;
mOutput->setColorTransform(refreshArgs);
// The internal state should have been updated
EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
// The dirtyRegion should be set to the full display size
EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
}
TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) {
mOutput->editState().colorTransformMatrix = kIdentity;
// Setting a different colorTransformMatrix should perform the update.
CompositionRefreshArgs refreshArgs;
refreshArgs.colorTransformMatrix = kNonIdentityHalf;
mOutput->setColorTransform(refreshArgs);
// The internal state should have been updated
EXPECT_EQ(kNonIdentityHalf, mOutput->getState().colorTransformMatrix);
// The dirtyRegion should be set to the full display size
EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
}
TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) {
mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
// Setting a different colorTransformMatrix should perform the update.
CompositionRefreshArgs refreshArgs;
refreshArgs.colorTransformMatrix = kNonIdentityQuarter;
mOutput->setColorTransform(refreshArgs);
// The internal state should have been updated
EXPECT_EQ(kNonIdentityQuarter, mOutput->getState().colorTransformMatrix);
// The dirtyRegion should be set to the full display size
EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
}
/*
* Output::setColorProfile
*/
using OutputSetColorProfileTest = OutputTest;
TEST_F(OutputSetColorProfileTest, setsStateAndDirtiesOutputIfChanged) {
using ColorProfile = Output::ColorProfile;
EXPECT_CALL(*mDisplayColorProfile,
getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
ui::Dataspace::UNKNOWN))
.WillOnce(Return(ui::Dataspace::UNKNOWN));
EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
ui::RenderIntent::TONE_MAP_COLORIMETRIC,
ui::Dataspace::UNKNOWN});
EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput->getState().colorMode);
EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput->getState().dataspace);
EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput->getState().renderIntent);
EXPECT_EQ(ui::Dataspace::UNKNOWN, mOutput->getState().targetDataspace);
EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
}
TEST_F(OutputSetColorProfileTest, doesNothingIfNoChange) {
using ColorProfile = Output::ColorProfile;
EXPECT_CALL(*mDisplayColorProfile,
getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
ui::Dataspace::UNKNOWN))
.WillOnce(Return(ui::Dataspace::UNKNOWN));
mOutput->editState().colorMode = ui::ColorMode::DISPLAY_P3;
mOutput->editState().dataspace = ui::Dataspace::DISPLAY_P3;
mOutput->editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC;
mOutput->editState().targetDataspace = ui::Dataspace::UNKNOWN;
mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
ui::RenderIntent::TONE_MAP_COLORIMETRIC,
ui::Dataspace::UNKNOWN});
EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
}
/*
* Output::setRenderSurface()
*/
TEST_F(OutputTest, setRenderSurfaceResetsBounds) {
const ui::Size newDisplaySize{640, 480};
mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize));
mOutput->setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface));
EXPECT_EQ(Rect(newDisplaySize), mOutput->getState().bounds);
}
/*
* Output::getDirtyRegion()
*/
TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingTrue) {
const Rect viewport{100, 200};
mOutput->editState().viewport = viewport;
mOutput->editState().dirtyRegion.set(50, 300);
{
Region result = mOutput->getDirtyRegion(true);
EXPECT_THAT(result, RegionEq(Region(viewport)));
}
}
TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingFalse) {
const Rect viewport{100, 200};
mOutput->editState().viewport = viewport;
mOutput->editState().dirtyRegion.set(50, 300);
{
Region result = mOutput->getDirtyRegion(false);
// The dirtyRegion should be clipped to the display bounds.
EXPECT_THAT(result, RegionEq(Region(Rect(50, 200))));
}
}
/*
* Output::belongsInOutput()
*/
TEST_F(OutputTest, belongsInOutputFiltersAsExpected) {
const uint32_t layerStack1 = 123u;
const uint32_t layerStack2 = 456u;
// If the output accepts layerStack1 and internal-only layers....
mOutput->setLayerStackFilter(layerStack1, true);
// A layer with no layerStack does not belong to it, internal-only or not.
EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, false));
EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, true));
// Any layer with layerStack1 belongs to it, internal-only or not.
EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false));
EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, true));
EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true));
EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false));
// If the output accepts layerStack21 but not internal-only layers...
mOutput->setLayerStackFilter(layerStack1, false);
// Only non-internal layers with layerStack1 belong to it.
EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false));
EXPECT_FALSE(mOutput->belongsInOutput(layerStack1, true));
EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true));
EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false));
}
TEST_F(OutputTest, belongsInOutputHandlesLayerWithNoCompositionState) {
NonInjectedLayer layer;
sp<LayerFE> layerFE(layer.layerFE);
// If the layer has no composition state, it does not belong to any output.
EXPECT_CALL(*layer.layerFE, getCompositionState).WillOnce(Return(nullptr));
EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
}
TEST_F(OutputTest, belongsInOutputFiltersLayersAsExpected) {
NonInjectedLayer layer;
sp<LayerFE> layerFE(layer.layerFE);
const uint32_t layerStack1 = 123u;
const uint32_t layerStack2 = 456u;
// If the output accepts layerStack1 and internal-only layers....
mOutput->setLayerStackFilter(layerStack1, true);
// A layer with no layerStack does not belong to it, internal-only or not.
layer.layerFEState.layerStackId = std::nullopt;
layer.layerFEState.internalOnly = false;
EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
layer.layerFEState.layerStackId = std::nullopt;
layer.layerFEState.internalOnly = true;
EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
// Any layer with layerStack1 belongs to it, internal-only or not.
layer.layerFEState.layerStackId = layerStack1;
layer.layerFEState.internalOnly = false;
EXPECT_TRUE(mOutput->belongsInOutput(layerFE));
layer.layerFEState.layerStackId = layerStack1;
layer.layerFEState.internalOnly = true;
EXPECT_TRUE(mOutput->belongsInOutput(layerFE));
layer.layerFEState.layerStackId = layerStack2;
layer.layerFEState.internalOnly = true;
EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
layer.layerFEState.layerStackId = layerStack2;
layer.layerFEState.internalOnly = false;
EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
// If the output accepts layerStack1 but not internal-only layers...
mOutput->setLayerStackFilter(layerStack1, false);
// Only non-internal layers with layerStack1 belong to it.
layer.layerFEState.layerStackId = layerStack1;
layer.layerFEState.internalOnly = false;
EXPECT_TRUE(mOutput->belongsInOutput(layerFE));
layer.layerFEState.layerStackId = layerStack1;
layer.layerFEState.internalOnly = true;
EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
layer.layerFEState.layerStackId = layerStack2;
layer.layerFEState.internalOnly = true;
EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
layer.layerFEState.layerStackId = layerStack2;
layer.layerFEState.internalOnly = false;
EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
}
/*
* Output::getOutputLayerForLayer()
*/
TEST_F(OutputTest, getOutputLayerForLayerWorks) {
InjectedLayer layer1;
InjectedLayer layer2;
NonInjectedLayer layer3;
injectOutputLayer(layer1);
injectNullOutputLayer();
injectOutputLayer(layer2);
// If the input layer matches the first OutputLayer, it will be returned.
EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
EXPECT_EQ(layer1.outputLayer, mOutput->getOutputLayerForLayer(layer1.layerFE));
// If the input layer matches the second OutputLayer, it will be returned.
EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get()));
EXPECT_EQ(layer2.outputLayer, mOutput->getOutputLayerForLayer(layer2.layerFE));
// If the input layer does not match an output layer, null will be returned.
EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get()));
EXPECT_EQ(nullptr, mOutput->getOutputLayerForLayer(layer3.layerFE));
}
/*
* Output::setReleasedLayers()
*/
using OutputSetReleasedLayersTest = OutputTest;
TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) {
sp<StrictMock<mock::LayerFE>> layer1FE{new StrictMock<mock::LayerFE>()};
sp<StrictMock<mock::LayerFE>> layer2FE{new StrictMock<mock::LayerFE>()};
sp<StrictMock<mock::LayerFE>> layer3FE{new StrictMock<mock::LayerFE>()};
Output::ReleasedLayers layers;
layers.push_back(layer1FE);
layers.push_back(layer2FE);
layers.push_back(layer3FE);
mOutput->setReleasedLayers(std::move(layers));
const auto& setLayers = mOutput->getReleasedLayersForTest();
ASSERT_EQ(3u, setLayers.size());
ASSERT_EQ(layer1FE.get(), setLayers[0].promote().get());
ASSERT_EQ(layer2FE.get(), setLayers[1].promote().get());
ASSERT_EQ(layer3FE.get(), setLayers[2].promote().get());
}
/*
* Output::updateLayerStateFromFE()
*/
using OutputUpdateLayerStateFromFETest = OutputTest;
TEST_F(OutputUpdateLayerStateFromFETest, handlesNoOutputLayerCase) {
CompositionRefreshArgs refreshArgs;
mOutput->updateLayerStateFromFE(refreshArgs);
}
TEST_F(OutputUpdateLayerStateFromFETest, preparesContentStateForAllContainedLayers) {
InjectedLayer layer1;
InjectedLayer layer2;
InjectedLayer layer3;
EXPECT_CALL(*layer1.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content));
EXPECT_CALL(*layer2.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content));
EXPECT_CALL(*layer3.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content));
injectOutputLayer(layer1);
injectOutputLayer(layer2);
injectOutputLayer(layer3);
CompositionRefreshArgs refreshArgs;
refreshArgs.updatingGeometryThisFrame = false;
mOutput->updateLayerStateFromFE(refreshArgs);
}
TEST_F(OutputUpdateLayerStateFromFETest, preparesGeometryAndContentStateForAllContainedLayers) {
InjectedLayer layer1;
InjectedLayer layer2;
InjectedLayer layer3;
EXPECT_CALL(*layer1.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent));
EXPECT_CALL(*layer2.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent));
EXPECT_CALL(*layer3.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent));
injectOutputLayer(layer1);
injectOutputLayer(layer2);
injectOutputLayer(layer3);
CompositionRefreshArgs refreshArgs;
refreshArgs.updatingGeometryThisFrame = true;
mOutput->updateLayerStateFromFE(refreshArgs);
}
/*
* Output::updateAndWriteCompositionState()
*/
using OutputUpdateAndWriteCompositionStateTest = OutputTest;
TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfLayers) {
mOutput->editState().isEnabled = true;
CompositionRefreshArgs args;
mOutput->updateAndWriteCompositionState(args);
}
TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfOutputNotEnabled) {
InjectedLayer layer1;
InjectedLayer layer2;
InjectedLayer layer3;
mOutput->editState().isEnabled = false;
injectOutputLayer(layer1);
injectOutputLayer(layer2);
injectOutputLayer(layer3);
CompositionRefreshArgs args;
mOutput->updateAndWriteCompositionState(args);
}
TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerContentForAllLayers) {
InjectedLayer layer1;
InjectedLayer layer2;
InjectedLayer layer3;
EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
EXPECT_CALL(*layer1.outputLayer, writeStateToHWC(false));
EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
EXPECT_CALL(*layer2.outputLayer, writeStateToHWC(false));
EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
EXPECT_CALL(*layer3.outputLayer, writeStateToHWC(false));
injectOutputLayer(layer1);
injectOutputLayer(layer2);
injectOutputLayer(layer3);
mOutput->editState().isEnabled = true;
CompositionRefreshArgs args;
args.updatingGeometryThisFrame = false;
args.devOptForceClientComposition = false;
args.internalDisplayRotationFlags = ui::Transform::ROT_180;
mOutput->updateAndWriteCompositionState(args);
}
TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerGeometryAndContentForAllLayers) {
InjectedLayer layer1;
InjectedLayer layer2;
InjectedLayer layer3;
EXPECT_CALL(*layer1.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
EXPECT_CALL(*layer1.outputLayer, writeStateToHWC(true));
EXPECT_CALL(*layer2.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
EXPECT_CALL(*layer2.outputLayer, writeStateToHWC(true));
EXPECT_CALL(*layer3.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
EXPECT_CALL(*layer3.outputLayer, writeStateToHWC(true));
injectOutputLayer(layer1);
injectOutputLayer(layer2);
injectOutputLayer(layer3);
mOutput->editState().isEnabled = true;
CompositionRefreshArgs args;
args.updatingGeometryThisFrame = true;
args.devOptForceClientComposition = false;
mOutput->updateAndWriteCompositionState(args);
}
TEST_F(OutputUpdateAndWriteCompositionStateTest, forcesClientCompositionForAllLayers) {
InjectedLayer layer1;
InjectedLayer layer2;
InjectedLayer layer3;
EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
EXPECT_CALL(*layer1.outputLayer, writeStateToHWC(false));
EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
EXPECT_CALL(*layer2.outputLayer, writeStateToHWC(false));
EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
EXPECT_CALL(*layer3.outputLayer, writeStateToHWC(false));
injectOutputLayer(layer1);
injectOutputLayer(layer2);
injectOutputLayer(layer3);
mOutput->editState().isEnabled = true;
CompositionRefreshArgs args;
args.updatingGeometryThisFrame = false;
args.devOptForceClientComposition = true;
mOutput->updateAndWriteCompositionState(args);
}
/*
* Output::prepareFrame()
*/
struct OutputPrepareFrameTest : public testing::Test {
struct OutputPartialMock : public OutputPartialMockBase {
// Sets up the helper functions called by the function under test to use
// mock implementations.
MOCK_METHOD0(chooseCompositionStrategy, void());
};
OutputPrepareFrameTest() {
mOutput.setDisplayColorProfileForTest(
std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
}
StrictMock<mock::CompositionEngine> mCompositionEngine;
mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
StrictMock<OutputPartialMock> mOutput;
};
TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) {
mOutput.editState().isEnabled = false;
mOutput.prepareFrame();
}
TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) {
mOutput.editState().isEnabled = true;
mOutput.editState().usesClientComposition = false;
mOutput.editState().usesDeviceComposition = true;
EXPECT_CALL(mOutput, chooseCompositionStrategy()).Times(1);
EXPECT_CALL(*mRenderSurface, prepareFrame(false, true));
mOutput.prepareFrame();
}
// Note: Use OutputTest and not OutputPrepareFrameTest, so the real
// base chooseCompositionStrategy() is invoked.
TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) {
mOutput->editState().isEnabled = true;
mOutput->editState().usesClientComposition = false;
mOutput->editState().usesDeviceComposition = true;
EXPECT_CALL(*mRenderSurface, prepareFrame(true, false));
mOutput->prepareFrame();
EXPECT_TRUE(mOutput->getState().usesClientComposition);
EXPECT_FALSE(mOutput->getState().usesDeviceComposition);
}
/*
* Output::prepare()
*/
struct OutputPrepareTest : public testing::Test {
struct OutputPartialMock : public OutputPartialMockBase {
// Sets up the helper functions called by the function under test to use
// mock implementations.
MOCK_METHOD2(rebuildLayerStacks,
void(const compositionengine::CompositionRefreshArgs&,
compositionengine::LayerFESet&));
};
StrictMock<OutputPartialMock> mOutput;
CompositionRefreshArgs mRefreshArgs;
LayerFESet mGeomSnapshots;
};
TEST_F(OutputPrepareTest, justInvokesRebuildLayerStacks) {
InSequence seq;
EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots)));
mOutput.prepare(mRefreshArgs, mGeomSnapshots);
}
/*
* Output::rebuildLayerStacks()
*/
struct OutputRebuildLayerStacksTest : public testing::Test {
struct OutputPartialMock : public OutputPartialMockBase {
// Sets up the helper functions called by the function under test to use
// mock implementations.
MOCK_METHOD2(collectVisibleLayers,
void(const compositionengine::CompositionRefreshArgs&,
compositionengine::Output::CoverageState&));
};
OutputRebuildLayerStacksTest() {
mOutput.mState.isEnabled = true;
mOutput.mState.transform = kIdentityTransform;
mOutput.mState.bounds = kOutputBounds;
mRefreshArgs.updatingOutputGeometryThisFrame = true;
mCoverageAboveCoveredLayersToSet = Region(Rect(0, 0, 10, 10));
EXPECT_CALL(mOutput, collectVisibleLayers(Ref(mRefreshArgs), _))
.WillRepeatedly(Invoke(this, &OutputRebuildLayerStacksTest::setTestCoverageValues));
}
void setTestCoverageValues(const CompositionRefreshArgs&,
compositionengine::Output::CoverageState& state) {
state.aboveCoveredLayers = mCoverageAboveCoveredLayersToSet;
state.aboveOpaqueLayers = mCoverageAboveOpaqueLayersToSet;
state.dirtyRegion = mCoverageDirtyRegionToSet;
}
static const ui::Transform kIdentityTransform;
static const ui::Transform kRotate90Transform;
static const Rect kOutputBounds;
StrictMock<OutputPartialMock> mOutput;
CompositionRefreshArgs mRefreshArgs;
LayerFESet mGeomSnapshots;
Region mCoverageAboveCoveredLayersToSet;
Region mCoverageAboveOpaqueLayersToSet;
Region mCoverageDirtyRegionToSet;
};
const ui::Transform OutputRebuildLayerStacksTest::kIdentityTransform{TR_IDENT, 1920, 1080};
const ui::Transform OutputRebuildLayerStacksTest::kRotate90Transform{TR_ROT_90, 1920, 1080};
const Rect OutputRebuildLayerStacksTest::kOutputBounds{0, 0, 1920, 1080};
TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotEnabled) {
mOutput.mState.isEnabled = false;
mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
}
TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotUpdatingGeometryThisFrame) {
mRefreshArgs.updatingOutputGeometryThisFrame = false;
mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
}
TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndFullCoverage) {
mOutput.mState.transform = kIdentityTransform;
mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1920, 1080));
mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
}
TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndPartialCoverage) {
mOutput.mState.transform = kIdentityTransform;
mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 960, 1080));
mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(960, 0, 1920, 1080))));
}
TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndFullCoverage) {
mOutput.mState.transform = kRotate90Transform;
mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 1920));
mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
}
TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndPartialCoverage) {
mOutput.mState.transform = kRotate90Transform;
mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 960));
mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 960, 1080))));
}
TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWithNoRotation) {
mOutput.mState.transform = kIdentityTransform;
mOutput.mState.dirtyRegion = Region(Rect(960, 0, 1920, 1080));
mCoverageDirtyRegionToSet = Region(Rect(0, 0, 960, 1080));
mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1920, 1080))));
}
TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWith90Rotation) {
mOutput.mState.transform = kRotate90Transform;
mOutput.mState.dirtyRegion = Region(Rect(0, 960, 1080, 1920));
mCoverageDirtyRegionToSet = Region(Rect(0, 0, 1080, 960));
mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1080, 1920))));
}
/*
* Output::collectVisibleLayers()
*/
struct OutputCollectVisibleLayersTest : public testing::Test {
struct OutputPartialMock : public OutputPartialMockBase {
// Sets up the helper functions called by the function under test to use
// mock implementations.
MOCK_METHOD2(ensureOutputLayerIfVisible,
void(sp<compositionengine::LayerFE>&,
compositionengine::Output::CoverageState&));
MOCK_METHOD1(setReleasedLayers, void(const compositionengine::CompositionRefreshArgs&));
MOCK_METHOD0(finalizePendingOutputLayers, void());
};
struct Layer {
Layer() {
EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
}
StrictMock<mock::OutputLayer> outputLayer;
impl::OutputLayerCompositionState outputLayerState;
sp<StrictMock<mock::LayerFE>> layerFE{new StrictMock<mock::LayerFE>()};
};
OutputCollectVisibleLayersTest() {
EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
.WillRepeatedly(Return(&mLayer1.outputLayer));
EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
.WillRepeatedly(Return(&mLayer2.outputLayer));
EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
.WillRepeatedly(Return(&mLayer3.outputLayer));
mRefreshArgs.layers.push_back(mLayer1.layerFE);
mRefreshArgs.layers.push_back(mLayer2.layerFE);
mRefreshArgs.layers.push_back(mLayer3.layerFE);
}
StrictMock<OutputPartialMock> mOutput;
CompositionRefreshArgs mRefreshArgs;
LayerFESet mGeomSnapshots;
Output::CoverageState mCoverageState{mGeomSnapshots};
Layer mLayer1;
Layer mLayer2;
Layer mLayer3;
};
TEST_F(OutputCollectVisibleLayersTest, doesMinimalWorkIfNoLayers) {
mRefreshArgs.layers.clear();
EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
EXPECT_CALL(mOutput, finalizePendingOutputLayers());
mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
}
TEST_F(OutputCollectVisibleLayersTest, processesCandidateLayersReversedAndSetsOutputLayerZ) {
// Enforce a call order sequence for this test.
InSequence seq;
// Layer coverage is evaluated from front to back!
EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer3.layerFE), Ref(mCoverageState)));
EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer2.layerFE), Ref(mCoverageState)));
EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer1.layerFE), Ref(mCoverageState)));
EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
EXPECT_CALL(mOutput, finalizePendingOutputLayers());
mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
// Ensure all output layers have been assigned a simple/flattened z-order.
EXPECT_EQ(0u, mLayer1.outputLayerState.z);
EXPECT_EQ(1u, mLayer2.outputLayerState.z);
EXPECT_EQ(2u, mLayer3.outputLayerState.z);
}
/*
* Output::ensureOutputLayerIfVisible()
*/
struct OutputEnsureOutputLayerIfVisibleTest : public testing::Test {
struct OutputPartialMock : public OutputPartialMockBase {
// Sets up the helper functions called by the function under test to use
// mock implementations.
MOCK_CONST_METHOD1(belongsInOutput, bool(const sp<compositionengine::LayerFE>&));
MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, OutputLayer*(size_t));
MOCK_METHOD2(ensureOutputLayer,
compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
};
OutputEnsureOutputLayerIfVisibleTest() {
EXPECT_CALL(mOutput, belongsInOutput(sp<LayerFE>(mLayer.layerFE)))
.WillRepeatedly(Return(true));
EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
.WillRepeatedly(Return(&mLayer.outputLayer));
mOutput.mState.bounds = Rect(0, 0, 200, 300);
mOutput.mState.viewport = Rect(0, 0, 200, 300);
mOutput.mState.transform = ui::Transform(TR_IDENT, 200, 300);
mLayer.layerFEState.isVisible = true;
mLayer.layerFEState.isOpaque = true;
mLayer.layerFEState.contentDirty = true;
mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
mLayer.layerFEState.transparentRegionHint = Region(Rect(0, 0, 100, 100));
mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 50, 200));
mLayer.outputLayerState.coveredRegion = Region(Rect(50, 0, 100, 200));
mGeomSnapshots.insert(mLayer.layerFE);
}
void ensureOutputLayerIfVisible() {
sp<LayerFE> layerFE(mLayer.layerFE);
mOutput.ensureOutputLayerIfVisible(layerFE, mCoverageState);
}
static const Region kEmptyRegion;
static const Region kFullBoundsNoRotation;
static const Region kRightHalfBoundsNoRotation;
static const Region kLowerHalfBoundsNoRotation;
static const Region kFullBounds90Rotation;
StrictMock<OutputPartialMock> mOutput;
LayerFESet mGeomSnapshots;
Output::CoverageState mCoverageState{mGeomSnapshots};
NonInjectedLayer mLayer;
};
const Region OutputEnsureOutputLayerIfVisibleTest::kEmptyRegion = Region(Rect(0, 0, 0, 0));
const Region OutputEnsureOutputLayerIfVisibleTest::kFullBoundsNoRotation =
Region(Rect(0, 0, 100, 200));
const Region OutputEnsureOutputLayerIfVisibleTest::kRightHalfBoundsNoRotation =
Region(Rect(0, 100, 100, 200));
const Region OutputEnsureOutputLayerIfVisibleTest::kLowerHalfBoundsNoRotation =
Region(Rect(50, 0, 100, 200));
const Region OutputEnsureOutputLayerIfVisibleTest::kFullBounds90Rotation =
Region(Rect(0, 0, 200, 100));
TEST_F(OutputEnsureOutputLayerIfVisibleTest, performsGeomLatchBeforeCheckingIfLayerBelongs) {
EXPECT_CALL(mOutput, belongsInOutput(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false));
EXPECT_CALL(*mLayer.layerFE,
prepareCompositionState(compositionengine::LayerFE::StateSubset::BasicGeometry));
mGeomSnapshots.clear();
ensureOutputLayerIfVisible();
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest,
skipsLatchIfAlreadyLatchedBeforeCheckingIfLayerBelongs) {
EXPECT_CALL(mOutput, belongsInOutput(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false));
ensureOutputLayerIfVisible();
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasNoCompositionState) {
EXPECT_CALL(*mLayer.layerFE, getCompositionState()).WillOnce(Return(nullptr));
ensureOutputLayerIfVisible();
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerNotVisible) {
mLayer.layerFEState.isVisible = false;
ensureOutputLayerIfVisible();
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasEmptyVisibleRegion) {
mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 0, 0};
ensureOutputLayerIfVisible();
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifDrawRegionEmpty) {
mOutput.mState.bounds = Rect(0, 0, 0, 0);
ensureOutputLayerIfVisible();
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest,
handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
mLayer.layerFEState.isOpaque = true;
mLayer.layerFEState.contentDirty = true;
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest,
handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
mLayer.layerFEState.isOpaque = true;
mLayer.layerFEState.contentDirty = true;
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest,
handlesCreatingOutputLayerForTransparentDirtyNotRotatedLayer) {
mLayer.layerFEState.isOpaque = false;
mLayer.layerFEState.contentDirty = true;
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
RegionEq(kRightHalfBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest,
handlesUpdatingOutputLayerForTransparentDirtyNotRotatedLayer) {
mLayer.layerFEState.isOpaque = false;
mLayer.layerFEState.contentDirty = true;
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
RegionEq(kRightHalfBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest,
handlesCreatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
mLayer.layerFEState.isOpaque = true;
mLayer.layerFEState.contentDirty = false;
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest,
handlesUpdatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
mLayer.layerFEState.isOpaque = true;
mLayer.layerFEState.contentDirty = false;
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kLowerHalfBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest,
handlesCreatingOutputLayerForOpaqueDirtyRotated90Layer) {
mLayer.layerFEState.isOpaque = true;
mLayer.layerFEState.contentDirty = true;
mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest,
handlesUpdatingOutputLayerForOpaqueDirtyRotated90Layer) {
mLayer.layerFEState.isOpaque = true;
mLayer.layerFEState.contentDirty = true;
mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest,
handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
mLayer.layerFEState.isOpaque = true;
mLayer.layerFEState.contentDirty = true;
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
mOutput.mState.viewport = Rect(0, 0, 300, 200);
mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest,
handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
mLayer.layerFEState.isOpaque = true;
mLayer.layerFEState.contentDirty = true;
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
mOutput.mState.viewport = Rect(0, 0, 300, 200);
mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
RegionEq(kFullBoundsNoRotation));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest,
handlesCreatingOutputLayerForOpaqueDirtyArbitraryTransformLayer) {
ui::Transform arbitraryTransform;
arbitraryTransform.set(1, 1, -1, 1);
arbitraryTransform.set(0, 100);
mLayer.layerFEState.isOpaque = true;
mLayer.layerFEState.contentDirty = true;
mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
mLayer.layerFEState.geomLayerTransform = arbitraryTransform;
EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
const Region kRegion = Region(Rect(0, 0, 300, 300));
const Region kRegionClipped = Region(Rect(0, 0, 200, 300));
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kRegion));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kRegion));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kRegion));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, RegionEq(kRegion));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kRegionClipped));
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesTest) {
mLayer.layerFEState.isOpaque = false;
mLayer.layerFEState.contentDirty = true;
mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
mCoverageState.aboveCoveredLayers = Region(Rect(50, 0, 150, 200));
mCoverageState.aboveOpaqueLayers = Region(Rect(50, 0, 150, 200));
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500));
const Region kExpectedAboveCoveredRegion = Region(Rect(0, 0, 150, 200));
const Region kExpectedAboveOpaqueRegion = Region(Rect(50, 0, 150, 200));
const Region kExpectedLayerVisibleRegion = Region(Rect(0, 0, 50, 200));
const Region kExpectedLayerCoveredRegion = Region(Rect(50, 0, 100, 200));
const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(0, 100, 50, 200));
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
RegionEq(kExpectedLayerVisibleNonTransparentRegion));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion,
RegionEq(kExpectedLayerVisibleRegion));
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesWithShadowsTest) {
ui::Transform translate;
translate.set(50, 50);
mLayer.layerFEState.geomLayerTransform = translate;
mLayer.layerFEState.shadowRadius = 10.0f;
mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
// half of the layer including the casting shadow is covered and opaque
mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 100, 260));
mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 100, 260));
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500));
const Region kExpectedAboveCoveredRegion = Region(Rect(40, 40, 160, 260));
// add starting opaque region to the opaque half of the casting layer bounds
const Region kExpectedAboveOpaqueRegion =
Region(Rect(40, 40, 100, 260)).orSelf(Rect(100, 50, 150, 250));
const Region kExpectedLayerVisibleRegion = Region(Rect(100, 40, 160, 260));
const Region kExpectedoutputSpaceLayerVisibleRegion = Region(Rect(100, 50, 150, 250));
const Region kExpectedLayerCoveredRegion = Region(Rect(40, 40, 100, 260));
const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(100, 40, 160, 260));
const Region kExpectedLayerShadowRegion =
Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250));
EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion));
EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion));
EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
RegionEq(kExpectedLayerVisibleNonTransparentRegion));
EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion));
EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion,
RegionEq(kExpectedoutputSpaceLayerVisibleRegion));
EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion));
EXPECT_FALSE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty());
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest, shadowRegionOnlyTest) {
ui::Transform translate;
translate.set(50, 50);
mLayer.layerFEState.geomLayerTransform = translate;
mLayer.layerFEState.shadowRadius = 10.0f;
mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
// Casting layer is covered by an opaque region leaving only part of its shadow to be drawn
mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 150, 260));
mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 150, 260));
EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
.WillOnce(Return(&mLayer.outputLayer));
ensureOutputLayerIfVisible();
const Region kExpectedLayerVisibleRegion = Region(Rect(150, 40, 160, 260));
const Region kExpectedLayerShadowRegion =
Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250));
EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion));
EXPECT_TRUE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty());
}
TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifLayerWithShadowIsCovered) {
ui::Transform translate;
translate.set(50, 50);
mLayer.layerFEState.geomLayerTransform = translate;
mLayer.layerFEState.shadowRadius = 10.0f;
mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
// Casting layer and its shadows are covered by an opaque region
mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 160, 260));
mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 160, 260));
ensureOutputLayerIfVisible();
}
/*
* Output::present()
*/
struct OutputPresentTest : public testing::Test {
struct OutputPartialMock : public OutputPartialMockBase {
// Sets up the helper functions called by the function under test to use
// mock implementations.
MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&));
MOCK_METHOD1(updateAndWriteCompositionState,
void(const compositionengine::CompositionRefreshArgs&));
MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&));
MOCK_METHOD0(beginFrame, void());
MOCK_METHOD0(prepareFrame, void());
MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&));
MOCK_METHOD1(finishFrame, void(const compositionengine::CompositionRefreshArgs&));
MOCK_METHOD0(postFramebuffer, void());
};
StrictMock<OutputPartialMock> mOutput;
};
TEST_F(OutputPresentTest, justInvokesChildFunctionsInSequence) {
CompositionRefreshArgs args;
InSequence seq;
EXPECT_CALL(mOutput, updateColorProfile(Ref(args)));
EXPECT_CALL(mOutput, updateAndWriteCompositionState(Ref(args)));
EXPECT_CALL(mOutput, setColorTransform(Ref(args)));
EXPECT_CALL(mOutput, beginFrame());
EXPECT_CALL(mOutput, prepareFrame());
EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args)));
EXPECT_CALL(mOutput, finishFrame(Ref(args)));
EXPECT_CALL(mOutput, postFramebuffer());
mOutput.present(args);
}
/*
* Output::updateColorProfile()
*/
struct OutputUpdateColorProfileTest : public testing::Test {
using TestType = OutputUpdateColorProfileTest;
struct OutputPartialMock : public OutputPartialMockBase {
// Sets up the helper functions called by the function under test to use
// mock implementations.
MOCK_METHOD1(setColorProfile, void(const ColorProfile&));
};
struct Layer {
Layer() {
EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(mLayerFE));
EXPECT_CALL(mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
}
StrictMock<mock::OutputLayer> mOutputLayer;
StrictMock<mock::LayerFE> mLayerFE;
LayerFECompositionState mLayerFEState;
};
OutputUpdateColorProfileTest() {
mOutput.setDisplayColorProfileForTest(
std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
.WillRepeatedly(Return(&mLayer1.mOutputLayer));
EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
.WillRepeatedly(Return(&mLayer2.mOutputLayer));
EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
.WillRepeatedly(Return(&mLayer3.mOutputLayer));
}
struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
void execute() { getInstance()->mOutput.updateColorProfile(getInstance()->mRefreshArgs); }
};
mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
StrictMock<OutputPartialMock> mOutput;
Layer mLayer1;
Layer mLayer2;
Layer mLayer3;
CompositionRefreshArgs mRefreshArgs;
};
// TODO(b/144522012): Refactor Output::updateColorProfile and the related code
// to make it easier to write unit tests.
TEST_F(OutputUpdateColorProfileTest, setsAColorProfileWhenUnmanaged) {
// When the outputColorSetting is set to kUnmanaged, the implementation sets
// a simple default color profile without looking at anything else.
EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
EXPECT_CALL(mOutput,
setColorProfile(ColorProfileEq(
ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN})));
mRefreshArgs.outputColorSetting = OutputColorSetting::kUnmanaged;
mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
mOutput.updateColorProfile(mRefreshArgs);
}
struct OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile
: public OutputUpdateColorProfileTest {
OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile() {
EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
}
struct ExpectBestColorModeCallResultUsedToSetColorProfileState
: public CallOrderStateMachineHelper<
TestType, ExpectBestColorModeCallResultUsedToSetColorProfileState> {
[[nodiscard]] auto expectBestColorModeCallResultUsedToSetColorProfile(
ui::ColorMode colorMode, ui::Dataspace dataspace, ui::RenderIntent renderIntent) {
EXPECT_CALL(*getInstance()->mDisplayColorProfile,
getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _,
_))
.WillOnce(DoAll(SetArgPointee<2>(dataspace), SetArgPointee<3>(colorMode),
SetArgPointee<4>(renderIntent)));
EXPECT_CALL(getInstance()->mOutput,
setColorProfile(
ColorProfileEq(ColorProfile{colorMode, dataspace, renderIntent,
ui::Dataspace::UNKNOWN})));
return nextState<ExecuteState>();
}
};
// Call this member function to start using the mini-DSL defined above.
[[nodiscard]] auto verify() {
return ExpectBestColorModeCallResultUsedToSetColorProfileState::make(this);
}
};
TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
Native_Unknown_Colorimetric_Set) {
verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::NATIVE,
ui::Dataspace::UNKNOWN,
ui::RenderIntent::COLORIMETRIC)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
DisplayP3_DisplayP3_Enhance_Set) {
verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::DISPLAY_P3,
ui::Dataspace::DISPLAY_P3,
ui::RenderIntent::ENHANCE)
.execute();
}
struct OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile
: public OutputUpdateColorProfileTest {
OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile() {
EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
EXPECT_CALL(*mDisplayColorProfile,
getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, _))
.WillRepeatedly(DoAll(SetArgPointee<2>(ui::Dataspace::UNKNOWN),
SetArgPointee<3>(ui::ColorMode::NATIVE),
SetArgPointee<4>(ui::RenderIntent::COLORIMETRIC)));
mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
}
struct IfColorSpaceAgnosticDataspaceSetToState
: public CallOrderStateMachineHelper<TestType, IfColorSpaceAgnosticDataspaceSetToState> {
[[nodiscard]] auto ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace dataspace) {
getInstance()->mRefreshArgs.colorSpaceAgnosticDataspace = dataspace;
return nextState<ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState>();
}
};
struct ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState
: public CallOrderStateMachineHelper<
TestType, ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState> {
[[nodiscard]] auto thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(
ui::Dataspace dataspace) {
EXPECT_CALL(getInstance()->mOutput,
setColorProfile(ColorProfileEq(
ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
ui::RenderIntent::COLORIMETRIC, dataspace})));
return nextState<ExecuteState>();
}
};
// Call this member function to start using the mini-DSL defined above.
[[nodiscard]] auto verify() { return IfColorSpaceAgnosticDataspaceSetToState::make(this); }
};
TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, DisplayP3) {
verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::DISPLAY_P3)
.thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::DISPLAY_P3)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, V0_SRGB) {
verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::V0_SRGB)
.thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::V0_SRGB)
.execute();
}
struct OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference
: public OutputUpdateColorProfileTest {
// Internally the implementation looks through the dataspaces of all the
// visible layers. The topmost one that also has an actual dataspace
// preference set is used to drive subsequent choices.
OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference() {
mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
}
struct IfTopLayerDataspaceState
: public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
[[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
getInstance()->mLayer3.mLayerFEState.dataspace = dataspace;
return nextState<AndIfMiddleLayerDataspaceState>();
}
[[nodiscard]] auto ifTopLayerHasNoPreference() {
return ifTopLayerIs(ui::Dataspace::UNKNOWN);
}
};
struct AndIfMiddleLayerDataspaceState
: public CallOrderStateMachineHelper<TestType, AndIfMiddleLayerDataspaceState> {
[[nodiscard]] auto andIfMiddleLayerIs(ui::Dataspace dataspace) {
getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
return nextState<AndIfBottomLayerDataspaceState>();
}
[[nodiscard]] auto andIfMiddleLayerHasNoPreference() {
return andIfMiddleLayerIs(ui::Dataspace::UNKNOWN);
}
};
struct AndIfBottomLayerDataspaceState
: public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
[[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
return nextState<ThenExpectBestColorModeCallUsesState>();
}
[[nodiscard]] auto andIfBottomLayerHasNoPreference() {
return andIfBottomLayerIs(ui::Dataspace::UNKNOWN);
}
};
struct ThenExpectBestColorModeCallUsesState
: public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
[[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
EXPECT_CALL(*getInstance()->mDisplayColorProfile,
getBestColorMode(dataspace, _, _, _, _));
return nextState<ExecuteState>();
}
};
// Call this member function to start using the mini-DSL defined above.
[[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
};
TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
noStrongLayerPrefenceUses_V0_SRGB) {
// If none of the layers indicate a preference, then V0_SRGB is the
// preferred choice (subject to additional checks).
verify().ifTopLayerHasNoPreference()
.andIfMiddleLayerHasNoPreference()
.andIfBottomLayerHasNoPreference()
.thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
ifTopmostUses_DisplayP3_Then_DisplayP3_Chosen) {
// If only the topmost layer has a preference, then that is what is chosen.
verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
.andIfMiddleLayerHasNoPreference()
.andIfBottomLayerHasNoPreference()
.thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
ifMiddleUses_DisplayP3_Then_DisplayP3_Chosen) {
// If only the middle layer has a preference, that that is what is chosen.
verify().ifTopLayerHasNoPreference()
.andIfMiddleLayerIs(ui::Dataspace::DISPLAY_P3)
.andIfBottomLayerHasNoPreference()
.thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
ifBottomUses_DisplayP3_Then_DisplayP3_Chosen) {
// If only the middle layer has a preference, that that is what is chosen.
verify().ifTopLayerHasNoPreference()
.andIfMiddleLayerHasNoPreference()
.andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
.thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
ifTopUses_DisplayBT2020_AndBottomUses_DisplayP3_Then_DisplayBT2020_Chosen) {
// If multiple layers have a preference, the topmost value is what is used.
verify().ifTopLayerIs(ui::Dataspace::DISPLAY_BT2020)
.andIfMiddleLayerHasNoPreference()
.andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
.thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
ifTopUses_DisplayP3_AndBottomUses_V0_SRGB_Then_DisplayP3_Chosen) {
// If multiple layers have a preference, the topmost value is what is used.
verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
.andIfMiddleLayerHasNoPreference()
.andIfBottomLayerIs(ui::Dataspace::DISPLAY_BT2020)
.thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
.execute();
}
struct OutputUpdateColorProfileTest_ForceOutputColorOverrides
: public OutputUpdateColorProfileTest {
// If CompositionRefreshArgs::forceOutputColorMode is set to some specific
// values, it overrides the layer dataspace choice.
OutputUpdateColorProfileTest_ForceOutputColorOverrides() {
mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
mLayer1.mLayerFEState.dataspace = ui::Dataspace::DISPLAY_BT2020;
EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
}
struct IfForceOutputColorModeState
: public CallOrderStateMachineHelper<TestType, IfForceOutputColorModeState> {
[[nodiscard]] auto ifForceOutputColorMode(ui::ColorMode colorMode) {
getInstance()->mRefreshArgs.forceOutputColorMode = colorMode;
return nextState<ThenExpectBestColorModeCallUsesState>();
}
[[nodiscard]] auto ifNoOverride() { return ifForceOutputColorMode(ui::ColorMode::NATIVE); }
};
struct ThenExpectBestColorModeCallUsesState
: public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
[[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
EXPECT_CALL(*getInstance()->mDisplayColorProfile,
getBestColorMode(dataspace, _, _, _, _));
return nextState<ExecuteState>();
}
};
// Call this member function to start using the mini-DSL defined above.
[[nodiscard]] auto verify() { return IfForceOutputColorModeState::make(this); }
};
TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, NoOverride_DoesNotOverride) {
// By default the layer state is used to set the preferred dataspace
verify().ifNoOverride()
.thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, SRGB_Override_USES_V0_SRGB) {
// Setting ui::ColorMode::SRGB overrides it with ui::Dataspace::V0_SRGB
verify().ifForceOutputColorMode(ui::ColorMode::SRGB)
.thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, DisplayP3_Override_Uses_DisplayP3) {
// Setting ui::ColorMode::DISPLAY_P3 overrides it with ui::Dataspace::DISPLAY_P3
verify().ifForceOutputColorMode(ui::ColorMode::DISPLAY_P3)
.thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
.execute();
}
// HDR output requires all layers to be compatible with the chosen HDR
// dataspace, along with there being proper support.
struct OutputUpdateColorProfileTest_Hdr : public OutputUpdateColorProfileTest {
OutputUpdateColorProfileTest_Hdr() {
mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
}
static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
static constexpr ui::Dataspace BT2020_PQ = ui::Dataspace::BT2020_PQ;
static constexpr ui::Dataspace BT2020_HLG = ui::Dataspace::BT2020_HLG;
static constexpr ui::Dataspace DISPLAY_P3 = ui::Dataspace::DISPLAY_P3;
struct IfTopLayerDataspaceState
: public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
[[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
return nextState<AndTopLayerCompositionTypeState>();
}
[[nodiscard]] auto ifTopLayerIsNotHdr() { return ifTopLayerIs(kNonHdrDataspace); }
};
struct AndTopLayerCompositionTypeState
: public CallOrderStateMachineHelper<TestType, AndTopLayerCompositionTypeState> {
[[nodiscard]] auto andTopLayerIsREComposed(bool renderEngineComposed) {
getInstance()->mLayer2.mLayerFEState.forceClientComposition = renderEngineComposed;
return nextState<AndIfBottomLayerDataspaceState>();
}
};
struct AndIfBottomLayerDataspaceState
: public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
[[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
return nextState<AndBottomLayerCompositionTypeState>();
}
[[nodiscard]] auto andIfBottomLayerIsNotHdr() {
return andIfBottomLayerIs(kNonHdrDataspace);
}
};
struct AndBottomLayerCompositionTypeState
: public CallOrderStateMachineHelper<TestType, AndBottomLayerCompositionTypeState> {
[[nodiscard]] auto andBottomLayerIsREComposed(bool renderEngineComposed) {
getInstance()->mLayer1.mLayerFEState.forceClientComposition = renderEngineComposed;
return nextState<AndIfHasLegacySupportState>();
}
};
struct AndIfHasLegacySupportState
: public CallOrderStateMachineHelper<TestType, AndIfHasLegacySupportState> {
[[nodiscard]] auto andIfLegacySupportFor(ui::Dataspace dataspace, bool legacySupport) {
EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasLegacyHdrSupport(dataspace))
.WillOnce(Return(legacySupport));
return nextState<ThenExpectBestColorModeCallUsesState>();
}
};
struct ThenExpectBestColorModeCallUsesState
: public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
[[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
EXPECT_CALL(*getInstance()->mDisplayColorProfile,
getBestColorMode(dataspace, _, _, _, _));
return nextState<ExecuteState>();
}
};
// Call this member function to start using the mini-DSL defined above.
[[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
};
TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_Uses_PQ) {
// If all layers use BT2020_PQ, and there are no other special conditions,
// BT2020_PQ is used.
verify().ifTopLayerIs(BT2020_PQ)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIs(BT2020_PQ)
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_PQ, false)
.thenExpectBestColorModeCallUses(BT2020_PQ)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
// BT2020_PQ is not used if there is only legacy support for it.
verify().ifTopLayerIs(BT2020_PQ)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIs(BT2020_PQ)
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_PQ, true)
.thenExpectBestColorModeCallUses(DISPLAY_P3)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_RE_Uses_PQ) {
// BT2020_PQ is still used if the bottom layer is RenderEngine composed.
verify().ifTopLayerIs(BT2020_PQ)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIs(BT2020_PQ)
.andBottomLayerIsREComposed(true)
.andIfLegacySupportFor(BT2020_PQ, false)
.thenExpectBestColorModeCallUses(BT2020_PQ)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_PQ_HW_Uses_DisplayP3) {
// BT2020_PQ is not used if the top layer is RenderEngine composed.
verify().ifTopLayerIs(BT2020_PQ)
.andTopLayerIsREComposed(true)
.andIfBottomLayerIs(BT2020_PQ)
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_PQ, false)
.thenExpectBestColorModeCallUses(DISPLAY_P3)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_Uses_PQ) {
// If there is mixed HLG/PQ use, and the topmost layer is PQ, then PQ is used if there
// are no other special conditions.
verify().ifTopLayerIs(BT2020_PQ)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIs(BT2020_HLG)
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_PQ, false)
.thenExpectBestColorModeCallUses(BT2020_PQ)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
// BT2020_PQ is not used if there is only legacy support for it.
verify().ifTopLayerIs(BT2020_PQ)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIs(BT2020_HLG)
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_PQ, true)
.thenExpectBestColorModeCallUses(DISPLAY_P3)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_RE_Uses_PQ) {
// BT2020_PQ is used if the bottom HLG layer is RenderEngine composed.
verify().ifTopLayerIs(BT2020_PQ)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIs(BT2020_HLG)
.andBottomLayerIsREComposed(true)
.andIfLegacySupportFor(BT2020_PQ, false)
.thenExpectBestColorModeCallUses(BT2020_PQ)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_HLG_HW_Uses_DisplayP3) {
// BT2020_PQ is not used if the top PQ layer is RenderEngine composed.
verify().ifTopLayerIs(BT2020_PQ)
.andTopLayerIsREComposed(true)
.andIfBottomLayerIs(BT2020_HLG)
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_PQ, false)
.thenExpectBestColorModeCallUses(DISPLAY_P3)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_Uses_PQ) {
// If there is mixed HLG/PQ use, and the topmost layer is HLG, then PQ is
// used if there are no other special conditions.
verify().ifTopLayerIs(BT2020_HLG)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIs(BT2020_PQ)
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_PQ, false)
.thenExpectBestColorModeCallUses(BT2020_PQ)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
// BT2020_PQ is not used if there is only legacy support for it.
verify().ifTopLayerIs(BT2020_HLG)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIs(BT2020_PQ)
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_PQ, true)
.thenExpectBestColorModeCallUses(DISPLAY_P3)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_RE_Uses_DisplayP3) {
// BT2020_PQ is not used if the bottom PQ layer is RenderEngine composed.
verify().ifTopLayerIs(BT2020_HLG)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIs(BT2020_PQ)
.andBottomLayerIsREComposed(true)
.andIfLegacySupportFor(BT2020_PQ, false)
.thenExpectBestColorModeCallUses(DISPLAY_P3)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_PQ_HW_Uses_PQ) {
// BT2020_PQ is still used if the top HLG layer is RenderEngine composed.
verify().ifTopLayerIs(BT2020_HLG)
.andTopLayerIsREComposed(true)
.andIfBottomLayerIs(BT2020_PQ)
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_PQ, false)
.thenExpectBestColorModeCallUses(BT2020_PQ)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_Uses_HLG) {
// If all layers use HLG then HLG is used if there are no other special
// conditions.
verify().ifTopLayerIs(BT2020_HLG)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIs(BT2020_HLG)
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_HLG, false)
.thenExpectBestColorModeCallUses(BT2020_HLG)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
// BT2020_HLG is not used if there is legacy support for it.
verify().ifTopLayerIs(BT2020_HLG)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIs(BT2020_HLG)
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_HLG, true)
.thenExpectBestColorModeCallUses(DISPLAY_P3)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_RE_Uses_HLG) {
// BT2020_HLG is used even if the bottom layer is client composed.
verify().ifTopLayerIs(BT2020_HLG)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIs(BT2020_HLG)
.andBottomLayerIsREComposed(true)
.andIfLegacySupportFor(BT2020_HLG, false)
.thenExpectBestColorModeCallUses(BT2020_HLG)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_HLG_HW_Uses_HLG) {
// BT2020_HLG is used even if the top layer is client composed.
verify().ifTopLayerIs(BT2020_HLG)
.andTopLayerIsREComposed(true)
.andIfBottomLayerIs(BT2020_HLG)
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_HLG, false)
.thenExpectBestColorModeCallUses(BT2020_HLG)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_NonHdr_HW_Uses_PQ) {
// Even if there are non-HDR layers present, BT2020_PQ can still be used.
verify().ifTopLayerIs(BT2020_PQ)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIsNotHdr()
.andBottomLayerIsREComposed(false)
.andIfLegacySupportFor(BT2020_PQ, false)
.thenExpectBestColorModeCallUses(BT2020_PQ)
.execute();
}
TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_NonHdr_RE_Uses_HLG) {
// If all layers use HLG then HLG is used if there are no other special
// conditions.
verify().ifTopLayerIs(BT2020_HLG)
.andTopLayerIsREComposed(false)
.andIfBottomLayerIsNotHdr()
.andBottomLayerIsREComposed(true)
.andIfLegacySupportFor(BT2020_HLG, false)
.thenExpectBestColorModeCallUses(BT2020_HLG)
.execute();
}
struct OutputUpdateColorProfile_AffectsChosenRenderIntentTest
: public OutputUpdateColorProfileTest {
// The various values for CompositionRefreshArgs::outputColorSetting affect
// the chosen renderIntent, along with whether the preferred dataspace is an
// HDR dataspace or not.
OutputUpdateColorProfile_AffectsChosenRenderIntentTest() {
mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
mLayer1.mLayerFEState.dataspace = ui::Dataspace::BT2020_PQ;
EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
EXPECT_CALL(*mDisplayColorProfile, hasLegacyHdrSupport(ui::Dataspace::BT2020_PQ))
.WillRepeatedly(Return(false));
}
// The tests here involve enough state and GMock setup that using a mini-DSL
// makes the tests much more readable, and allows the test to focus more on
// the intent than on some of the details.
static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
static constexpr ui::Dataspace kHdrDataspace = ui::Dataspace::BT2020_PQ;
struct IfDataspaceChosenState
: public CallOrderStateMachineHelper<TestType, IfDataspaceChosenState> {
[[nodiscard]] auto ifDataspaceChosenIs(ui::Dataspace dataspace) {
getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
return nextState<AndOutputColorSettingState>();
}
[[nodiscard]] auto ifDataspaceChosenIsNonHdr() {
return ifDataspaceChosenIs(kNonHdrDataspace);
}
[[nodiscard]] auto ifDataspaceChosenIsHdr() { return ifDataspaceChosenIs(kHdrDataspace); }
};
struct AndOutputColorSettingState
: public CallOrderStateMachineHelper<TestType, AndOutputColorSettingState> {
[[nodiscard]] auto andOutputColorSettingIs(OutputColorSetting setting) {
getInstance()->mRefreshArgs.outputColorSetting = setting;
return nextState<ThenExpectBestColorModeCallUsesState>();
}
};
struct ThenExpectBestColorModeCallUsesState
: public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
[[nodiscard]] auto thenExpectBestColorModeCallUses(ui::RenderIntent intent) {
EXPECT_CALL(*getInstance()->mDisplayColorProfile,
getBestColorMode(getInstance()->mLayer1.mLayerFEState.dataspace, intent, _,
_, _));
return nextState<ExecuteState>();
}
};
// Tests call one of these two helper member functions to start using the
// mini-DSL defined above.
[[nodiscard]] auto verify() { return IfDataspaceChosenState::make(this); }
};
TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
Managed_NonHdr_Prefers_Colorimetric) {
verify().ifDataspaceChosenIsNonHdr()
.andOutputColorSettingIs(OutputColorSetting::kManaged)
.thenExpectBestColorModeCallUses(ui::RenderIntent::COLORIMETRIC)
.execute();
}
TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
Managed_Hdr_Prefers_ToneMapColorimetric) {
verify().ifDataspaceChosenIsHdr()
.andOutputColorSettingIs(OutputColorSetting::kManaged)
.thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_COLORIMETRIC)
.execute();
}
TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Enhanced_NonHdr_Prefers_Enhance) {
verify().ifDataspaceChosenIsNonHdr()
.andOutputColorSettingIs(OutputColorSetting::kEnhanced)
.thenExpectBestColorModeCallUses(ui::RenderIntent::ENHANCE)
.execute();
}
TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
Enhanced_Hdr_Prefers_ToneMapEnhance) {
verify().ifDataspaceChosenIsHdr()
.andOutputColorSettingIs(OutputColorSetting::kEnhanced)
.thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_ENHANCE)
.execute();
}
TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_NonHdr_Prefers_Vendor) {
verify().ifDataspaceChosenIsNonHdr()
.andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
.thenExpectBestColorModeCallUses(
static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
.execute();
}
TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_Hdr_Prefers_Vendor) {
verify().ifDataspaceChosenIsHdr()
.andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
.thenExpectBestColorModeCallUses(
static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
.execute();
}
/*
* Output::beginFrame()
*/
struct OutputBeginFrameTest : public ::testing::Test {
using TestType = OutputBeginFrameTest;
struct OutputPartialMock : public OutputPartialMockBase {
// Sets up the helper functions called by the function under test to use
// mock implementations.
MOCK_CONST_METHOD1(getDirtyRegion, Region(bool));
};
OutputBeginFrameTest() {
mOutput.setDisplayColorProfileForTest(
std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
}
struct IfGetDirtyRegionExpectationState
: public CallOrderStateMachineHelper<TestType, IfGetDirtyRegionExpectationState> {
[[nodiscard]] auto ifGetDirtyRegionReturns(Region dirtyRegion) {
EXPECT_CALL(getInstance()->mOutput, getDirtyRegion(false))
.WillOnce(Return(dirtyRegion));
return nextState<AndIfGetOutputLayerCountExpectationState>();
}
};
struct AndIfGetOutputLayerCountExpectationState
: public CallOrderStateMachineHelper<TestType, AndIfGetOutputLayerCountExpectationState> {
[[nodiscard]] auto andIfGetOutputLayerCountReturns(size_t layerCount) {
EXPECT_CALL(getInstance()->mOutput, getOutputLayerCount()).WillOnce(Return(layerCount));
return nextState<AndIfLastCompositionHadVisibleLayersState>();
}
};
struct AndIfLastCompositionHadVisibleLayersState
: public CallOrderStateMachineHelper<TestType,
AndIfLastCompositionHadVisibleLayersState> {
[[nodiscard]] auto andIfLastCompositionHadVisibleLayersIs(bool hadOutputLayers) {
getInstance()->mOutput.mState.lastCompositionHadVisibleLayers = hadOutputLayers;
return nextState<ThenExpectRenderSurfaceBeginFrameCallState>();
}
};
struct ThenExpectRenderSurfaceBeginFrameCallState
: public CallOrderStateMachineHelper<TestType,
ThenExpectRenderSurfaceBeginFrameCallState> {
[[nodiscard]] auto thenExpectRenderSurfaceBeginFrameCall(bool mustRecompose) {
EXPECT_CALL(*getInstance()->mRenderSurface, beginFrame(mustRecompose));
return nextState<ExecuteState>();
}
};
struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
[[nodiscard]] auto execute() {
getInstance()->mOutput.beginFrame();
return nextState<CheckPostconditionHadVisibleLayersState>();
}
};
struct CheckPostconditionHadVisibleLayersState
: public CallOrderStateMachineHelper<TestType, CheckPostconditionHadVisibleLayersState> {
void checkPostconditionHadVisibleLayers(bool expected) {
EXPECT_EQ(expected, getInstance()->mOutput.mState.lastCompositionHadVisibleLayers);
}
};
// Tests call one of these two helper member functions to start using the
// mini-DSL defined above.
[[nodiscard]] auto verify() { return IfGetDirtyRegionExpectationState::make(this); }
static const Region kEmptyRegion;
static const Region kNotEmptyRegion;
mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
StrictMock<OutputPartialMock> mOutput;
};
const Region OutputBeginFrameTest::kEmptyRegion{Rect{0, 0, 0, 0}};
const Region OutputBeginFrameTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
TEST_F(OutputBeginFrameTest, hasDirtyHasLayersHadLayersLastFrame) {
verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
.andIfGetOutputLayerCountReturns(1u)
.andIfLastCompositionHadVisibleLayersIs(true)
.thenExpectRenderSurfaceBeginFrameCall(true)
.execute()
.checkPostconditionHadVisibleLayers(true);
}
TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersHadLayersLastFrame) {
verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
.andIfGetOutputLayerCountReturns(0u)
.andIfLastCompositionHadVisibleLayersIs(true)
.thenExpectRenderSurfaceBeginFrameCall(true)
.execute()
.checkPostconditionHadVisibleLayers(false);
}
TEST_F(OutputBeginFrameTest, hasDirtyHasLayersNotHadLayersLastFrame) {
verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
.andIfGetOutputLayerCountReturns(1u)
.andIfLastCompositionHadVisibleLayersIs(false)
.thenExpectRenderSurfaceBeginFrameCall(true)
.execute()
.checkPostconditionHadVisibleLayers(true);
}
TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersNotHadLayersLastFrame) {
verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
.andIfGetOutputLayerCountReturns(0u)
.andIfLastCompositionHadVisibleLayersIs(false)
.thenExpectRenderSurfaceBeginFrameCall(false)
.execute()
.checkPostconditionHadVisibleLayers(false);
}
TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersHadLayersLastFrame) {
verify().ifGetDirtyRegionReturns(kEmptyRegion)
.andIfGetOutputLayerCountReturns(1u)
.andIfLastCompositionHadVisibleLayersIs(true)
.thenExpectRenderSurfaceBeginFrameCall(false)
.execute()
.checkPostconditionHadVisibleLayers(true);
}
TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersHadLayersLastFrame) {
verify().ifGetDirtyRegionReturns(kEmptyRegion)
.andIfGetOutputLayerCountReturns(0u)
.andIfLastCompositionHadVisibleLayersIs(true)
.thenExpectRenderSurfaceBeginFrameCall(false)
.execute()
.checkPostconditionHadVisibleLayers(true);
}
TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersNotHadLayersLastFrame) {
verify().ifGetDirtyRegionReturns(kEmptyRegion)
.andIfGetOutputLayerCountReturns(1u)
.andIfLastCompositionHadVisibleLayersIs(false)
.thenExpectRenderSurfaceBeginFrameCall(false)
.execute()
.checkPostconditionHadVisibleLayers(false);
}
TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersNotHadLayersLastFrame) {
verify().ifGetDirtyRegionReturns(kEmptyRegion)
.andIfGetOutputLayerCountReturns(0u)
.andIfLastCompositionHadVisibleLayersIs(false)
.thenExpectRenderSurfaceBeginFrameCall(false)
.execute()
.checkPostconditionHadVisibleLayers(false);
}
/*
* Output::devOptRepaintFlash()
*/
struct OutputDevOptRepaintFlashTest : public testing::Test {
struct OutputPartialMock : public OutputPartialMockBase {
// Sets up the helper functions called by the function under test to use
// mock implementations.
MOCK_CONST_METHOD1(getDirtyRegion, Region(bool));
MOCK_METHOD2(composeSurfaces,
std::optional<base::unique_fd>(
const Region&, const compositionengine::CompositionRefreshArgs&));
MOCK_METHOD0(postFramebuffer, void());
MOCK_METHOD0(prepareFrame, void());
};
OutputDevOptRepaintFlashTest() {
mOutput.setDisplayColorProfileForTest(
std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
}
static const Region kEmptyRegion;
static const Region kNotEmptyRegion;
StrictMock<OutputPartialMock> mOutput;
mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
CompositionRefreshArgs mRefreshArgs;
};
const Region OutputDevOptRepaintFlashTest::kEmptyRegion{Rect{0, 0, 0, 0}};
const Region OutputDevOptRepaintFlashTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
TEST_F(OutputDevOptRepaintFlashTest, doesNothingIfFlashDelayNotSet) {
mRefreshArgs.devOptFlashDirtyRegionsDelay = {};