forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a unit test for PhysicalShapeLayer (flutter#8616)
An unnecessary PrerollContext copy is also removed. The added unit test will catch the error if we forget to subtract the elevation after the copy removal. This change has been tested with the framework (`flutter test --local-engine=host_debug_unopt`).
- Loading branch information
Showing
6 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/flow/layers/physical_shape_layer.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace flow { | ||
|
||
TEST(PhysicalShapeLayer, TotalElevation) { | ||
std::shared_ptr<PhysicalShapeLayer> layers[4]; | ||
|
||
for (int i = 0; i < 4; i += 1) { | ||
layers[i] = std::make_shared<PhysicalShapeLayer>(Clip::none); | ||
layers[i]->set_elevation((float)(i + 1)); | ||
} | ||
|
||
layers[0]->Add(layers[1]); | ||
layers[0]->Add(layers[2]); | ||
layers[2]->Add(layers[3]); | ||
|
||
const Stopwatch unused_stopwatch; | ||
TextureRegistry unused_texture_registry; | ||
PrerollContext preroll_context{ | ||
nullptr, // raster_cache (don't consult the cache) | ||
nullptr, // gr_context (used for the raster cache) | ||
nullptr, // external view embedder | ||
nullptr, // SkColorSpace* dst_color_space | ||
kGiantRect, // SkRect cull_rect | ||
unused_stopwatch, // frame time (dont care) | ||
unused_stopwatch, // engine time (dont care) | ||
unused_texture_registry, // texture registry (not supported) | ||
false, // checkerboard_offscreen_layers | ||
0.0f, // total elevation | ||
}; | ||
|
||
SkMatrix identity; | ||
identity.setIdentity(); | ||
|
||
layers[0]->Preroll(&preroll_context, identity); | ||
|
||
// It should look like this: | ||
// layers[0] +1.0f | ||
// | \ | ||
// | \ | ||
// | \ | ||
// | layers[2] +3.0f | ||
// | | | ||
// | layers[3] +4.0f | ||
// | | ||
// | | ||
// layers[1] + 2.0f | ||
EXPECT_EQ(layers[0]->total_elevation_, 1.0f); | ||
EXPECT_EQ(layers[1]->total_elevation_, 3.0f); | ||
EXPECT_EQ(layers[2]->total_elevation_, 4.0f); | ||
EXPECT_EQ(layers[3]->total_elevation_, 8.0f); | ||
} | ||
|
||
} // namespace flow |