mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-23 07:02:25 +00:00
add RS TDD
Signed-off-by: 李蔚 <liwei576@huawei.com>
This commit is contained in:
parent
e6f0fa161c
commit
525f89bad9
@ -0,0 +1,631 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* 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 "gtest/gtest.h"
|
||||
|
||||
#include "common/rs_obj_geometry.h"
|
||||
#include "draw/canvas.h"
|
||||
#include "modifier/rs_modifier_type.h"
|
||||
#include "params/rs_render_params.h"
|
||||
#include "pipeline/rs_canvas_drawing_render_node.h"
|
||||
#include "pipeline/rs_context.h"
|
||||
#include "property/rs_properties_painter.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class RSCanvasDrawingRenderNodeDrawableAdapterTest : public DrawableV2::RSRenderNodeDrawableAdapter {
|
||||
public:
|
||||
explicit RSCanvasDrawingRenderNodeDrawableAdapterTest(std::shared_ptr<const RSRenderNode> node)
|
||||
: RSRenderNodeDrawableAdapter(std::move(node))
|
||||
{}
|
||||
void Draw(Drawing::Canvas& canvas) {}
|
||||
};
|
||||
class RSCanvasRenderNodeTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
static inline NodeId id;
|
||||
static inline std::weak_ptr<RSContext> context = {};
|
||||
static inline RSPaintFilterCanvas* canvas_;
|
||||
static inline Drawing::Canvas drawingCanvas_;
|
||||
};
|
||||
|
||||
void RSCanvasRenderNodeTest::SetUpTestCase()
|
||||
{
|
||||
canvas_ = new RSPaintFilterCanvas(&drawingCanvas_);
|
||||
}
|
||||
void RSCanvasRenderNodeTest::TearDownTestCase()
|
||||
{
|
||||
if (canvas_) {
|
||||
delete canvas_;
|
||||
canvas_ = nullptr;
|
||||
}
|
||||
}
|
||||
void RSCanvasRenderNodeTest::SetUp() {}
|
||||
void RSCanvasRenderNodeTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: ProcessRenderContentsTest
|
||||
* @tc.desc: test results of ProcessRenderContents
|
||||
* @tc.type:FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, ProcessRenderContentsTest, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 1;
|
||||
std::weak_ptr<RSContext> context;
|
||||
RSCanvasDrawingRenderNode rsCanvasDrawingRenderNode(nodeId, context);
|
||||
rsCanvasDrawingRenderNode.ProcessRenderContents(*canvas_);
|
||||
|
||||
Drawing::Matrix matrix;
|
||||
PropertyId id = 1;
|
||||
std::shared_ptr<RSRenderProperty<Drawing::Matrix>> property =
|
||||
std::make_shared<RSRenderProperty<Drawing::Matrix>>(matrix, id);
|
||||
std::shared_ptr<RSGeometryTransRenderModifier> modifierCast =
|
||||
std::make_shared<RSGeometryTransRenderModifier>(property);
|
||||
std::shared_ptr<RSRenderModifier> modifier = modifierCast;
|
||||
modifierCast->drawStyle_ = RSModifierType::BOUNDS;
|
||||
rsCanvasDrawingRenderNode.boundsModifier_ = modifier;
|
||||
rsCanvasDrawingRenderNode.AddGeometryModifier(modifier);
|
||||
rsCanvasDrawingRenderNode.surface_ = std::make_shared<Drawing::Surface>();
|
||||
rsCanvasDrawingRenderNode.image_ = std::make_shared<Drawing::Image>();
|
||||
rsCanvasDrawingRenderNode.ProcessRenderContents(*canvas_);
|
||||
ASSERT_FALSE(rsCanvasDrawingRenderNode.isNeedProcess_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ProcessRenderContentsOtherTest
|
||||
* @tc.desc: test results of ProcessRenderContents other case
|
||||
* @tc.type:FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, ProcessRenderContentsOtherTest, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 1;
|
||||
RSCanvasDrawingRenderNode rsCanvasDrawingRenderNode(nodeId);
|
||||
// case 1: can GetSizeFromDrawCmdModifiers
|
||||
std::shared_ptr<Drawing::DrawCmdList> drawCmdList = std::make_shared<Drawing::DrawCmdList>();
|
||||
drawCmdList->SetWidth(1024);
|
||||
drawCmdList->SetHeight(1090);
|
||||
auto property = std::make_shared<RSRenderProperty<Drawing::DrawCmdListPtr>>();
|
||||
property->GetRef() = drawCmdList;
|
||||
std::list<std::shared_ptr<RSRenderModifier>> listModifier { std::make_shared<RSDrawCmdListRenderModifier>(
|
||||
property) };
|
||||
rsCanvasDrawingRenderNode.renderContent_->drawCmdModifiers_.emplace(RSModifierType::CONTENT_STYLE, listModifier);
|
||||
std::function<void(std::shared_ptr<Drawing::Surface>)> callbackFunc = [](std::shared_ptr<Drawing::Surface>) {
|
||||
printf("ProcessRenderContentsTest callbackFunc\n");
|
||||
};
|
||||
// case 1.1: IsNeedResetSurface
|
||||
rsCanvasDrawingRenderNode.preThreadInfo_.second = callbackFunc;
|
||||
rsCanvasDrawingRenderNode.ProcessRenderContents(*canvas_);
|
||||
// case 1.2: Isn't NeedResetSurface
|
||||
rsCanvasDrawingRenderNode.isGpuSurface_ = true;
|
||||
rsCanvasDrawingRenderNode.preThreadInfo_.first = 10;
|
||||
rsCanvasDrawingRenderNode.isNeedProcess_.store(true);
|
||||
rsCanvasDrawingRenderNode.ProcessRenderContents(*canvas_);
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode.isNeedProcess_);
|
||||
// case 2.2.1: can GetGravityMatrix, recordingCanvas_ is false
|
||||
rsCanvasDrawingRenderNode.isGpuSurface_ = false;
|
||||
rsCanvasDrawingRenderNode.GetMutableRenderProperties().frameGravity_ = Gravity::TOP;
|
||||
rsCanvasDrawingRenderNode.GetMutableRenderProperties().frameGeo_.SetHeight(3048.0f);
|
||||
rsCanvasDrawingRenderNode.GetMutableRenderProperties().frameGeo_.SetWidth(2048.0f);
|
||||
rsCanvasDrawingRenderNode.ProcessRenderContents(*canvas_);
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode.isNeedProcess_);
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode.recordingCanvas_ == nullptr);
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode.image_ != nullptr);
|
||||
EXPECT_FALSE(canvas_->GetRecordingState());
|
||||
// case 2.2.2: can GetGravityMatrix, recordingCanvas_ is true
|
||||
canvas_->SetRecordingState(true);
|
||||
rsCanvasDrawingRenderNode.ProcessRenderContents(*canvas_);
|
||||
canvas_->SetRecordingState(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ResetSurfaceTest
|
||||
* @tc.desc: test results of ResetSurface
|
||||
* @tc.type:FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, ResetSurfaceTest, TestSize.Level1)
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
NodeId nodeId = 1;
|
||||
std::weak_ptr<RSContext> context;
|
||||
RSCanvasDrawingRenderNode rsCanvasDrawingRenderNode(nodeId, context);
|
||||
auto res = rsCanvasDrawingRenderNode.ResetSurface(width, height, *canvas_);
|
||||
ASSERT_FALSE(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetSizeFromDrawCmdModifiersTest001
|
||||
* @tc.desc: test results of GetSizeFromDrawCmdModifiers
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, GetSizeFromDrawCmdModifiersTest001, TestSize.Level1)
|
||||
{
|
||||
int32_t width = 0;
|
||||
int32_t height = 0;
|
||||
NodeId nodeId = 1;
|
||||
std::weak_ptr<RSContext> context;
|
||||
RSCanvasDrawingRenderNode rsCanvasDrawingRenderNode(nodeId, context);
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode.GetSizeFromDrawCmdModifiers(width, height));
|
||||
|
||||
std::shared_ptr<Drawing::DrawCmdList> drawCmdList = std::make_shared<Drawing::DrawCmdList>(1024, 1090);
|
||||
auto property = std::make_shared<RSRenderProperty<Drawing::DrawCmdListPtr>>();
|
||||
property->GetRef() = drawCmdList;
|
||||
std::list<std::shared_ptr<RSRenderModifier>> listModifier { std::make_shared<RSDrawCmdListRenderModifier>(
|
||||
property) };
|
||||
rsCanvasDrawingRenderNode.renderContent_->drawCmdModifiers_.emplace(RSModifierType::CONTENT_STYLE, listModifier);
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode.GetSizeFromDrawCmdModifiers(width, height));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetSizeFromDrawCmdModifiersTest002
|
||||
* @tc.desc: test results of GetSizeFromDrawCmdModifiers
|
||||
* @tc.type:FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, GetSizeFromDrawCmdModifiersTest002, TestSize.Level1)
|
||||
{
|
||||
int width = -1;
|
||||
int height = -1;
|
||||
NodeId nodeId = 1;
|
||||
std::weak_ptr<RSContext> context;
|
||||
RSCanvasDrawingRenderNode rsCanvasDrawingRenderNode(nodeId, context);
|
||||
|
||||
Drawing::Matrix matrix;
|
||||
PropertyId id = 1;
|
||||
std::shared_ptr<RSRenderProperty<Drawing::Matrix>> property =
|
||||
std::make_shared<RSRenderProperty<Drawing::Matrix>>(matrix, id);
|
||||
std::shared_ptr<RSGeometryTransRenderModifier> modifierCast =
|
||||
std::make_shared<RSGeometryTransRenderModifier>(property);
|
||||
modifierCast->SetType(RSModifierType::CONTENT_STYLE);
|
||||
std::shared_ptr<RSRenderModifier> modifier = modifierCast;
|
||||
rsCanvasDrawingRenderNode.modifiers_.emplace(modifier->GetPropertyId(), modifier);
|
||||
auto res = rsCanvasDrawingRenderNode.GetSizeFromDrawCmdModifiers(width, height);
|
||||
ASSERT_FALSE(res);
|
||||
|
||||
width = 1;
|
||||
height = 1;
|
||||
ASSERT_FALSE(rsCanvasDrawingRenderNode.GetSizeFromDrawCmdModifiers(width, height));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetSizeFromDrawCmdModifiersTest003
|
||||
* @tc.desc: test results of GetSizeFromDrawCmdModifiers
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, GetSizeFromDrawCmdModifiersTest003, TestSize.Level1)
|
||||
{
|
||||
int32_t width = 0;
|
||||
int32_t height = 0;
|
||||
NodeId nodeId = 1;
|
||||
RSCanvasDrawingRenderNode rsCanvasDrawingRenderNode(nodeId);
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode.GetSizeFromDrawCmdModifiers(width, height));
|
||||
std::shared_ptr<Drawing::DrawCmdList> drawCmdList = std::make_shared<Drawing::DrawCmdList>(width, height);
|
||||
auto property = std::make_shared<RSRenderProperty<Drawing::DrawCmdListPtr>>();
|
||||
property->GetRef() = drawCmdList;
|
||||
std::list<std::shared_ptr<RSRenderModifier>> listModifier { std::make_shared<RSDrawCmdListRenderModifier>(
|
||||
property) };
|
||||
rsCanvasDrawingRenderNode.renderContent_->drawCmdModifiers_.emplace(RSModifierType::CONTENT_STYLE, listModifier);
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode.GetSizeFromDrawCmdModifiers(width, height));
|
||||
EXPECT_EQ(width, 0);
|
||||
EXPECT_EQ(height, 0);
|
||||
}
|
||||
/**
|
||||
* @tc.name: IsNeedResetSurfaceTest
|
||||
* @tc.desc: test results of IsNeedResetSurface
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, IsNeedResetSurfaceTest, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 1;
|
||||
std::weak_ptr<RSContext> context;
|
||||
RSCanvasDrawingRenderNode rsCanvasDrawingRenderNode(nodeId, context);
|
||||
rsCanvasDrawingRenderNode.surface_ = std::make_shared<Drawing::Surface>();
|
||||
ASSERT_TRUE(rsCanvasDrawingRenderNode.IsNeedResetSurface());
|
||||
|
||||
int32_t width = 1024;
|
||||
int32_t height = 2468;
|
||||
rsCanvasDrawingRenderNode.surface_->cachedCanvas_ = std::make_shared<Drawing::Canvas>(width, height);
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode.IsNeedResetSurface());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @tc.name: InitRenderParamsTest
|
||||
* @tc.desc: test results of InitRenderParams
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, InitRenderParamsTest, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 1;
|
||||
auto rsCanvasDrawingRenderNode = std::make_shared<RSCanvasDrawingRenderNode>(nodeId);
|
||||
rsCanvasDrawingRenderNode->InitRenderParams();
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode->renderDrawable_ == nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PlaybackInCorrespondThread
|
||||
* @tc.desc: test results of PlaybackInCorrespondThread
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, PlaybackInCorrespondThread, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 1;
|
||||
std::shared_ptr<RSContext> sharedContext = std::make_shared<RSContext>();
|
||||
std::weak_ptr<RSContext> context = sharedContext;
|
||||
auto rsCanvasDrawingRenderNode = std::make_shared<RSCanvasDrawingRenderNode>(nodeId, context);
|
||||
auto ctxNode =
|
||||
context.lock()->GetNodeMap().GetRenderNode<RSCanvasDrawingRenderNode>(rsCanvasDrawingRenderNode->GetId());
|
||||
EXPECT_TRUE(ctxNode == nullptr);
|
||||
rsCanvasDrawingRenderNode->PlaybackInCorrespondThread();
|
||||
|
||||
auto& ctxNodeMap = context.lock()->GetMutableNodeMap();
|
||||
ctxNodeMap.renderNodeMap_[rsCanvasDrawingRenderNode->GetId()] = rsCanvasDrawingRenderNode;
|
||||
ctxNode = context.lock()->GetNodeMap().GetRenderNode<RSCanvasDrawingRenderNode>(rsCanvasDrawingRenderNode->GetId());
|
||||
EXPECT_TRUE(ctxNode != nullptr);
|
||||
int32_t width = 1;
|
||||
int32_t height = 1;
|
||||
Drawing::Canvas canvas(width, height);
|
||||
rsCanvasDrawingRenderNode->canvas_ = std::make_unique<RSPaintFilterCanvas>(&canvas);
|
||||
rsCanvasDrawingRenderNode->PlaybackInCorrespondThread();
|
||||
rsCanvasDrawingRenderNode->surface_ = std::make_shared<Drawing::Surface>();
|
||||
rsCanvasDrawingRenderNode->isNeedProcess_.store(true);
|
||||
rsCanvasDrawingRenderNode->PlaybackInCorrespondThread();
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode->isNeedProcess_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ApplyDrawCmdModifier
|
||||
* @tc.desc: test results of ApplyDrawCmdModifier
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, ApplyDrawCmdModifier, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 1;
|
||||
std::weak_ptr<RSContext> context;
|
||||
RSCanvasDrawingRenderNode rsCanvasDrawingRenderNode(nodeId, context);
|
||||
|
||||
RSProperties properties;
|
||||
RSModifierContext contextArgs(properties);
|
||||
rsCanvasDrawingRenderNode.ApplyDrawCmdModifier(contextArgs, RSModifierType::CONTENT_STYLE);
|
||||
|
||||
int width = 1024;
|
||||
int hight = 1090;
|
||||
auto type = RSModifierType::CONTENT_STYLE;
|
||||
std::list<Drawing::DrawCmdListPtr> listDrawCmd { std::make_shared<Drawing::DrawCmdList>(width, hight) };
|
||||
rsCanvasDrawingRenderNode.drawCmdLists_.emplace(type, listDrawCmd);
|
||||
auto it = rsCanvasDrawingRenderNode.drawCmdLists_.find(type);
|
||||
EXPECT_FALSE(it == rsCanvasDrawingRenderNode.drawCmdLists_.end() || it->second.empty());
|
||||
Drawing::Canvas canvas(width, hight);
|
||||
RSPaintFilterCanvas paintCanvas(&canvas);
|
||||
contextArgs.canvas_ = &paintCanvas;
|
||||
rsCanvasDrawingRenderNode.ApplyDrawCmdModifier(contextArgs, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetBitmap
|
||||
* @tc.desc: test results of GetBitmap
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, GetBitmap, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 1;
|
||||
std::weak_ptr<RSContext> context;
|
||||
RSCanvasDrawingRenderNode rsCanvasDrawingRenderNode(nodeId, context);
|
||||
uint64_t tid = 1;
|
||||
rsCanvasDrawingRenderNode.GetBitmap(tid);
|
||||
|
||||
rsCanvasDrawingRenderNode.image_ = std::make_shared<Drawing::Image>();
|
||||
Drawing::Bitmap bitmap;
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode.image_->AsLegacyBitmap(bitmap));
|
||||
ASSERT_NE(rsCanvasDrawingRenderNode.GetBitmap(tid).bmpImplPtr, nullptr);
|
||||
|
||||
rsCanvasDrawingRenderNode.GetBitmap();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetPixelmap
|
||||
* @tc.desc: test results of GetPixelmap
|
||||
* @tc.type:FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, GetPixelmap, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 1;
|
||||
std::weak_ptr<RSContext> context;
|
||||
RSCanvasDrawingRenderNode rsCanvasDrawingRenderNode(nodeId, context);
|
||||
uint64_t tid = 1;
|
||||
int32_t width = 1;
|
||||
int32_t height = 1;
|
||||
{
|
||||
std::shared_ptr<Media::PixelMap> pixelmap = std::make_shared<Media::PixelMap>();
|
||||
Drawing::Rect rect(1, 1, 1, 1);
|
||||
std::shared_ptr<Drawing::DrawCmdList> drawCmdList = std::make_shared<Drawing::DrawCmdList>(width, height);
|
||||
ASSERT_FALSE(rsCanvasDrawingRenderNode.GetPixelmap(pixelmap, &rect, tid, drawCmdList));
|
||||
}
|
||||
{
|
||||
std::shared_ptr<Media::PixelMap> pixelmap;
|
||||
Drawing::Rect* rect = nullptr;
|
||||
std::shared_ptr<Drawing::DrawCmdList> drawCmdList = std::make_shared<Drawing::DrawCmdList>(width, height);
|
||||
ASSERT_FALSE(rsCanvasDrawingRenderNode.GetPixelmap(pixelmap, rect, tid, drawCmdList));
|
||||
}
|
||||
{
|
||||
std::shared_ptr<Media::PixelMap> pixelmap = std::make_shared<Media::PixelMap>();
|
||||
Drawing::Rect rect(1, 1, 1, 1);
|
||||
std::shared_ptr<Drawing::DrawCmdList> drawCmdList = std::make_shared<Drawing::DrawCmdList>(width, height);
|
||||
rsCanvasDrawingRenderNode.surface_ = std::make_shared<Drawing::Surface>();
|
||||
uint64_t tidTwo = OHOS::Rosen::UNI_MAIN_THREAD_INDEX;
|
||||
ASSERT_FALSE(rsCanvasDrawingRenderNode.GetPixelmap(pixelmap, &rect, tid, drawCmdList));
|
||||
ASSERT_FALSE(rsCanvasDrawingRenderNode.GetPixelmap(pixelmap, &rect, tidTwo, drawCmdList));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetPixelmapSurfaceImgValidTest
|
||||
* @tc.desc: test results of GetPixelmapSurfaceImgValid
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, GetPixelmapSurfaceImgValidTest, TestSize.Level1)
|
||||
{
|
||||
uint64_t tid = 1;
|
||||
NodeId nodeId = 2;
|
||||
auto rsCanvasDrawingRenderNode = std::make_shared<RSCanvasDrawingRenderNode>(nodeId);
|
||||
std::shared_ptr<Media::PixelMap> pixelmap = std::make_shared<Media::PixelMap>();
|
||||
Drawing::Rect rect(1, 2, 3, 4);
|
||||
std::shared_ptr<Drawing::DrawCmdList> drawCmdList;
|
||||
rsCanvasDrawingRenderNode->surface_ = std::make_shared<Drawing::Surface>();
|
||||
Drawing::BitmapFormat bitmapFormat { Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_OPAQUE };
|
||||
Drawing::Bitmap bitmap;
|
||||
bitmap.Build(10, 10, bitmapFormat);
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode->surface_->Bind(bitmap));
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode->surface_->GetImageSnapshot() != nullptr);
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode->GetPixelmap(pixelmap, &rect, tid, drawCmdList));
|
||||
|
||||
tid = rsCanvasDrawingRenderNode->GetTid();
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode->GetPixelmap(pixelmap, &rect, tid, drawCmdList));
|
||||
|
||||
#if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
|
||||
int32_t width = 1024;
|
||||
int32_t height = 2468;
|
||||
drawCmdList = std::make_shared<Drawing::DrawCmdList>(width, height);
|
||||
Drawing::Canvas canvas(width, height);
|
||||
rsCanvasDrawingRenderNode->canvas_ = std::make_unique<RSPaintFilterCanvas>(&canvas);
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode->canvas_->GetGPUContext() == nullptr);
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode->GetPixelmap(pixelmap, &rect, tid, drawCmdList));
|
||||
|
||||
rsCanvasDrawingRenderNode->canvas_->gpuContext_ = std::make_shared<Drawing::GPUContext>();
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode->GetPixelmap(pixelmap, &rect, tid, drawCmdList));
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AddDirtyType
|
||||
* @tc.desc: test results of AddDirtyType
|
||||
* @tc.type:FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, AddDirtyType, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 1;
|
||||
std::weak_ptr<RSContext> context;
|
||||
RSCanvasDrawingRenderNode rsCanvasDrawingRenderNode(nodeId, context);
|
||||
Drawing::Matrix matrix;
|
||||
PropertyId id = 1;
|
||||
std::shared_ptr<RSRenderProperty<Drawing::Matrix>> property =
|
||||
std::make_shared<RSRenderProperty<Drawing::Matrix>>(matrix, id);
|
||||
std::shared_ptr<RSGeometryTransRenderModifier> modifierCast =
|
||||
std::make_shared<RSGeometryTransRenderModifier>(property);
|
||||
std::shared_ptr<RSRenderModifier> modifier = modifierCast;
|
||||
modifierCast->drawStyle_ = RSModifierType::BOUNDS;
|
||||
rsCanvasDrawingRenderNode.boundsModifier_ = modifier;
|
||||
rsCanvasDrawingRenderNode.AddGeometryModifier(modifier);
|
||||
rsCanvasDrawingRenderNode.AddDirtyType(RSModifierType::BLOOM);
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode.isNeedProcess_);
|
||||
|
||||
int32_t width = 1024;
|
||||
int32_t height = 2468;
|
||||
auto type = RSModifierType::CONTENT_STYLE;
|
||||
std::shared_ptr<Drawing::DrawCmdList> drawCmdList = std::make_shared<Drawing::DrawCmdList>(width, height);
|
||||
auto property1 = std::make_shared<RSRenderProperty<Drawing::DrawCmdListPtr>>();
|
||||
property1->GetRef() = drawCmdList;
|
||||
std::list<std::shared_ptr<RSRenderModifier>> listModifier { std::make_shared<RSDrawCmdListRenderModifier>(
|
||||
property1) };
|
||||
std::shared_ptr<RSDrawCmdListRenderModifier> modifier1;
|
||||
listModifier.emplace_back(modifier1);
|
||||
auto property2 = std::make_shared<RSRenderProperty<Drawing::DrawCmdListPtr>>();
|
||||
auto modifier2 = std::make_shared<RSDrawCmdListRenderModifier>(property2);
|
||||
listModifier.emplace_back(modifier2);
|
||||
rsCanvasDrawingRenderNode.renderContent_->drawCmdModifiers_.emplace(type, listModifier);
|
||||
std::list<Drawing::DrawCmdListPtr> listDrawCmd;
|
||||
auto listDrawCmdMax = 20;
|
||||
for (int i = 0; i < listDrawCmdMax; ++i) {
|
||||
listDrawCmd.emplace_back(std::make_shared<Drawing::DrawCmdList>(width + i, height + i));
|
||||
}
|
||||
rsCanvasDrawingRenderNode.drawCmdLists_.emplace(type, listDrawCmd);
|
||||
rsCanvasDrawingRenderNode.AddDirtyType(type);
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode.isNeedProcess_);
|
||||
rsCanvasDrawingRenderNode.ClearOp();
|
||||
const auto& curDrawCmdLists = rsCanvasDrawingRenderNode.GetDrawCmdLists();
|
||||
EXPECT_TRUE(curDrawCmdLists.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ResetSurface
|
||||
* @tc.desc: test results of ResetSurface
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, ResetSurface, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 1;
|
||||
std::weak_ptr<RSContext> context;
|
||||
int width = 1;
|
||||
int height = 1;
|
||||
RSCanvasDrawingRenderNode rsCanvasDrawingRenderNode(nodeId, context);
|
||||
rsCanvasDrawingRenderNode.stagingRenderParams_ = std::make_unique<RSRenderParams>(nodeId);
|
||||
rsCanvasDrawingRenderNode.ResetSurface(width, height);
|
||||
ASSERT_EQ(rsCanvasDrawingRenderNode.surface_, nullptr);
|
||||
|
||||
rsCanvasDrawingRenderNode.surface_ = std::make_shared<Drawing::Surface>();
|
||||
std::function<void(std::shared_ptr<Drawing::Surface>)> callBackFunc = [](std::shared_ptr<Drawing::Surface>) {
|
||||
printf("ResetSurface preThreadInfo_ callBackFunc\n");
|
||||
};
|
||||
rsCanvasDrawingRenderNode.preThreadInfo_.second = callBackFunc;
|
||||
ASSERT_TRUE(rsCanvasDrawingRenderNode.preThreadInfo_.second && rsCanvasDrawingRenderNode.surface_);
|
||||
rsCanvasDrawingRenderNode.ResetSurface(width, height);
|
||||
ASSERT_EQ(rsCanvasDrawingRenderNode.surface_, nullptr);
|
||||
|
||||
#if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
|
||||
Drawing::Canvas canvas(1024, 1096);
|
||||
RSPaintFilterCanvas paintCanvas(&canvas);
|
||||
EXPECT_TRUE(paintCanvas.GetGPUContext() == nullptr);
|
||||
auto ret = rsCanvasDrawingRenderNode.ResetSurface(canvas.GetWidth() + 10, canvas.GetHeight() + 10, paintCanvas);
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
paintCanvas.canvas_->gpuContext_ = std::make_shared<Drawing::GPUContext>();
|
||||
EXPECT_TRUE(paintCanvas.GetGPUContext() != nullptr);
|
||||
ret = rsCanvasDrawingRenderNode.ResetSurface(canvas.GetWidth() + 20, canvas.GetHeight() + 20, paintCanvas);
|
||||
EXPECT_TRUE(ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ResetSurfaceWithTextureTest
|
||||
* @tc.desc: Test ResetSurfaceWithTexture
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, ResetSurfaceWithTextureTest, TestSize.Level1)
|
||||
{
|
||||
#if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
|
||||
NodeId nodeId = 2;
|
||||
auto rsCanvasDrawingRenderNode = std::make_shared<RSCanvasDrawingRenderNode>(nodeId);
|
||||
rsCanvasDrawingRenderNode->surface_ = std::make_shared<Drawing::Surface>();
|
||||
int width = 1024;
|
||||
int height = 1920;
|
||||
Drawing::Canvas canvas(width, height);
|
||||
RSPaintFilterCanvas paintCanvas(&canvas);
|
||||
auto ret = rsCanvasDrawingRenderNode->ResetSurface(width + 10, height + 10, paintCanvas);
|
||||
EXPECT_TRUE(ret);
|
||||
auto preSurface = rsCanvasDrawingRenderNode->surface_;
|
||||
ret = rsCanvasDrawingRenderNode->ResetSurfaceWithTexture(width, height, paintCanvas);
|
||||
EXPECT_FALSE(ret);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsNeedProcessTest
|
||||
* @tc.desc: Test IsNeedProcess
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, IsNeedProcessTest, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 3;
|
||||
auto rsCanvasDrawingRenderNode = std::make_shared<RSCanvasDrawingRenderNode>(nodeId);
|
||||
std::shared_ptr<const RSRenderNode> otherNode = std::make_shared<const RSRenderNode>(nodeId + 1);
|
||||
rsCanvasDrawingRenderNode->renderDrawable_ =
|
||||
std::make_shared<RSCanvasDrawingRenderNodeDrawableAdapterTest>(otherNode);
|
||||
rsCanvasDrawingRenderNode->renderDrawable_->renderParams_ = std::make_unique<RSRenderParams>(nodeId);
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode->IsNeedProcess());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetNeedProcessTest
|
||||
* @tc.desc: Test SetNeedProcess
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, SetNeedProcessTest, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 4;
|
||||
auto rsCanvasDrawingRenderNode = std::make_shared<RSCanvasDrawingRenderNode>(nodeId);
|
||||
rsCanvasDrawingRenderNode->stagingRenderParams_ = std::make_unique<RSRenderParams>(nodeId);
|
||||
bool needProcess = true;
|
||||
rsCanvasDrawingRenderNode->SetNeedProcess(needProcess);
|
||||
EXPECT_FALSE(rsCanvasDrawingRenderNode->stagingRenderParams_->NeedSync());
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode->isNeedProcess_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetTidTest
|
||||
* @tc.desc: Test GetTid
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, GetTidTest, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 5;
|
||||
auto rsCanvasDrawingRenderNode = std::make_shared<RSCanvasDrawingRenderNode>(nodeId);
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode->drawingNodeRenderID != UNI_RENDER_THREAD_INDEX);
|
||||
rsCanvasDrawingRenderNode->GetTid();
|
||||
|
||||
rsCanvasDrawingRenderNode->drawingNodeRenderID = UNI_RENDER_THREAD_INDEX;
|
||||
rsCanvasDrawingRenderNode->GetTid();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetImageTest
|
||||
* @tc.desc: Test GetImage
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, GetImageTest, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 6;
|
||||
auto rsCanvasDrawingRenderNode = std::make_shared<RSCanvasDrawingRenderNode>(nodeId);
|
||||
uint64_t tid = 1;
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode->GetTid() != tid);
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode->GetImage(tid) == nullptr);
|
||||
tid = rsCanvasDrawingRenderNode->GetTid();
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode->image_ == nullptr);
|
||||
EXPECT_TRUE(rsCanvasDrawingRenderNode->GetImage(tid) == nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ClearResourceTest
|
||||
* @tc.desc: Test ClearResource
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9W0GK
|
||||
*/
|
||||
HWTEST_F(RSCanvasRenderNodeTest, ClearResourceTest, TestSize.Level1)
|
||||
{
|
||||
NodeId nodeId = 7;
|
||||
auto rsCanvasDrawingRenderNode = std::make_shared<RSCanvasDrawingRenderNode>(nodeId);
|
||||
auto drawable = DrawableV2::RSRenderNodeDrawableAdapter::OnGenerate(rsCanvasDrawingRenderNode);
|
||||
if (!drawable) {
|
||||
return;
|
||||
}
|
||||
EXPECT_FALSE(drawable == nullptr);
|
||||
rsCanvasDrawingRenderNode->ClearResource();
|
||||
auto lists = rsCanvasDrawingRenderNode->GetDrawCmdLists();
|
||||
EXPECT_TRUE(lists.empty());
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* 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 "gtest/gtest.h"
|
||||
#include "pipeline/rs_context.h"
|
||||
#include "pipeline/rs_render_node.h"
|
||||
#include "platform/common/rs_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class RSRenderContextTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
};
|
||||
|
||||
void RSRenderContextTest::SetUpTestCase() {}
|
||||
void RSRenderContextTest::TearDownTestCase() {}
|
||||
void RSRenderContextTest::SetUp() {}
|
||||
void RSRenderContextTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: AnNodeRecordOrDeleteTest001
|
||||
* @tc.desc: AnimationNodeRecordOrDelete test.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issuesI9J766
|
||||
*/
|
||||
HWTEST_F(RSRenderContextTest, AnNodeRecordOrDeleteTest001, TestSize.Level1)
|
||||
{
|
||||
RSContext rSContext;
|
||||
std::shared_ptr<RSRenderNode> nodePtr = std::make_shared<RSRenderNode>(1);
|
||||
EXPECT_TRUE(nodePtr);
|
||||
rSContext.RegisterAnimatingRenderNode(nodePtr);
|
||||
rSContext.UnregisterAnimatingRenderNode(1);
|
||||
}
|
||||
/**
|
||||
* @tc.name: ActivityNodesRecordTest002
|
||||
* @tc.desc: ActivityNodesRecord test.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issuesI9J766
|
||||
*/
|
||||
HWTEST_F(RSRenderContextTest, ActivityNodesRecordTest002, TestSize.Level1)
|
||||
{
|
||||
RSContext rSContext;
|
||||
|
||||
// is nodePtr nullptr handling
|
||||
std::shared_ptr<RSRenderNode> nodePtr = nullptr;
|
||||
rSContext.AddActiveNode(nodePtr);
|
||||
EXPECT_FALSE(rSContext.HasActiveNode(nodePtr));
|
||||
|
||||
// is nodePtr invalid value handling
|
||||
nodePtr = std::make_shared<RSRenderNode>(INVALID_NODEID);
|
||||
EXPECT_TRUE(nodePtr);
|
||||
rSContext.AddActiveNode(nodePtr);
|
||||
EXPECT_FALSE(rSContext.HasActiveNode(nodePtr));
|
||||
|
||||
// is nodePtr effective value handling
|
||||
nodePtr = std::make_shared<RSRenderNode>(1);
|
||||
EXPECT_TRUE(nodePtr);
|
||||
rSContext.AddActiveNode(nodePtr);
|
||||
EXPECT_TRUE(rSContext.HasActiveNode(nodePtr));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PendingSyncNodesRecordTest003
|
||||
* @tc.desc: PendingSyncNodesRecord test.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issuesI9J766
|
||||
*/
|
||||
HWTEST_F(RSRenderContextTest, PendingSyncNodesRecordTest003, TestSize.Level1)
|
||||
{
|
||||
RSContext rSContext;
|
||||
|
||||
// is nodePtr nullptr handling
|
||||
std::shared_ptr<RSRenderNode> nodePtr = nullptr;
|
||||
rSContext.AddPendingSyncNode(nodePtr);
|
||||
|
||||
// is nodePtr invalid value handling
|
||||
nodePtr = std::make_shared<RSRenderNode>(INVALID_NODEID);
|
||||
EXPECT_TRUE(nodePtr);
|
||||
rSContext.AddPendingSyncNode(nodePtr);
|
||||
|
||||
// is nodePtr effective value handling
|
||||
nodePtr = std::make_shared<RSRenderNode>(1);
|
||||
EXPECT_TRUE(nodePtr);
|
||||
rSContext.AddPendingSyncNode(nodePtr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TaskRunnerTest004
|
||||
* @tc.desc: TaskRunner test.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issuesI9J766
|
||||
*/
|
||||
HWTEST_F(RSRenderContextTest, TaskRunnerTest004, TestSize.Level1)
|
||||
{
|
||||
RSContext rSContext;
|
||||
|
||||
// Set Task Runner
|
||||
auto taskRunner = [](const std::function<void()>& task, bool isSyncTask) {};
|
||||
rSContext.SetTaskRunner(taskRunner);
|
||||
auto taskRunnerTest = []() {};
|
||||
rSContext.PostTask(taskRunnerTest, true);
|
||||
|
||||
// Set RTTask Runner
|
||||
auto rtTaskRunner = [](const std::function<void()>& task) {};
|
||||
rSContext.SetRTTaskRunner(rtTaskRunner);
|
||||
rSContext.PostRTTask(taskRunnerTest);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InitializeTest005
|
||||
* @tc.desc: Initialize test.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issuesI9J766
|
||||
*/
|
||||
HWTEST_F(RSRenderContextTest, InitializeTest005, TestSize.Level1)
|
||||
{
|
||||
RSContext rSContext;
|
||||
rSContext.Initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UiFrameworkTest
|
||||
* @tc.desc: UiFramework test.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: IAJ46S
|
||||
*/
|
||||
HWTEST_F(RSRenderContextTest, UiFrameworkTest, TestSize.Level1)
|
||||
{
|
||||
RSContext rSContext;
|
||||
std::vector<std::string> uiFrameworkTypeTable = { "0" };
|
||||
rSContext.SetUiFrameworkTypeTable(uiFrameworkTypeTable);
|
||||
auto uiFwkTypeTable = rSContext.GetUiFrameworkTypeTable();
|
||||
auto ret = uiFwkTypeTable.size();
|
||||
EXPECT_GT(ret, 0);
|
||||
|
||||
auto dirtyNode = std::make_shared<RSRenderNode>(0);
|
||||
rSContext.UpdateUiFrameworkDirtyNodes(dirtyNode);
|
||||
auto dirtyNodes = rSContext.GetUiFrameworkDirtyNodes();
|
||||
ret = dirtyNodes.size();
|
||||
EXPECT_GT(ret, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetRequestedNextVsyncAnimateTest007
|
||||
* @tc.desc: SetRequestedNextVsyncAnimate test.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: IAJ46S
|
||||
*/
|
||||
HWTEST_F(RSRenderContextTest, SetRequestedNextVsyncAnimateTest007, TestSize.Level1)
|
||||
{
|
||||
RSContext rSContext;
|
||||
rSContext.SetRequestedNextVsyncAnimate(true);
|
||||
auto ret = rSContext.IsRequestedNextVsyncAnimate();
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAnimatingNodeListTest001
|
||||
* @tc.desc: GetAnimatingNodeList test.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: IAYANC
|
||||
*/
|
||||
HWTEST_F(RSRenderContextTest, GetAnimatingNodeListTest001, TestSize.Level1)
|
||||
{
|
||||
RSContext rSContext;
|
||||
EXPECT_TRUE(rSContext.GetAnimatingNodeList().empty());
|
||||
std::shared_ptr<RSRenderNode> nodePtr = std::make_shared<RSRenderNode>(1);
|
||||
EXPECT_TRUE(nodePtr);
|
||||
rSContext.RegisterAnimatingRenderNode(nodePtr);
|
||||
EXPECT_EQ(rSContext.GetAnimatingNodeList().size(), 1);
|
||||
rSContext.UnregisterAnimatingRenderNode(1);
|
||||
EXPECT_TRUE(rSContext.GetAnimatingNodeList().empty());
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* 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 "gtest/gtest.h"
|
||||
|
||||
#include "pipeline/rs_task_dispatcher.h"
|
||||
#include "pipeline/sk_resource_manager.h"
|
||||
#include "platform/common/rs_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class RSSKResourceManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase() {}
|
||||
static void TearDownTestCase() {}
|
||||
void SetUp() override {}
|
||||
void TearDown() override;
|
||||
|
||||
private:
|
||||
SKResourceManager skResManager_;
|
||||
};
|
||||
void RSSKResourceManagerTest::TearDown()
|
||||
{
|
||||
RSTaskDispatcher::GetInstance().taskDispatchFuncMap_.clear();
|
||||
}
|
||||
|
||||
static inline void TaskDispatchFunc(const RSTaskDispatcher::RSTask& task, bool isSyncTask = false)
|
||||
{
|
||||
ROSEN_LOGI("%{public}s:%{public}d TaskDispatchFunc!", __func__, __LINE__);
|
||||
if (task) {
|
||||
ROSEN_LOGI("%{public}s:%{public}d call task!", __func__, __LINE__);
|
||||
task();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HoldResourceImg001
|
||||
* @tc.desc: test hold resource of image
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9IUKU
|
||||
*/
|
||||
HWTEST_F(RSSKResourceManagerTest, HoldResourceImg001, TestSize.Level1)
|
||||
{
|
||||
#ifdef ROSEN_OHOS
|
||||
auto img = std::make_shared<Drawing::Image>();
|
||||
// case 1: Task is not registered, should return immediately
|
||||
skResManager_.HoldResource(img);
|
||||
EXPECT_TRUE(skResManager_.images_.empty());
|
||||
|
||||
// case 2: Task is registered, the img push back to the images_
|
||||
RSTaskDispatcher::GetInstance().RegisterTaskDispatchFunc(gettid(), TaskDispatchFunc);
|
||||
skResManager_.HoldResource(img);
|
||||
EXPECT_EQ(skResManager_.images_.size(), 1);
|
||||
|
||||
// case 3: the img already exists
|
||||
skResManager_.HoldResource(img);
|
||||
EXPECT_EQ(skResManager_.images_.size(), 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HoldResourceSurface001
|
||||
* @tc.desc: test hold resource surfacePtr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9IUKU
|
||||
*/
|
||||
HWTEST_F(RSSKResourceManagerTest, HoldResourceSurface001, TestSize.Level1)
|
||||
{
|
||||
#ifdef ROSEN_OHOS
|
||||
auto surfacePtr = std::make_shared<Drawing::Surface>();
|
||||
// case 1: Task is not registered, should return immediately
|
||||
skResManager_.HoldResource(surfacePtr);
|
||||
EXPECT_TRUE(skResManager_.skSurfaces_.empty());
|
||||
|
||||
// case 2: Task is registered, the surfacePtr push back to the skSurfaces_
|
||||
RSTaskDispatcher::GetInstance().RegisterTaskDispatchFunc(gettid(), TaskDispatchFunc);
|
||||
skResManager_.HoldResource(surfacePtr);
|
||||
EXPECT_EQ(skResManager_.skSurfaces_.size(), 1);
|
||||
|
||||
// case 3: the surfacePtr already exists
|
||||
skResManager_.HoldResource(surfacePtr);
|
||||
EXPECT_EQ(skResManager_.skSurfaces_.size(), 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReleaseResource001
|
||||
* @tc.desc: test release resource
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI9IUKU
|
||||
*/
|
||||
HWTEST_F(RSSKResourceManagerTest, ReleaseResource001, TestSize.Level1)
|
||||
{
|
||||
#ifdef ROSEN_OHOS
|
||||
RSTaskDispatcher::GetInstance().RegisterTaskDispatchFunc(gettid(), TaskDispatchFunc);
|
||||
// case 1: images_ isn't empty
|
||||
{
|
||||
auto img = std::make_shared<Drawing::Image>();
|
||||
skResManager_.HoldResource(img);
|
||||
EXPECT_EQ(skResManager_.images_.size(), 1);
|
||||
}
|
||||
skResManager_.ReleaseResource();
|
||||
for (auto& images : skResManager_.images_) {
|
||||
EXPECT_TRUE(images.second->IsEmpty());
|
||||
}
|
||||
|
||||
// case 2: skSurfaces_ isn't empty
|
||||
{
|
||||
auto validDrawingSurface = std::make_shared<Drawing::Surface>();
|
||||
skResManager_.HoldResource(validDrawingSurface);
|
||||
std::shared_ptr<Drawing::Surface> nullDrawingSurface;
|
||||
skResManager_.HoldResource(nullDrawingSurface);
|
||||
auto newValidDrawingSurface = std::make_shared<Drawing::Surface>();
|
||||
skResManager_.HoldResource(newValidDrawingSurface);
|
||||
EXPECT_EQ(skResManager_.skSurfaces_.size(), 1);
|
||||
}
|
||||
skResManager_.ReleaseResource();
|
||||
for (auto& skSurface : skResManager_.skSurfaces_) {
|
||||
EXPECT_TRUE(skSurface.second.empty());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace OHOS::Rosen
|
Loading…
Reference in New Issue
Block a user