2013-04-25 19:54:59 +00:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
|
|
|
|
2013-07-02 16:27:17 +00:00
|
|
|
#include "TestLayers.h"
|
2013-04-25 19:54:59 +00:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "gmock/gmock.h"
|
2015-10-22 20:04:35 +00:00
|
|
|
#include "LayerUserData.h"
|
2014-08-28 02:13:43 +00:00
|
|
|
#include "mozilla/layers/LayerMetricsWrapper.h"
|
2016-03-22 18:08:38 +00:00
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
2013-04-25 19:54:59 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-01-27 15:28:04 +00:00
|
|
|
using namespace mozilla::gfx;
|
2013-04-25 19:54:59 +00:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
2013-07-02 16:27:17 +00:00
|
|
|
class TestContainerLayer : public ContainerLayer {
|
|
|
|
public:
|
2014-09-01 03:31:20 +00:00
|
|
|
explicit TestContainerLayer(LayerManager* aManager)
|
2013-07-02 16:27:17 +00:00
|
|
|
: ContainerLayer(aManager, nullptr) {}
|
2013-04-25 19:54:59 +00:00
|
|
|
|
|
|
|
virtual const char* Name() const { return "TestContainerLayer"; }
|
|
|
|
|
|
|
|
virtual LayerType GetType() const { return TYPE_CONTAINER; }
|
|
|
|
|
2014-01-27 15:28:04 +00:00
|
|
|
virtual void ComputeEffectiveTransforms(
|
|
|
|
const Matrix4x4& aTransformToSurface) {
|
2013-07-30 18:03:41 +00:00
|
|
|
DefaultComputeEffectiveTransforms(aTransformToSurface);
|
2013-07-02 16:27:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-26 17:06:08 +00:00
|
|
|
class TestPaintedLayer : public PaintedLayer {
|
2013-07-02 16:27:17 +00:00
|
|
|
public:
|
2014-09-26 17:06:08 +00:00
|
|
|
explicit TestPaintedLayer(LayerManager* aManager)
|
|
|
|
: PaintedLayer(aManager, nullptr) {}
|
2013-07-02 16:27:17 +00:00
|
|
|
|
|
|
|
virtual const char* Name() const { return "TestPaintedLayer"; }
|
|
|
|
|
|
|
|
virtual LayerType GetType() const { return TYPE_PAINTED; }
|
|
|
|
|
|
|
|
virtual void InvalidateRegion(const nsIntRegion& aRegion) { MOZ_CRASH(); }
|
2013-04-25 19:54:59 +00:00
|
|
|
};
|
|
|
|
|
2015-01-14 22:24:09 +00:00
|
|
|
class TestLayerManager : public LayerManager {
|
|
|
|
public:
|
|
|
|
TestLayerManager() : LayerManager() {}
|
|
|
|
|
|
|
|
virtual bool EndEmptyTransaction(EndTransactionFlags aFlags = END_DEFAULT) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual already_AddRefed<ContainerLayer> CreateContainerLayer() {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ContainerLayer> layer = new TestContainerLayer(this);
|
2015-01-14 22:24:09 +00:00
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
virtual void GetBackendName(nsAString& aName) {}
|
|
|
|
virtual LayersBackend GetBackendType() { return LayersBackend::LAYERS_BASIC; }
|
2018-11-19 07:55:28 +00:00
|
|
|
virtual bool BeginTransaction(const nsCString& = nsCString()) { return true; }
|
2015-01-14 22:24:09 +00:00
|
|
|
virtual already_AddRefed<ImageLayer> CreateImageLayer() {
|
2016-12-02 21:46:53 +00:00
|
|
|
MOZ_CRASH("Not implemented.");
|
2015-01-14 22:24:09 +00:00
|
|
|
}
|
|
|
|
virtual already_AddRefed<PaintedLayer> CreatePaintedLayer() {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<PaintedLayer> layer = new TestPaintedLayer(this);
|
2015-01-14 22:24:09 +00:00
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
virtual already_AddRefed<ColorLayer> CreateColorLayer() {
|
2017-10-25 06:30:31 +00:00
|
|
|
MOZ_CRASH("Not implemented.");
|
2015-01-14 22:24:09 +00:00
|
|
|
}
|
|
|
|
virtual void SetRoot(Layer* aLayer) {}
|
2018-11-19 07:55:28 +00:00
|
|
|
virtual bool BeginTransactionWithTarget(gfxContext* aTarget,
|
|
|
|
const nsCString& = nsCString()) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-01-14 22:24:09 +00:00
|
|
|
virtual already_AddRefed<CanvasLayer> CreateCanvasLayer() {
|
2017-10-25 06:30:31 +00:00
|
|
|
MOZ_CRASH("Not implemented.");
|
2015-01-14 22:24:09 +00:00
|
|
|
}
|
|
|
|
virtual void EndTransaction(DrawPaintedLayerCallback aCallback,
|
|
|
|
void* aCallbackData,
|
|
|
|
EndTransactionFlags aFlags = END_DEFAULT) {}
|
|
|
|
virtual int32_t GetMaxTextureSize() const { return 0; }
|
|
|
|
};
|
|
|
|
|
2013-04-25 19:54:59 +00:00
|
|
|
class TestUserData : public LayerUserData {
|
|
|
|
public:
|
|
|
|
MOCK_METHOD0(Die, void());
|
|
|
|
virtual ~TestUserData() { Die(); }
|
|
|
|
};
|
|
|
|
|
2019-04-05 21:42:17 +00:00
|
|
|
TEST(Layers, LayerConstructor)
|
|
|
|
{ TestContainerLayer layer(nullptr); }
|
2013-04-25 19:54:59 +00:00
|
|
|
|
2019-04-05 21:42:17 +00:00
|
|
|
TEST(Layers, Defaults)
|
|
|
|
{
|
2013-07-02 16:27:17 +00:00
|
|
|
TestContainerLayer layer(nullptr);
|
2013-04-25 19:54:59 +00:00
|
|
|
ASSERT_EQ(1.0, layer.GetOpacity());
|
|
|
|
ASSERT_EQ(1.0f, layer.GetPostXScale());
|
|
|
|
ASSERT_EQ(1.0f, layer.GetPostYScale());
|
|
|
|
|
|
|
|
ASSERT_EQ(nullptr, layer.GetNextSibling());
|
|
|
|
ASSERT_EQ(nullptr, layer.GetPrevSibling());
|
|
|
|
ASSERT_EQ(nullptr, layer.GetFirstChild());
|
|
|
|
ASSERT_EQ(nullptr, layer.GetLastChild());
|
|
|
|
}
|
|
|
|
|
2019-04-05 21:42:17 +00:00
|
|
|
TEST(Layers, Transform)
|
|
|
|
{
|
2013-07-02 16:27:17 +00:00
|
|
|
TestContainerLayer layer(nullptr);
|
2013-04-25 19:54:59 +00:00
|
|
|
|
2014-01-27 15:28:47 +00:00
|
|
|
Matrix4x4 identity;
|
2013-04-25 19:54:59 +00:00
|
|
|
ASSERT_EQ(true, identity.IsIdentity());
|
|
|
|
|
|
|
|
ASSERT_EQ(identity, layer.GetTransform());
|
|
|
|
}
|
|
|
|
|
2019-04-05 21:42:17 +00:00
|
|
|
TEST(Layers, Type)
|
|
|
|
{
|
2013-07-02 16:27:17 +00:00
|
|
|
TestContainerLayer layer(nullptr);
|
2014-09-26 17:06:08 +00:00
|
|
|
ASSERT_EQ(nullptr, layer.AsPaintedLayer());
|
2013-04-25 19:54:59 +00:00
|
|
|
ASSERT_EQ(nullptr, layer.AsRefLayer());
|
|
|
|
ASSERT_EQ(nullptr, layer.AsColorLayer());
|
|
|
|
}
|
|
|
|
|
2019-04-05 21:42:17 +00:00
|
|
|
TEST(Layers, UserData)
|
|
|
|
{
|
2015-03-17 14:50:06 +00:00
|
|
|
UniquePtr<TestContainerLayer> layerPtr(new TestContainerLayer(nullptr));
|
2013-07-02 16:27:17 +00:00
|
|
|
TestContainerLayer& layer = *layerPtr;
|
2013-04-25 19:54:59 +00:00
|
|
|
|
|
|
|
void* key1 = (void*)1;
|
|
|
|
void* key2 = (void*)2;
|
|
|
|
void* key3 = (void*)3;
|
|
|
|
|
|
|
|
ASSERT_EQ(nullptr, layer.GetUserData(key1));
|
|
|
|
ASSERT_EQ(nullptr, layer.GetUserData(key2));
|
|
|
|
ASSERT_EQ(nullptr, layer.GetUserData(key3));
|
|
|
|
|
2015-03-17 14:50:06 +00:00
|
|
|
TestUserData* data1 = new TestUserData;
|
|
|
|
TestUserData* data2 = new TestUserData;
|
|
|
|
TestUserData* data3 = new TestUserData;
|
|
|
|
|
2013-04-25 19:54:59 +00:00
|
|
|
layer.SetUserData(key1, data1);
|
|
|
|
layer.SetUserData(key2, data2);
|
|
|
|
layer.SetUserData(key3, data3);
|
|
|
|
|
|
|
|
// Also checking that the user data is returned but not free'd
|
2016-05-24 22:17:27 +00:00
|
|
|
UniquePtr<LayerUserData> d1(layer.RemoveUserData(key1));
|
|
|
|
UniquePtr<LayerUserData> d2(layer.RemoveUserData(key2));
|
|
|
|
UniquePtr<LayerUserData> d3(layer.RemoveUserData(key3));
|
2015-03-17 14:50:06 +00:00
|
|
|
ASSERT_EQ(data1, d1.get());
|
|
|
|
ASSERT_EQ(data2, d2.get());
|
|
|
|
ASSERT_EQ(data3, d3.get());
|
2013-04-25 19:54:59 +00:00
|
|
|
|
2015-03-17 14:50:06 +00:00
|
|
|
layer.SetUserData(key1, d1.release());
|
|
|
|
layer.SetUserData(key2, d2.release());
|
|
|
|
layer.SetUserData(key3, d3.release());
|
2013-04-25 19:54:59 +00:00
|
|
|
|
|
|
|
// Layer has ownership of data1-3, check that they are destroyed
|
|
|
|
EXPECT_CALL(*data1, Die());
|
|
|
|
EXPECT_CALL(*data2, Die());
|
|
|
|
EXPECT_CALL(*data3, Die());
|
|
|
|
}
|
|
|
|
|
2013-07-02 16:27:17 +00:00
|
|
|
static already_AddRefed<Layer> CreateLayer(char aLayerType,
|
|
|
|
LayerManager* aManager) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Layer> layer = nullptr;
|
2013-07-02 16:27:17 +00:00
|
|
|
if (aLayerType == 'c') {
|
2015-01-14 22:24:09 +00:00
|
|
|
layer = aManager->CreateContainerLayer();
|
2013-07-02 16:27:17 +00:00
|
|
|
} else if (aLayerType == 't') {
|
2015-01-14 22:24:09 +00:00
|
|
|
layer = aManager->CreatePaintedLayer();
|
|
|
|
} else if (aLayerType == 'o') {
|
|
|
|
layer = aManager->CreateColorLayer();
|
2013-07-02 16:27:17 +00:00
|
|
|
}
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Layer> CreateLayerTree(const char* aLayerTreeDescription,
|
|
|
|
nsIntRegion* aVisibleRegions,
|
2014-08-01 12:31:48 +00:00
|
|
|
const Matrix4x4* aTransforms,
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<LayerManager>& manager,
|
|
|
|
nsTArray<RefPtr<Layer> >& aLayersOut) {
|
2013-07-02 16:27:17 +00:00
|
|
|
aLayersOut.Clear();
|
|
|
|
|
2015-01-14 22:24:09 +00:00
|
|
|
if (!manager) {
|
|
|
|
manager = new TestLayerManager();
|
|
|
|
}
|
2013-07-02 16:27:17 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Layer> rootLayer = nullptr;
|
|
|
|
RefPtr<ContainerLayer> parentContainerLayer = nullptr;
|
|
|
|
RefPtr<Layer> lastLayer = nullptr;
|
2013-07-02 16:27:17 +00:00
|
|
|
int layerNumber = 0;
|
|
|
|
for (size_t i = 0; i < strlen(aLayerTreeDescription); i++) {
|
|
|
|
if (aLayerTreeDescription[i] == '(') {
|
|
|
|
if (!lastLayer) {
|
|
|
|
printf(
|
|
|
|
"Syntax error, likely '(' character isn't preceded by a "
|
|
|
|
"container.\n");
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
parentContainerLayer = lastLayer->AsContainerLayer();
|
|
|
|
if (!parentContainerLayer) {
|
|
|
|
printf("Layer before '(' must be a container.\n");
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
} else if (aLayerTreeDescription[i] == ')') {
|
|
|
|
parentContainerLayer = parentContainerLayer->GetParent();
|
|
|
|
lastLayer = nullptr;
|
|
|
|
} else {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Layer> layer =
|
|
|
|
CreateLayer(aLayerTreeDescription[i], manager.get());
|
2014-02-18 21:38:30 +00:00
|
|
|
if (aVisibleRegions) {
|
2015-11-29 07:07:55 +00:00
|
|
|
layer->SetVisibleRegion(
|
|
|
|
LayerIntRegion::FromUnknownRegion(aVisibleRegions[layerNumber]));
|
2014-12-15 02:37:52 +00:00
|
|
|
layer->SetEventRegions(EventRegions(aVisibleRegions[layerNumber]));
|
2014-02-18 21:38:30 +00:00
|
|
|
}
|
|
|
|
if (aTransforms) {
|
2014-08-01 12:31:48 +00:00
|
|
|
layer->SetBaseTransform(aTransforms[layerNumber]);
|
2014-02-18 21:38:30 +00:00
|
|
|
}
|
2013-07-02 16:27:17 +00:00
|
|
|
aLayersOut.AppendElement(layer);
|
|
|
|
layerNumber++;
|
|
|
|
if (rootLayer && !parentContainerLayer) {
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
if (!rootLayer) {
|
|
|
|
rootLayer = layer;
|
|
|
|
}
|
|
|
|
if (parentContainerLayer) {
|
2014-02-18 21:38:29 +00:00
|
|
|
parentContainerLayer->InsertAfter(layer,
|
|
|
|
parentContainerLayer->GetLastChild());
|
2013-07-02 16:27:17 +00:00
|
|
|
layer->SetParent(parentContainerLayer);
|
|
|
|
}
|
|
|
|
lastLayer = layer;
|
|
|
|
}
|
|
|
|
}
|
2013-07-30 18:03:41 +00:00
|
|
|
if (rootLayer) {
|
2014-01-27 15:28:04 +00:00
|
|
|
rootLayer->ComputeEffectiveTransforms(Matrix4x4());
|
2015-01-14 22:24:09 +00:00
|
|
|
manager->SetRoot(rootLayer);
|
2016-11-24 05:11:27 +00:00
|
|
|
if (rootLayer->AsHostLayer()) {
|
2015-01-14 22:24:09 +00:00
|
|
|
// Only perform this for LayerManagerComposite
|
2016-03-22 18:08:38 +00:00
|
|
|
CompositorBridgeParent::SetShadowProperties(rootLayer);
|
2015-01-14 22:24:09 +00:00
|
|
|
}
|
2013-07-30 18:03:41 +00:00
|
|
|
}
|
2013-07-02 16:27:17 +00:00
|
|
|
return rootLayer.forget();
|
|
|
|
}
|
|
|
|
|
2019-04-05 21:42:17 +00:00
|
|
|
TEST(Layers, LayerTree)
|
|
|
|
{
|
2013-07-02 16:27:17 +00:00
|
|
|
const char* layerTreeSyntax = "c(c(tt))";
|
|
|
|
nsIntRegion layerVisibleRegion[] = {
|
2015-05-07 09:08:01 +00:00
|
|
|
nsIntRegion(IntRect(0, 0, 100, 100)),
|
|
|
|
nsIntRegion(IntRect(0, 0, 100, 100)),
|
|
|
|
nsIntRegion(IntRect(0, 0, 100, 100)),
|
|
|
|
nsIntRegion(IntRect(10, 10, 20, 20)),
|
2013-07-02 16:27:17 +00:00
|
|
|
};
|
2014-08-01 12:31:48 +00:00
|
|
|
Matrix4x4 transforms[] = {
|
|
|
|
Matrix4x4(),
|
|
|
|
Matrix4x4(),
|
|
|
|
Matrix4x4(),
|
|
|
|
Matrix4x4(),
|
2013-07-02 16:27:17 +00:00
|
|
|
};
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<Layer> > layers;
|
2013-07-02 16:27:17 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<LayerManager> lm;
|
|
|
|
RefPtr<Layer> root = CreateLayerTree(layerTreeSyntax, layerVisibleRegion,
|
|
|
|
transforms, lm, layers);
|
2013-07-02 16:27:17 +00:00
|
|
|
|
|
|
|
// B2G g++ doesn't like ASSERT_NE with nullptr directly. It thinks it's
|
|
|
|
// an int.
|
|
|
|
Layer* nullLayer = nullptr;
|
|
|
|
ASSERT_NE(nullLayer, layers[0]->AsContainerLayer());
|
|
|
|
ASSERT_NE(nullLayer, layers[1]->AsContainerLayer());
|
2014-09-26 17:06:08 +00:00
|
|
|
ASSERT_NE(nullLayer, layers[2]->AsPaintedLayer());
|
|
|
|
ASSERT_NE(nullLayer, layers[3]->AsPaintedLayer());
|
2013-07-02 16:27:17 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 21:38:30 +00:00
|
|
|
static void ValidateTreePointers(Layer* aLayer) {
|
|
|
|
if (aLayer->GetNextSibling()) {
|
|
|
|
ASSERT_EQ(aLayer, aLayer->GetNextSibling()->GetPrevSibling());
|
|
|
|
} else if (aLayer->GetParent()) {
|
|
|
|
ASSERT_EQ(aLayer, aLayer->GetParent()->GetLastChild());
|
|
|
|
}
|
|
|
|
if (aLayer->GetPrevSibling()) {
|
|
|
|
ASSERT_EQ(aLayer, aLayer->GetPrevSibling()->GetNextSibling());
|
|
|
|
} else if (aLayer->GetParent()) {
|
|
|
|
ASSERT_EQ(aLayer, aLayer->GetParent()->GetFirstChild());
|
|
|
|
}
|
|
|
|
if (aLayer->GetFirstChild()) {
|
|
|
|
ASSERT_EQ(aLayer, aLayer->GetFirstChild()->GetParent());
|
|
|
|
}
|
|
|
|
if (aLayer->GetLastChild()) {
|
|
|
|
ASSERT_EQ(aLayer, aLayer->GetLastChild()->GetParent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
static void ValidateTreePointers(nsTArray<RefPtr<Layer> >& aLayers) {
|
2014-02-18 21:38:30 +00:00
|
|
|
for (uint32_t i = 0; i < aLayers.Length(); i++) {
|
|
|
|
ValidateTreePointers(aLayers[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 21:42:17 +00:00
|
|
|
TEST(Layers, RepositionChild)
|
|
|
|
{
|
2014-02-18 21:38:30 +00:00
|
|
|
const char* layerTreeSyntax = "c(ttt)";
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<Layer> > layers;
|
|
|
|
RefPtr<LayerManager> lm;
|
|
|
|
RefPtr<Layer> root =
|
|
|
|
CreateLayerTree(layerTreeSyntax, nullptr, nullptr, lm, layers);
|
2014-02-18 21:38:30 +00:00
|
|
|
ContainerLayer* parent = root->AsContainerLayer();
|
|
|
|
ValidateTreePointers(layers);
|
|
|
|
|
|
|
|
// tree is currently like this (using indexes into layers):
|
|
|
|
// 0
|
|
|
|
// 1 2 3
|
|
|
|
ASSERT_EQ(layers[2], layers[1]->GetNextSibling());
|
|
|
|
ASSERT_EQ(layers[3], layers[2]->GetNextSibling());
|
|
|
|
ASSERT_EQ(nullptr, layers[3]->GetNextSibling());
|
|
|
|
|
|
|
|
parent->RepositionChild(layers[1], layers[3]);
|
|
|
|
ValidateTreePointers(layers);
|
|
|
|
|
|
|
|
// now the tree is like this:
|
|
|
|
// 0
|
|
|
|
// 2 3 1
|
|
|
|
ASSERT_EQ(layers[3], layers[2]->GetNextSibling());
|
|
|
|
ASSERT_EQ(layers[1], layers[3]->GetNextSibling());
|
|
|
|
ASSERT_EQ(nullptr, layers[1]->GetNextSibling());
|
|
|
|
|
|
|
|
parent->RepositionChild(layers[3], layers[2]);
|
|
|
|
ValidateTreePointers(layers);
|
|
|
|
|
|
|
|
// no change
|
|
|
|
ASSERT_EQ(layers[3], layers[2]->GetNextSibling());
|
|
|
|
ASSERT_EQ(layers[1], layers[3]->GetNextSibling());
|
|
|
|
ASSERT_EQ(nullptr, layers[1]->GetNextSibling());
|
|
|
|
|
|
|
|
parent->RepositionChild(layers[3], layers[1]);
|
|
|
|
ValidateTreePointers(layers);
|
|
|
|
|
|
|
|
// 0
|
|
|
|
// 2 1 3
|
|
|
|
ASSERT_EQ(layers[1], layers[2]->GetNextSibling());
|
|
|
|
ASSERT_EQ(layers[3], layers[1]->GetNextSibling());
|
|
|
|
ASSERT_EQ(nullptr, layers[3]->GetNextSibling());
|
|
|
|
|
|
|
|
parent->RepositionChild(layers[3], nullptr);
|
|
|
|
ValidateTreePointers(layers);
|
|
|
|
|
|
|
|
// 0
|
|
|
|
// 3 2 1
|
|
|
|
ASSERT_EQ(layers[2], layers[3]->GetNextSibling());
|
|
|
|
ASSERT_EQ(layers[1], layers[2]->GetNextSibling());
|
|
|
|
ASSERT_EQ(nullptr, layers[1]->GetNextSibling());
|
|
|
|
}
|
2014-08-28 02:13:43 +00:00
|
|
|
|
2016-03-30 21:04:10 +00:00
|
|
|
class LayerMetricsWrapperTester : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
virtual void SetUp() {
|
|
|
|
// This ensures ScrollMetadata::sNullMetadata is initialized.
|
|
|
|
gfxPlatform::GetPlatform();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(LayerMetricsWrapperTester, SimpleTree) {
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<Layer> > layers;
|
|
|
|
RefPtr<LayerManager> lm;
|
|
|
|
RefPtr<Layer> root =
|
|
|
|
CreateLayerTree("c(c(c(tt)c(t)))", nullptr, nullptr, lm, layers);
|
2014-08-28 02:13:43 +00:00
|
|
|
LayerMetricsWrapper wrapper(root);
|
|
|
|
|
|
|
|
ASSERT_EQ(root.get(), wrapper.GetLayer());
|
|
|
|
wrapper = wrapper.GetFirstChild();
|
|
|
|
ASSERT_EQ(layers[1].get(), wrapper.GetLayer());
|
|
|
|
ASSERT_FALSE(wrapper.GetNextSibling().IsValid());
|
|
|
|
wrapper = wrapper.GetFirstChild();
|
|
|
|
ASSERT_EQ(layers[2].get(), wrapper.GetLayer());
|
|
|
|
wrapper = wrapper.GetFirstChild();
|
|
|
|
ASSERT_EQ(layers[3].get(), wrapper.GetLayer());
|
|
|
|
ASSERT_FALSE(wrapper.GetFirstChild().IsValid());
|
|
|
|
wrapper = wrapper.GetNextSibling();
|
|
|
|
ASSERT_EQ(layers[4].get(), wrapper.GetLayer());
|
|
|
|
ASSERT_FALSE(wrapper.GetNextSibling().IsValid());
|
|
|
|
wrapper = wrapper.GetParent();
|
|
|
|
ASSERT_EQ(layers[2].get(), wrapper.GetLayer());
|
|
|
|
wrapper = wrapper.GetNextSibling();
|
|
|
|
ASSERT_EQ(layers[5].get(), wrapper.GetLayer());
|
|
|
|
ASSERT_FALSE(wrapper.GetNextSibling().IsValid());
|
|
|
|
wrapper = wrapper.GetLastChild();
|
|
|
|
ASSERT_EQ(layers[6].get(), wrapper.GetLayer());
|
|
|
|
wrapper = wrapper.GetParent();
|
|
|
|
ASSERT_EQ(layers[5].get(), wrapper.GetLayer());
|
|
|
|
LayerMetricsWrapper layer5 = wrapper;
|
|
|
|
wrapper = wrapper.GetPrevSibling();
|
|
|
|
ASSERT_EQ(layers[2].get(), wrapper.GetLayer());
|
|
|
|
wrapper = wrapper.GetParent();
|
|
|
|
ASSERT_EQ(layers[1].get(), wrapper.GetLayer());
|
|
|
|
ASSERT_TRUE(layer5 == wrapper.GetLastChild());
|
|
|
|
LayerMetricsWrapper rootWrapper(root);
|
|
|
|
ASSERT_TRUE(rootWrapper == wrapper.GetParent());
|
|
|
|
}
|
|
|
|
|
2018-11-01 20:15:46 +00:00
|
|
|
static ScrollMetadata MakeMetadata(ScrollableLayerGuid::ViewID aId) {
|
2016-03-28 23:14:52 +00:00
|
|
|
ScrollMetadata metadata;
|
|
|
|
metadata.GetMetrics().SetScrollId(aId);
|
|
|
|
return metadata;
|
2014-08-28 02:13:43 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 21:04:10 +00:00
|
|
|
TEST_F(LayerMetricsWrapperTester, MultiFramemetricsTree) {
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<Layer> > layers;
|
|
|
|
RefPtr<LayerManager> lm;
|
|
|
|
RefPtr<Layer> root =
|
|
|
|
CreateLayerTree("c(c(c(tt)c(t)))", nullptr, nullptr, lm, layers);
|
2014-08-28 02:13:43 +00:00
|
|
|
|
2016-03-28 23:14:52 +00:00
|
|
|
nsTArray<ScrollMetadata> metadata;
|
2018-11-01 20:15:46 +00:00
|
|
|
metadata.InsertElementAt(0,
|
|
|
|
MakeMetadata(ScrollableLayerGuid::START_SCROLL_ID +
|
|
|
|
0)); // topmost of root layer
|
|
|
|
metadata.InsertElementAt(0,
|
|
|
|
MakeMetadata(ScrollableLayerGuid::NULL_SCROLL_ID));
|
|
|
|
metadata.InsertElementAt(
|
|
|
|
0, MakeMetadata(ScrollableLayerGuid::START_SCROLL_ID + 1));
|
|
|
|
metadata.InsertElementAt(
|
|
|
|
0, MakeMetadata(ScrollableLayerGuid::START_SCROLL_ID + 2));
|
|
|
|
metadata.InsertElementAt(0,
|
|
|
|
MakeMetadata(ScrollableLayerGuid::NULL_SCROLL_ID));
|
|
|
|
metadata.InsertElementAt(
|
|
|
|
0, MakeMetadata(
|
|
|
|
ScrollableLayerGuid::NULL_SCROLL_ID)); // bottom of root layer
|
2016-03-28 23:14:52 +00:00
|
|
|
root->SetScrollMetadata(metadata);
|
|
|
|
|
|
|
|
metadata.Clear();
|
2018-11-01 20:15:46 +00:00
|
|
|
metadata.InsertElementAt(
|
|
|
|
0, MakeMetadata(ScrollableLayerGuid::START_SCROLL_ID + 3));
|
2016-03-28 23:14:52 +00:00
|
|
|
layers[1]->SetScrollMetadata(metadata);
|
|
|
|
|
|
|
|
metadata.Clear();
|
2018-11-01 20:15:46 +00:00
|
|
|
metadata.InsertElementAt(0,
|
|
|
|
MakeMetadata(ScrollableLayerGuid::NULL_SCROLL_ID));
|
|
|
|
metadata.InsertElementAt(
|
|
|
|
0, MakeMetadata(ScrollableLayerGuid::START_SCROLL_ID + 4));
|
2016-03-28 23:14:52 +00:00
|
|
|
layers[2]->SetScrollMetadata(metadata);
|
|
|
|
|
|
|
|
metadata.Clear();
|
2018-11-01 20:15:46 +00:00
|
|
|
metadata.InsertElementAt(
|
|
|
|
0, MakeMetadata(ScrollableLayerGuid::START_SCROLL_ID + 5));
|
2016-03-28 23:14:52 +00:00
|
|
|
layers[4]->SetScrollMetadata(metadata);
|
|
|
|
|
|
|
|
metadata.Clear();
|
2018-11-01 20:15:46 +00:00
|
|
|
metadata.InsertElementAt(
|
|
|
|
0, MakeMetadata(ScrollableLayerGuid::START_SCROLL_ID + 6));
|
2016-03-28 23:14:52 +00:00
|
|
|
layers[5]->SetScrollMetadata(metadata);
|
2014-08-28 02:13:43 +00:00
|
|
|
|
|
|
|
LayerMetricsWrapper wrapper(root, LayerMetricsWrapper::StartAt::TOP);
|
|
|
|
nsTArray<Layer*> expectedLayers;
|
|
|
|
expectedLayers.AppendElement(layers[0].get());
|
|
|
|
expectedLayers.AppendElement(layers[0].get());
|
|
|
|
expectedLayers.AppendElement(layers[0].get());
|
|
|
|
expectedLayers.AppendElement(layers[0].get());
|
|
|
|
expectedLayers.AppendElement(layers[0].get());
|
|
|
|
expectedLayers.AppendElement(layers[0].get());
|
|
|
|
expectedLayers.AppendElement(layers[1].get());
|
|
|
|
expectedLayers.AppendElement(layers[2].get());
|
|
|
|
expectedLayers.AppendElement(layers[2].get());
|
|
|
|
expectedLayers.AppendElement(layers[3].get());
|
2018-11-01 20:15:46 +00:00
|
|
|
nsTArray<ScrollableLayerGuid::ViewID> expectedIds;
|
|
|
|
expectedIds.AppendElement(ScrollableLayerGuid::START_SCROLL_ID + 0);
|
|
|
|
expectedIds.AppendElement(ScrollableLayerGuid::NULL_SCROLL_ID);
|
|
|
|
expectedIds.AppendElement(ScrollableLayerGuid::START_SCROLL_ID + 1);
|
|
|
|
expectedIds.AppendElement(ScrollableLayerGuid::START_SCROLL_ID + 2);
|
|
|
|
expectedIds.AppendElement(ScrollableLayerGuid::NULL_SCROLL_ID);
|
|
|
|
expectedIds.AppendElement(ScrollableLayerGuid::NULL_SCROLL_ID);
|
|
|
|
expectedIds.AppendElement(ScrollableLayerGuid::START_SCROLL_ID + 3);
|
|
|
|
expectedIds.AppendElement(ScrollableLayerGuid::NULL_SCROLL_ID);
|
|
|
|
expectedIds.AppendElement(ScrollableLayerGuid::START_SCROLL_ID + 4);
|
|
|
|
expectedIds.AppendElement(ScrollableLayerGuid::NULL_SCROLL_ID);
|
2014-08-28 02:13:43 +00:00
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
ASSERT_EQ(expectedLayers[i], wrapper.GetLayer());
|
|
|
|
ASSERT_EQ(expectedIds[i], wrapper.Metrics().GetScrollId());
|
|
|
|
wrapper = wrapper.GetFirstChild();
|
|
|
|
}
|
|
|
|
ASSERT_FALSE(wrapper.IsValid());
|
|
|
|
|
|
|
|
wrapper = LayerMetricsWrapper(root, LayerMetricsWrapper::StartAt::BOTTOM);
|
|
|
|
for (int i = 5; i < 10; i++) {
|
|
|
|
ASSERT_EQ(expectedLayers[i], wrapper.GetLayer());
|
|
|
|
ASSERT_EQ(expectedIds[i], wrapper.Metrics().GetScrollId());
|
|
|
|
wrapper = wrapper.GetFirstChild();
|
|
|
|
}
|
|
|
|
ASSERT_FALSE(wrapper.IsValid());
|
|
|
|
|
|
|
|
wrapper =
|
|
|
|
LayerMetricsWrapper(layers[4], LayerMetricsWrapper::StartAt::BOTTOM);
|
2018-11-01 20:15:46 +00:00
|
|
|
ASSERT_EQ(ScrollableLayerGuid::START_SCROLL_ID + 5,
|
|
|
|
wrapper.Metrics().GetScrollId());
|
2014-08-28 02:13:43 +00:00
|
|
|
wrapper = wrapper.GetParent();
|
2018-11-01 20:15:46 +00:00
|
|
|
ASSERT_EQ(ScrollableLayerGuid::START_SCROLL_ID + 4,
|
|
|
|
wrapper.Metrics().GetScrollId());
|
2014-08-28 02:13:43 +00:00
|
|
|
ASSERT_EQ(layers[2].get(), wrapper.GetLayer());
|
|
|
|
ASSERT_FALSE(wrapper.GetNextSibling().IsValid());
|
|
|
|
wrapper = wrapper.GetParent();
|
2018-11-01 20:15:46 +00:00
|
|
|
ASSERT_EQ(ScrollableLayerGuid::NULL_SCROLL_ID,
|
|
|
|
wrapper.Metrics().GetScrollId());
|
2014-08-28 02:13:43 +00:00
|
|
|
ASSERT_EQ(layers[2].get(), wrapper.GetLayer());
|
|
|
|
wrapper = wrapper.GetNextSibling();
|
2018-11-01 20:15:46 +00:00
|
|
|
ASSERT_EQ(ScrollableLayerGuid::START_SCROLL_ID + 6,
|
|
|
|
wrapper.Metrics().GetScrollId());
|
2014-08-28 02:13:43 +00:00
|
|
|
ASSERT_EQ(layers[5].get(), wrapper.GetLayer());
|
|
|
|
}
|