mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-23 15:11:51 +00:00
add testcase
Signed-off-by: lishijie <lishijie22@huawei.com> Change-Id: Ie8c9e161a527d3307d3c349375bc08e63a11a19a
This commit is contained in:
parent
687a716f61
commit
e73632be6a
@ -0,0 +1,529 @@
|
||||
/*
|
||||
* 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, Hardware
|
||||
* 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_divided_render_util.h"
|
||||
#include "pipeline/rs_render_engine.h"
|
||||
#include "rs_test_util.h"
|
||||
#include "pipeline/rs_surface_capture_task.h"
|
||||
#include "pipeline/rs_uni_render_judgement.h"
|
||||
#include "recording/recording_canvas.h"
|
||||
#include "pipeline/rs_uni_render_engine.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace {
|
||||
constexpr float DEFAULT_BOUNDS_WIDTH = 100.f;
|
||||
constexpr uint32_t DEFAULT_CANVAS_WIDTH = 800;
|
||||
constexpr uint32_t DEFAULT_CANVAS_HEIGHT = 600;
|
||||
constexpr uint32_t DEFAULT_DRAWING_CANVAS_WIDTH = 10;
|
||||
constexpr uint32_t DEFAULT_DRAWING_CANVAS_HEIGHT = 10;
|
||||
}
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class RSGraphicEngineTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
};
|
||||
|
||||
std::shared_ptr<RSSurfaceCaptureVisitor> visitor_;
|
||||
std::shared_ptr<Drawing::Canvas> drawingCanvas_;
|
||||
std::shared_ptr<Drawing::RecordingCanvas> drawingRecordingCanvas_ = nullptr;
|
||||
|
||||
void RSGraphicEngineTest::SetUpTestCase()
|
||||
{
|
||||
drawingCanvas_ = std::make_shared<Drawing::Canvas>(DEFAULT_CANVAS_WIDTH, DEFAULT_CANVAS_HEIGHT);
|
||||
bool isUnirender = RSUniRenderJudgement::IsUniRender();
|
||||
RSSurfaceCaptureConfig captureConfig;
|
||||
visitor_ = std::make_shared<RSSurfaceCaptureVisitor>(captureConfig, isUnirender);
|
||||
if (visitor_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
visitor_->renderEngine_ = std::make_shared<RSUniRenderEngine>();
|
||||
visitor_->renderEngine_->Init();
|
||||
if (!RSSystemProperties::IsUseVulkan()) {
|
||||
visitor_->canvas_ = std::make_unique<RSPaintFilterCanvas>(drawingCanvas_.get());
|
||||
} else {
|
||||
const int canvasWidth = 10;
|
||||
const int canvasHeight = 10;
|
||||
drawingRecordingCanvas_ = std::make_shared<Drawing::RecordingCanvas>(canvasWidth, canvasHeight);
|
||||
visitor_->canvas_ = std::make_unique<RSPaintFilterCanvas>(drawingRecordingCanvas_.get());
|
||||
}
|
||||
}
|
||||
void RSGraphicEngineTest::TearDownTestCase()
|
||||
{
|
||||
visitor_ = nullptr;
|
||||
drawingCanvas_ = nullptr;
|
||||
}
|
||||
void RSGraphicEngineTest::SetUp() {}
|
||||
|
||||
void RSGraphicEngineTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: DrawSurfaceNodeWithParams001
|
||||
* @tc.desc: test DrawSurfaceNodeWithParams when useCPU is false
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6R34I
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, DrawSurfaceNodeWithParams001, TestSize.Level1)
|
||||
{
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
renderEngine->Init();
|
||||
auto drawingCanvas = std::make_unique<Drawing::Canvas>(DEFAULT_DRAWING_CANVAS_WIDTH, DEFAULT_DRAWING_CANVAS_HEIGHT);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = nullptr;
|
||||
if (Drawing::SystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
|
||||
Drawing::SystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
|
||||
auto drawingRecordingCanvas =
|
||||
std::make_unique<Drawing::RecordingCanvas>(DEFAULT_DRAWING_CANVAS_WIDTH, DEFAULT_DRAWING_CANVAS_HEIGHT);
|
||||
drawingRecordingCanvas->SetGrRecordingContext(renderEngine->GetRenderContext()->GetSharedDrGPUContext());
|
||||
canvas = std::make_shared<RSPaintFilterCanvas>(drawingRecordingCanvas.release());
|
||||
} else {
|
||||
canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
}
|
||||
if (!RSUniRenderJudgement::IsUniRender()) {
|
||||
auto node = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
auto param = RSDividedRenderUtil::CreateBufferDrawParam(*node);
|
||||
param.useCPU = true;
|
||||
renderEngine->DrawSurfaceNodeWithParams(*canvas, *node, param, nullptr, nullptr);
|
||||
}
|
||||
ASSERT_NE(canvas, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DrawSurfaceNodeWithParams002
|
||||
* @tc.desc: test DrawSurfaceNodeWithParams when useCPU is true
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6R34I
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, DrawSurfaceNodeWithParams002, TestSize.Level1)
|
||||
{
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
renderEngine->Init();
|
||||
auto drawingCanvas = std::make_unique<Drawing::Canvas>(DEFAULT_DRAWING_CANVAS_WIDTH, DEFAULT_DRAWING_CANVAS_HEIGHT);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = nullptr;
|
||||
if (Drawing::SystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
|
||||
Drawing::SystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
|
||||
auto drawingRecordingCanvas =
|
||||
std::make_unique<Drawing::RecordingCanvas>(DEFAULT_DRAWING_CANVAS_WIDTH, DEFAULT_DRAWING_CANVAS_HEIGHT);
|
||||
drawingRecordingCanvas->SetGrRecordingContext(renderEngine->GetRenderContext()->GetSharedDrGPUContext());
|
||||
canvas = std::make_shared<RSPaintFilterCanvas>(drawingRecordingCanvas.release());
|
||||
} else {
|
||||
canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
}
|
||||
if (!RSUniRenderJudgement::IsUniRender()) {
|
||||
auto node = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
auto param = RSDividedRenderUtil::CreateBufferDrawParam(*node);
|
||||
param.useCPU = true;
|
||||
renderEngine->DrawSurfaceNodeWithParams(*canvas, *node, param, nullptr, nullptr);
|
||||
}
|
||||
ASSERT_NE(canvas, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DrawLayers001
|
||||
* @tc.desc: test DrawLayers with different GraphicCompositionType
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6R34I
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, DrawLayers001, TestSize.Level1)
|
||||
{
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
renderEngine->Init();
|
||||
auto drawingCanvas = std::make_unique<Drawing::Canvas>(DEFAULT_DRAWING_CANVAS_WIDTH, DEFAULT_DRAWING_CANVAS_HEIGHT);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = nullptr;
|
||||
if (Drawing::SystemProperties::GetGpuApiType() == GpuApiType::VULKAN ||
|
||||
Drawing::SystemProperties::GetGpuApiType() == GpuApiType::DDGR) {
|
||||
auto drawingRecordingCanvas =
|
||||
std::make_unique<Drawing::RecordingCanvas>(DEFAULT_DRAWING_CANVAS_WIDTH, DEFAULT_DRAWING_CANVAS_HEIGHT);
|
||||
drawingRecordingCanvas->SetGrRecordingContext(renderEngine->GetRenderContext()->GetSharedDrGPUContext());
|
||||
canvas = std::make_shared<RSPaintFilterCanvas>(drawingRecordingCanvas.release());
|
||||
} else {
|
||||
canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
}
|
||||
std::vector<LayerInfoPtr> layers;
|
||||
layers.emplace_back(nullptr);
|
||||
LayerInfoPtr layer1 = HdiLayerInfo::CreateHdiLayerInfo();
|
||||
layer1->SetCompositionType(GraphicCompositionType::GRAPHIC_COMPOSITION_DEVICE);
|
||||
layers.emplace_back(layer1);
|
||||
LayerInfoPtr layer2 = HdiLayerInfo::CreateHdiLayerInfo();
|
||||
layer2->SetCompositionType(GraphicCompositionType::GRAPHIC_COMPOSITION_DEVICE_CLEAR);
|
||||
layers.emplace_back(layer2);
|
||||
LayerInfoPtr layer3 = HdiLayerInfo::CreateHdiLayerInfo();
|
||||
layer3->SetCompositionType(GraphicCompositionType::GRAPHIC_COMPOSITION_CLIENT);
|
||||
layers.emplace_back(layer3);
|
||||
renderEngine->DrawLayers(*canvas, layers, false);
|
||||
ASSERT_NE(canvas, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DrawWithParams001
|
||||
* @tc.desc: test DrawWithParams when preProcessFunc and postProcessFunc are null
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6R34I
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, DrawWithParams001, TestSize.Level1)
|
||||
{
|
||||
if (!RSUniRenderJudgement::IsUniRender()) {
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
std::shared_ptr<Drawing::RecordingCanvas> drawingRecordingCanvas = nullptr;
|
||||
std::unique_ptr<Drawing::Canvas> drawingCanvas =
|
||||
std::make_unique<Drawing::Canvas>(DEFAULT_DRAWING_CANVAS_WIDTH, DEFAULT_DRAWING_CANVAS_HEIGHT);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = nullptr;
|
||||
if (!RSSystemProperties::IsUseVulkan()) {
|
||||
canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
} else {
|
||||
renderEngine->Init();
|
||||
const int canvasWidth = 10;
|
||||
const int canvasHeight = 10;
|
||||
drawingRecordingCanvas = std::make_shared<Drawing::RecordingCanvas>(canvasWidth, canvasHeight);
|
||||
drawingRecordingCanvas->SetGrRecordingContext(renderEngine->GetRenderContext()->GetSharedDrGPUContext());
|
||||
visitor_->canvas_ = std::make_unique<RSPaintFilterCanvas>(std::move(drawingRecordingCanvas).get());
|
||||
}
|
||||
auto node = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
auto param = RSDividedRenderUtil::CreateBufferDrawParam(*node);
|
||||
param.useCPU = true;
|
||||
renderEngine->DrawWithParams(*canvas, param, nullptr, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DrawWithParams002
|
||||
* @tc.desc: test DrawWithParams when param.setColorDilter are false
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, DrawWithParams002, TestSize.Level1)
|
||||
{
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
std::unique_ptr<Drawing::Canvas> drawingCanvas = std::make_unique<Drawing::Canvas>(10, 10);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
auto node = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
auto param = RSDividedRenderUtil::CreateBufferDrawParam(*node);
|
||||
param.setColorFilter = false;
|
||||
renderEngine->DrawWithParams(*canvas, param, nullptr, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DrawWithParams003
|
||||
* @tc.desc: test DrawWithParams when param.setColorDilter are true
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, DrawWithParams003, TestSize.Level1)
|
||||
{
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
std::unique_ptr<Drawing::Canvas> drawingCanvas = std::make_unique<Drawing::Canvas>(10, 10);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
auto node = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
auto param = RSDividedRenderUtil::CreateBufferDrawParam(*node);
|
||||
param.setColorFilter = true;
|
||||
renderEngine->DrawWithParams(*canvas, param, nullptr, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DrawWithParams004
|
||||
* @tc.desc: test DrawWithParams when param.useCPU are true
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, DrawWithParams004, TestSize.Level1)
|
||||
{
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
std::unique_ptr<Drawing::Canvas> drawingCanvas = std::make_unique<Drawing::Canvas>(10, 10);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
auto node = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
auto param = RSDividedRenderUtil::CreateBufferDrawParam(*node);
|
||||
param.useCPU = true;
|
||||
renderEngine->DrawWithParams(*canvas, param, nullptr, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DrawWithParams005
|
||||
* @tc.desc: test DrawWithParams when param.useCPU are true
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, DrawWithParams005, TestSize.Level1)
|
||||
{
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
std::unique_ptr<Drawing::Canvas> drawingCanvas = std::make_unique<Drawing::Canvas>(10, 10);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
auto node = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
auto param = RSDividedRenderUtil::CreateBufferDrawParam(*node);
|
||||
param.useCPU = false;
|
||||
renderEngine->DrawWithParams(*canvas, param, nullptr, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DrawWithParams006
|
||||
* @tc.desc: test DrawWithParams when param.useCPU are true
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, DrawWithParams006, TestSize.Level1)
|
||||
{
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
std::unique_ptr<Drawing::Canvas> drawingCanvas = std::make_unique<Drawing::Canvas>(10, 10);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
auto node = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
auto param = RSDividedRenderUtil::CreateBufferDrawParam(*node);
|
||||
param.useCPU = true;
|
||||
param.setColorFilter = true;
|
||||
renderEngine->DrawWithParams(*canvas, param, nullptr, nullptr);
|
||||
ASSERT_NE(canvas, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: DrawWithParams007
|
||||
* @tc.desc: test DrawWithParams when param.useCPU are true
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, DrawWithParams007, TestSize.Level1)
|
||||
{
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
std::unique_ptr<Drawing::Canvas> drawingCanvas = std::make_unique<Drawing::Canvas>(10, 10);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
auto node = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
auto param = RSDividedRenderUtil::CreateBufferDrawParam(*node);
|
||||
param.useCPU = true;
|
||||
param.setColorFilter = false;
|
||||
renderEngine->DrawWithParams(*canvas, param, nullptr, nullptr);
|
||||
ASSERT_NE(canvas, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RSSurfaceNodeCommonPreProcess
|
||||
* @tc.desc: test RSSurfaceNodeCommonPreProcess without filter, expect no error
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6R34I
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, RSSurfaceNodeCommonPreProcess, TestSize.Level1)
|
||||
{
|
||||
if (!RSUniRenderJudgement::IsUniRender()) {
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
std::unique_ptr<Drawing::Canvas> drawingCanvas = std::make_unique<Drawing::Canvas>(10, 10);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
auto node = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
auto param = RSDividedRenderUtil::CreateBufferDrawParam(*node);
|
||||
renderEngine->RSSurfaceNodeCommonPreProcess(*node, *canvas, param);
|
||||
ASSERT_NE(canvas, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RSSurfaceNodeCommonPostProcess
|
||||
* @tc.desc: test RSSurfaceNodeCommonPostProcess without filter, expect no error
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6R34I
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, RSSurfaceNodeCommonPostProcess, TestSize.Level1)
|
||||
{
|
||||
if (!RSUniRenderJudgement::IsUniRender()) {
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
std::unique_ptr<Drawing::Canvas> drawingCanvas = std::make_unique<Drawing::Canvas>(10, 10);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
auto node = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
auto param = RSDividedRenderUtil::CreateBufferDrawParam(*node);
|
||||
renderEngine->RSSurfaceNodeCommonPostProcess(*node, *canvas, param);
|
||||
ASSERT_NE(canvas, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ClipHoleForLayer
|
||||
* @tc.desc: test ClipHoleForLayer, expect no error
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6R34I
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, ClipHoleForLayer, TestSize.Level1)
|
||||
{
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
renderEngine->Init();
|
||||
auto drawingCanvas = std::make_unique<Drawing::Canvas>(DEFAULT_DRAWING_CANVAS_WIDTH, DEFAULT_DRAWING_CANVAS_HEIGHT);
|
||||
std::shared_ptr<RSPaintFilterCanvas> canvas = nullptr;
|
||||
canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
|
||||
auto node = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
renderEngine->ClipHoleForLayer(*canvas, *node);
|
||||
ASSERT_NE(canvas, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetColorFilterModeToPaint
|
||||
* @tc.desc: test SetColorFilterModeToPaint, expect no error
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6R34I
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, SetColorFilterModeToPaint, TestSize.Level1)
|
||||
{
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
renderEngine->Init();
|
||||
std::unique_ptr<Drawing::Brush> brush = std::make_unique<Drawing::Brush>();
|
||||
renderEngine->SetColorFilterModeToPaint(*brush);
|
||||
ASSERT_NE(brush, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetColorFilterModeToPaint002
|
||||
* @tc.desc: test SetColorFilterModeToPaint, expect no error
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6R34I
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, SetColorFilterModeToPaint002, TestSize.Level1)
|
||||
{
|
||||
RSRenderEngine::colorFilterMode_ = ColorFilterMode::COLOR_FILTER_END;
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
renderEngine->Init();
|
||||
std::unique_ptr<Drawing::Brush> brush = std::make_unique<Drawing::Brush>();
|
||||
renderEngine->SetColorFilterModeToPaint(*brush);
|
||||
ASSERT_NE(brush, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetColorFilterModeToPaint003
|
||||
* @tc.desc: test SetColorFilterModeToPaint, expect no error
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6R34I
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, SetColorFilterModeToPaint003, TestSize.Level1)
|
||||
{
|
||||
RSRenderEngine::colorFilterMode_ = ColorFilterMode::DALTONIZATION_PROTANOMALY_MODE;
|
||||
auto renderEngine = std::make_shared<RSRenderEngine>();
|
||||
renderEngine->Init();
|
||||
std::unique_ptr<Drawing::Brush> brush = std::make_unique<Drawing::Brush>();
|
||||
renderEngine->SetColorFilterModeToPaint(*brush);
|
||||
ASSERT_NE(brush, nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: CaptureSingleSurfaceNodeWithoutUni001
|
||||
* @tc.desc: Test RSGraphicEngineTest.CaptureSingleSurfaceNodeWithoutUni
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI794H6
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, CaptureSingleSurfaceNodeWithoutUni001, Function | SmallTest | Level2)
|
||||
{
|
||||
bool isUnirender = RSUniRenderJudgement::IsUniRender();
|
||||
ASSERT_NE(nullptr, visitor_);
|
||||
auto surfaceNode = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
surfaceNode->SetSecurityLayer(true);
|
||||
if (isUnirender) {
|
||||
if (RSSystemParameters::GetRsSurfaceCaptureType() ==
|
||||
RsSurfaceCaptureType::RS_SURFACE_CAPTURE_TYPE_MAIN_THREAD) {
|
||||
visitor_->CaptureSingleSurfaceNodeWithoutUni(*surfaceNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: CaptureSingleSurfaceNodeWithoutUni002
|
||||
* @tc.desc: Test RSGraphicEngineTest.CaptureSingleSurfaceNodeWithoutUni
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI794H6
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, CaptureSingleSurfaceNodeWithoutUni002, Function | SmallTest | Level2)
|
||||
{
|
||||
bool isUnirender = RSUniRenderJudgement::IsUniRender();
|
||||
ASSERT_NE(nullptr, visitor_);
|
||||
auto surfaceNode = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
surfaceNode->SetSecurityLayer(false);
|
||||
if (isUnirender) {
|
||||
if (RSSystemParameters::GetRsSurfaceCaptureType() ==
|
||||
RsSurfaceCaptureType::RS_SURFACE_CAPTURE_TYPE_MAIN_THREAD) {
|
||||
visitor_->CaptureSingleSurfaceNodeWithoutUni(*surfaceNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: CaptureSurfaceInDisplayWithoutUni001
|
||||
* @tc.desc: Test RSGraphicEngineTest.CaptureSurfaceInDisplayWithoutUni
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI794H6
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, CaptureSurfaceInDisplayWithoutUni001, Function | SmallTest | Level2)
|
||||
{
|
||||
bool isUnirender = RSUniRenderJudgement::IsUniRender();
|
||||
ASSERT_NE(nullptr, visitor_);
|
||||
auto surfaceNode = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
surfaceNode->SetSecurityLayer(false);
|
||||
if (!isUnirender) {
|
||||
visitor_->CaptureSingleSurfaceNodeWithoutUni(*surfaceNode);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: ProcessSurfaceRenderNode006
|
||||
* @tc.desc: Test RSGraphicEngineTest.ProcessSurfaceRenderNode
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI794H6
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, ProcessSurfaceRenderNode006, Function | SmallTest | Level2)
|
||||
{
|
||||
bool isUnirender = RSUniRenderJudgement::IsUniRender();
|
||||
ASSERT_NE(nullptr, visitor_);
|
||||
auto surfaceNode = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
surfaceNode->GetMutableRenderProperties().SetVisible(true);
|
||||
surfaceNode->GetMutableRenderProperties().SetAlpha(DEFAULT_BOUNDS_WIDTH);
|
||||
if (!isUnirender) {
|
||||
visitor_->ProcessSurfaceRenderNodeWithoutUni(*surfaceNode);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: ProcessSurfaceRenderNode007
|
||||
* @tc.desc: Test RSGraphicEngineTest.ProcessSurfaceRenderNode
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI794H6
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, ProcessSurfaceRenderNode007, Function | SmallTest | Level2)
|
||||
{
|
||||
bool isUnirender = RSUniRenderJudgement::IsUniRender();
|
||||
ASSERT_NE(nullptr, visitor_);
|
||||
auto surfaceNode = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
surfaceNode->GetMutableRenderProperties().SetVisible(true);
|
||||
surfaceNode->GetMutableRenderProperties().SetAlpha(.0f);
|
||||
if (isUnirender) {
|
||||
if (RSSystemParameters::GetRsSurfaceCaptureType() ==
|
||||
RsSurfaceCaptureType::RS_SURFACE_CAPTURE_TYPE_MAIN_THREAD) {
|
||||
visitor_->ProcessSurfaceRenderNode(*surfaceNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: ProcessSurfaceRenderNode008
|
||||
* @tc.desc: Test RSGraphicEngineTest.ProcessSurfaceRenderNode
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI794H6
|
||||
*/
|
||||
HWTEST_F(RSGraphicEngineTest, ProcessSurfaceRenderNode008, Function | SmallTest | Level2)
|
||||
{
|
||||
bool isUnirender = RSUniRenderJudgement::IsUniRender();
|
||||
ASSERT_NE(nullptr, visitor_);
|
||||
auto surfaceNode = RSTestUtil::CreateSurfaceNodeWithBuffer();
|
||||
visitor_->canvas_ = nullptr;
|
||||
if (isUnirender) {
|
||||
if (RSSystemParameters::GetRsSurfaceCaptureType() ==
|
||||
RsSurfaceCaptureType::RS_SURFACE_CAPTURE_TYPE_MAIN_THREAD) {
|
||||
visitor_->ProcessSurfaceRenderNode(*surfaceNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,300 @@
|
||||
/*
|
||||
* 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_main_thread.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
using ConfigItem = RSGraphicConfig::ConfigItem;
|
||||
const std::string XML_STR = R"(<?xml version='1.0' encoding="utf-8"?>
|
||||
<Configs>
|
||||
<testMap>
|
||||
<testBooL enable="true"></testBooL>
|
||||
</testMap>
|
||||
<testString>testString</testString>
|
||||
<testStrings>testStrings1 testStrings2 testStrings3</testStrings>
|
||||
<testInts>1 2 3</testInts>
|
||||
<testFloats>0.1 0.2 -0.3</testFloats>
|
||||
<testPositiveFloats>0.1 0.2 0.3</testPositiveFloats>
|
||||
<testInvalidPositiveFloats>0.1 0.2 -0.3</testInvalidPositiveFloats>
|
||||
<testUndifined></testUndifined>
|
||||
</Configs>
|
||||
)";
|
||||
|
||||
const std::string XML_INVALID_INPUT_STR = R"(<?xml version='1.0' encoding="utf-8"?>
|
||||
<Configs>
|
||||
<testMap>
|
||||
<testBooL></testBooL>
|
||||
</testMap>
|
||||
<testString></testString>
|
||||
<testStrings></testStrings>
|
||||
<testInts>a b c</testInts>
|
||||
<testFloats>a b c</testFloats>
|
||||
<testPositiveFloats>a b c</testPositiveFloats>
|
||||
</Configs>
|
||||
)";
|
||||
|
||||
class RSRenderGraphicConfigTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
ConfigItem ReadConfig(const std::string& xmlStr);
|
||||
};
|
||||
|
||||
void RSRenderGraphicConfigTest::SetUpTestCase() {}
|
||||
|
||||
void RSRenderGraphicConfigTest::TearDownTestCase() {}
|
||||
|
||||
void RSRenderGraphicConfigTest::SetUp() {}
|
||||
|
||||
void RSRenderGraphicConfigTest::TearDown() {}
|
||||
|
||||
void SetConfigMap(std::map<std::string, RSGraphicConfig::ValueType>* nonConstConfigMap)
|
||||
{
|
||||
*nonConstConfigMap = {
|
||||
{ "testMap", RSGraphicConfig::ValueType::MAP },
|
||||
{ "testBooL", RSGraphicConfig::ValueType::UNDIFINED },
|
||||
{ "testString", RSGraphicConfig::ValueType::STRING },
|
||||
{ "testStrings", RSGraphicConfig::ValueType::STRINGS },
|
||||
{ "testInts", RSGraphicConfig::ValueType::INTS },
|
||||
{ "testFloats", RSGraphicConfig::ValueType::FLOATS },
|
||||
{ "testPositiveFloats", RSGraphicConfig::ValueType::POSITIVE_FLOATS },
|
||||
{ "testInvalidPositiveFloats", RSGraphicConfig::ValueType::POSITIVE_FLOATS },
|
||||
{ "testUndifined", RSGraphicConfig::ValueType::UNDIFINED },
|
||||
};
|
||||
}
|
||||
|
||||
void ResetConfigMap(std::map<std::string, RSGraphicConfig::ValueType>* nonConstConfigMap)
|
||||
{
|
||||
*nonConstConfigMap = {
|
||||
{ "blurEffect", RSGraphicConfig::ValueType::MAP },
|
||||
{ "blurSwitchOpen", RSGraphicConfig::ValueType::UNDIFINED },
|
||||
};
|
||||
}
|
||||
|
||||
ConfigItem RSRenderGraphicConfigTest::ReadConfig(const std::string& xmlStr)
|
||||
{
|
||||
ConfigItem config;
|
||||
xmlDocPtr docPtr = xmlParseMemory(xmlStr.c_str(), xmlStr.length() + 1);
|
||||
if (docPtr == nullptr) {
|
||||
return config;
|
||||
}
|
||||
|
||||
xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
|
||||
if (rootPtr == nullptr || rootPtr->name == nullptr ||
|
||||
xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
|
||||
xmlFreeDoc(docPtr);
|
||||
return config;
|
||||
}
|
||||
|
||||
std::map<std::string, ConfigItem> configMap;
|
||||
config.SetValue(configMap);
|
||||
RSGraphicConfig::ReadConfig(rootPtr, *config.mapValue);
|
||||
xmlFreeDoc(docPtr);
|
||||
return config;
|
||||
}
|
||||
|
||||
namespace {
|
||||
/* *
|
||||
* @tc.name: LoadConfigXml
|
||||
* @tc.desc: test LoadConfigXml.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RSRenderGraphicConfigTest, LoadConfigXml, TestSize.Level2)
|
||||
{
|
||||
ASSERT_TRUE(RSGraphicConfig::LoadConfigXml());
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: ReadConfig
|
||||
* @tc.desc: test ReadConfig.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RSRenderGraphicConfigTest, ReadConfig, TestSize.Level2)
|
||||
{
|
||||
auto nonConstConfigMap =
|
||||
const_cast<std::map<std::string, RSGraphicConfig::ValueType>*>(&RSGraphicConfig::configItemTypeMap_);
|
||||
SetConfigMap(nonConstConfigMap);
|
||||
RSGraphicConfig::config_ = ReadConfig(XML_STR);
|
||||
RSGraphicConfig::ConfigItem item = RSGraphicConfig::config_["testMap"];
|
||||
ASSERT_TRUE(item.IsMap());
|
||||
|
||||
item = RSGraphicConfig::config_["testMap"]["testBooL"].GetProp("enable");
|
||||
ASSERT_TRUE(item.IsBool());
|
||||
ASSERT_TRUE(item.boolValue);
|
||||
|
||||
item = RSGraphicConfig::config_["testString"];
|
||||
ASSERT_TRUE(item.IsString());
|
||||
ASSERT_EQ("testString", item.stringValue);
|
||||
|
||||
item = RSGraphicConfig::config_["testStrings"];
|
||||
ASSERT_TRUE(item.IsStrings());
|
||||
ASSERT_TRUE(item.stringsValue->size() == 3);
|
||||
auto stringValues = *item.stringsValue;
|
||||
ASSERT_EQ("testStrings1", stringValues[0]);
|
||||
ASSERT_EQ("testStrings2", stringValues[1]);
|
||||
ASSERT_EQ("testStrings3", stringValues[2]);
|
||||
|
||||
item = RSGraphicConfig::config_["testInts"];
|
||||
ASSERT_TRUE(item.IsInts());
|
||||
ASSERT_TRUE(item.intsValue->size() == 3);
|
||||
auto intValues = *item.intsValue;
|
||||
ASSERT_EQ(1, intValues[0]);
|
||||
ASSERT_EQ(2, intValues[1]);
|
||||
ASSERT_EQ(3, intValues[2]);
|
||||
|
||||
item = RSGraphicConfig::config_["testFloats"];
|
||||
ASSERT_TRUE(item.IsFloats());
|
||||
ASSERT_TRUE(item.floatsValue->size() == 3);
|
||||
auto floatValues = *item.floatsValue;
|
||||
ASSERT_TRUE(std::abs(0.1 - floatValues[0]) < std::numeric_limits<float>::epsilon());
|
||||
ASSERT_TRUE(std::abs(0.2 - floatValues[1]) < std::numeric_limits<float>::epsilon());
|
||||
ASSERT_TRUE(std::abs(-0.3 - floatValues[2]) < std::numeric_limits<float>::epsilon());
|
||||
|
||||
item = RSGraphicConfig::config_["testPositiveFloats"];
|
||||
ASSERT_TRUE(item.IsFloats());
|
||||
ASSERT_TRUE(item.floatsValue->size() == 3);
|
||||
floatValues = *item.floatsValue;
|
||||
ASSERT_TRUE(std::abs(0.1 - floatValues[0]) < std::numeric_limits<float>::epsilon());
|
||||
ASSERT_TRUE(std::abs(0.2 - floatValues[1]) < std::numeric_limits<float>::epsilon());
|
||||
ASSERT_TRUE(std::abs(0.3 - floatValues[2]) < std::numeric_limits<float>::epsilon());
|
||||
|
||||
item = RSGraphicConfig::config_["testInvalidPositiveFloats"];
|
||||
ASSERT_TRUE(item.IsFloats());
|
||||
ASSERT_TRUE(item.floatsValue->size() == 0);
|
||||
|
||||
item = RSGraphicConfig::config_["testUndifined"];
|
||||
ASSERT_TRUE(item.type == RSBaseXmlConfig::ValueType::UNDIFINED);
|
||||
ResetConfigMap(nonConstConfigMap);
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: ReadConfig1
|
||||
* @tc.desc: test ReadConfig invalid value input.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RSRenderGraphicConfigTest, ReadConfig1, TestSize.Level2)
|
||||
{
|
||||
auto nonConstConfigMap =
|
||||
const_cast<std::map<std::string, RSGraphicConfig::ValueType>*>(&RSGraphicConfig::configItemTypeMap_);
|
||||
SetConfigMap(nonConstConfigMap);
|
||||
RSGraphicConfig::config_ = ReadConfig(XML_INVALID_INPUT_STR);
|
||||
RSGraphicConfig::ConfigItem item = RSGraphicConfig::config_["testMap"];
|
||||
ASSERT_TRUE(item.IsMap());
|
||||
|
||||
item = RSGraphicConfig::config_["testMap"]["testBooL"].GetProp("enable");
|
||||
ASSERT_FALSE(item.IsBool());
|
||||
|
||||
item = RSGraphicConfig::config_["testString"];
|
||||
ASSERT_TRUE(item.IsString());
|
||||
ASSERT_EQ("", item.stringValue);
|
||||
|
||||
item = RSGraphicConfig::config_["testStrings"];
|
||||
ASSERT_TRUE(item.IsStrings());
|
||||
ASSERT_TRUE(item.stringsValue->size() == 0);
|
||||
|
||||
item = RSGraphicConfig::config_["testInts"];
|
||||
ASSERT_TRUE(item.IsInts());
|
||||
ASSERT_TRUE(item.intsValue->size() == 0);
|
||||
|
||||
item = RSGraphicConfig::config_["testFloats"];
|
||||
ASSERT_TRUE(item.IsFloats());
|
||||
ASSERT_TRUE(item.floatsValue->size() == 0);
|
||||
|
||||
item = RSGraphicConfig::config_["testPositiveFloats"];
|
||||
ASSERT_TRUE(item.IsFloats());
|
||||
ASSERT_TRUE(item.floatsValue->size() == 0);
|
||||
|
||||
ResetConfigMap(nonConstConfigMap);
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: DumpConfig
|
||||
* @tc.desc: test DumpConfig.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RSRenderGraphicConfigTest, DumpConfig, TestSize.Level2)
|
||||
{
|
||||
std::string xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
|
||||
"<Configs>"
|
||||
"<blurEffect>"
|
||||
"<blurSwitchOpen enable=\"true\"></blurSwitchOpen>"
|
||||
"</blurEffect>"
|
||||
"</Configs>";
|
||||
RSGraphicConfig::config_ = ReadConfig(xmlStr);
|
||||
RSGraphicConfig::DumpConfig(*RSGraphicConfig::GetConfig().mapValue);
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: ReadProperty
|
||||
* @tc.desc: test ReadProperty name and enable.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RSRenderGraphicConfigTest, ReadProperty, TestSize.Level2)
|
||||
{
|
||||
std::string xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
|
||||
"<Configs>"
|
||||
"<blurEffect>"
|
||||
"<blurSwitchOpen name=\"testName\" enable=\"true\"></blurSwitchOpen>"
|
||||
"</blurEffect>"
|
||||
"</Configs>";
|
||||
RSGraphicConfig::config_ = ReadConfig(xmlStr);
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: BlurEffectConfig
|
||||
* @tc.desc: set blurEffect.blurSwitchOpen true.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RSRenderGraphicConfigTest, BlurEffectConfig, TestSize.Level2)
|
||||
{
|
||||
std::string xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
|
||||
"<Configs>"
|
||||
"<blurEffect>"
|
||||
"<blurSwitchOpen enable=\"true\"></blurSwitchOpen>"
|
||||
"</blurEffect>"
|
||||
"</Configs>";
|
||||
RSGraphicConfig::config_ = ReadConfig(xmlStr);
|
||||
RSMainThread::Instance()->ConfigureRenderService();
|
||||
ASSERT_TRUE(RSMainThread::Instance()->IsBlurSwitchOpen());
|
||||
}
|
||||
|
||||
/* *
|
||||
* @tc.name: BlurEffectConfig2
|
||||
* @tc.desc: set blurEffect.blurSwitchOpen false.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(RSRenderGraphicConfigTest, BlurEffectConfig2, TestSize.Level2)
|
||||
{
|
||||
std::string xmlStr = "<?xml version='1.0' encoding=\"utf-8\"?>"
|
||||
"<Configs>"
|
||||
"<blurEffect>"
|
||||
"<blurSwitchOpen enable=\"false\"></blurSwitchOpen>"
|
||||
"</blurEffect>"
|
||||
"</Configs>";
|
||||
RSGraphicConfig::config_ = ReadConfig(xmlStr);
|
||||
RSMainThread::Instance()->ConfigureRenderService();
|
||||
ASSERT_FALSE(RSMainThread::Instance()->IsBlurSwitchOpen());
|
||||
}
|
||||
} // namespace
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -0,0 +1,578 @@
|
||||
/*
|
||||
* 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 <hilog/log.h>
|
||||
#include <memory>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "rs_test_util.h"
|
||||
#include "surface_buffer_impl.h"
|
||||
#include "pipeline/rs_surface_capture_task.h"
|
||||
#include "pipeline/rs_ui_capture_task_parallel.h"
|
||||
#include "pipeline/rs_base_render_node.h"
|
||||
#include "pipeline/rs_display_render_node.h"
|
||||
#include "pipeline/rs_root_render_node.h"
|
||||
#include "pipeline/rs_render_node.h"
|
||||
#include "pipeline/rs_surface_render_node.h"
|
||||
#include "transaction/rs_interfaces.h"
|
||||
#include "ui/rs_surface_extractor.h"
|
||||
#include "ui/rs_canvas_node.h"
|
||||
#include "ui/rs_canvas_drawing_node.h"
|
||||
#include "ui/rs_proxy_node.h"
|
||||
#include "pipeline/rs_main_thread.h"
|
||||
#include "pipeline/rs_paint_filter_canvas.h"
|
||||
#include "pipeline/rs_uni_render_judgement.h"
|
||||
#include "pipeline/rs_uni_render_engine.h"
|
||||
#include "pipeline/rs_render_node_gc.h"
|
||||
#include "platform/common/rs_system_properties.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
using namespace HiviewDFX;
|
||||
using DisplayId = ScreenId;
|
||||
namespace {
|
||||
constexpr HiLogLabel LOG_LABEL = { LOG_CORE, 0xD001400, "RSUiCaptureTaskTest" };
|
||||
constexpr uint32_t MAX_TIME_WAITING_FOR_CALLBACK = 200;
|
||||
constexpr uint32_t SLEEP_TIME_IN_US = 10000; // 10ms
|
||||
constexpr uint32_t SLEEP_TIME_FOR_PROXY = 100000; // 100ms
|
||||
constexpr float DEFAULT_BOUNDS_WIDTH = 100.f;
|
||||
constexpr float DEFAULT_BOUNDS_HEIGHT = 200.f;
|
||||
constexpr float HALF_BOUNDS_WIDTH = 50.0f;
|
||||
constexpr float HALF_BOUNDS_HEIGHT = 100.0f;
|
||||
|
||||
class CustomizedSurfaceCapture : public SurfaceCaptureCallback {
|
||||
public:
|
||||
void OnSurfaceCapture(std::shared_ptr<Media::PixelMap> pixelmap) override
|
||||
{
|
||||
captureSuccess_ = (pixelmap != nullptr);
|
||||
isCallbackCalled_ = true;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
captureSuccess_ = false;
|
||||
isCallbackCalled_ = false;
|
||||
}
|
||||
|
||||
bool captureSuccess_ = false;
|
||||
bool isCallbackCalled_ = false;
|
||||
};
|
||||
|
||||
class RSC_EXPORT MockSurfaceCaptureCallback : public RSISurfaceCaptureCallback {
|
||||
sptr<IRemoteObject> AsObject()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void OnSurfaceCapture(NodeId id, Media::PixelMap* pixelmap)
|
||||
{
|
||||
// DO NOTHING
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
class RSUiCaptureTaskTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
InitRenderContext();
|
||||
rsInterfaces_ = &RSInterfaces::GetInstance();
|
||||
|
||||
ScreenId screenId = rsInterfaces_->GetDefaultScreenId();
|
||||
RSScreenModeInfo modeInfo = rsInterfaces_->GetScreenActiveMode(screenId);
|
||||
DisplayId virtualDisplayId = rsInterfaces_->CreateVirtualScreen("virtualDisplayTest",
|
||||
modeInfo.GetScreenWidth(), modeInfo.GetScreenHeight(), nullptr);
|
||||
mirrorConfig_.screenId = virtualDisplayId;
|
||||
mirrorConfig_.mirrorNodeId = screenId;
|
||||
displayNode_ = RSDisplayNode::Create(mirrorConfig_);
|
||||
|
||||
RSTransactionProxy::GetInstance()->FlushImplicitTransaction();
|
||||
usleep(SLEEP_TIME_FOR_PROXY);
|
||||
|
||||
auto& renderNodeGC = RSRenderNodeGC::Instance();
|
||||
renderNodeGC.nodeBucket_ = std::queue<std::vector<RSRenderNode*>>();
|
||||
renderNodeGC.drawableBucket_ = std::queue<std::vector<DrawableV2::RSRenderNodeDrawableAdapter*>>();
|
||||
}
|
||||
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
rsInterfaces_->RemoveVirtualScreen(mirrorConfig_.screenId);
|
||||
rsInterfaces_ = nullptr;
|
||||
renderContext_ = nullptr;
|
||||
displayNode_ = nullptr;
|
||||
RSTransactionProxy::GetInstance()->FlushImplicitTransaction();
|
||||
usleep(SLEEP_TIME_FOR_PROXY);
|
||||
}
|
||||
|
||||
static void InitRenderContext()
|
||||
{
|
||||
#ifdef ACE_ENABLE_GL
|
||||
if (renderContext_ == nullptr) {
|
||||
HiLog::Info(LOG_LABEL, "%s: init renderContext_", __func__);
|
||||
renderContext_ = RenderContextFactory::GetInstance().CreateEngine();
|
||||
renderContext_->InitializeEglContext();
|
||||
}
|
||||
#endif // ACE_ENABLE_GL
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
if (surfaceNode_) {
|
||||
displayNode_->RemoveChild(surfaceNode_);
|
||||
surfaceNode_ = nullptr;
|
||||
canvasNode_ = nullptr;
|
||||
|
||||
RSTransactionProxy::GetInstance()->FlushImplicitTransaction();
|
||||
usleep(SLEEP_TIME_FOR_PROXY);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<RSSurfaceNode> SetUpSurface()
|
||||
{
|
||||
RSSurfaceNodeConfig config;
|
||||
surfaceNode_ = RSSurfaceNode::Create(config);
|
||||
surfaceNode_->SetBounds(0.0f, 0.0f, DEFAULT_BOUNDS_WIDTH, DEFAULT_BOUNDS_HEIGHT);
|
||||
surfaceNode_->SetFrame(0.0f, 0.0f, DEFAULT_BOUNDS_WIDTH, DEFAULT_BOUNDS_HEIGHT);
|
||||
surfaceNode_->SetBackgroundColor(Drawing::Color::COLOR_RED);
|
||||
|
||||
canvasNode_ = RSCanvasNode::Create();
|
||||
canvasNode_->SetBounds(0.0f, 0.0f, HALF_BOUNDS_WIDTH, HALF_BOUNDS_HEIGHT);
|
||||
canvasNode_->SetFrame(0.0f, 0.0f, HALF_BOUNDS_WIDTH, HALF_BOUNDS_HEIGHT);
|
||||
canvasNode_->SetBackgroundColor(Drawing::Color::COLOR_YELLOW);
|
||||
|
||||
canvasDrawingNode_ = RSCanvasDrawingNode::Create();
|
||||
canvasDrawingNode_->SetBounds(0.0f, 0.0f, HALF_BOUNDS_WIDTH, HALF_BOUNDS_HEIGHT);
|
||||
canvasDrawingNode_->SetFrame(0.0f, 0.0f, HALF_BOUNDS_WIDTH, HALF_BOUNDS_HEIGHT);
|
||||
canvasDrawingNode_->SetBackgroundColor(Drawing::Color::COLOR_YELLOW);
|
||||
|
||||
canvasNode_->AddChild(canvasDrawingNode_, -1);
|
||||
surfaceNode_->AddChild(canvasNode_, -1);
|
||||
displayNode_->AddChild(surfaceNode_, -1);
|
||||
RSTransactionProxy::GetInstance()->FlushImplicitTransaction();
|
||||
usleep(SLEEP_TIME_FOR_PROXY);
|
||||
|
||||
return surfaceNode_;
|
||||
}
|
||||
|
||||
bool CheckSurfaceCaptureCallback(std::shared_ptr<CustomizedSurfaceCapture> callback)
|
||||
{
|
||||
if (!callback) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t times = 0;
|
||||
while (times < MAX_TIME_WAITING_FOR_CALLBACK) {
|
||||
if (callback->isCallbackCalled_) {
|
||||
return true;
|
||||
}
|
||||
usleep(SLEEP_TIME_IN_US);
|
||||
++times;
|
||||
}
|
||||
HiLog::Error(LOG_LABEL, "CheckSurfaceCaptureCallback timeout");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<RSUiCaptureTaskParallel> BuildTaskParallel(NodeId nodeId, float width = 0.0f, float height = 0.0f)
|
||||
{
|
||||
RSSurfaceCaptureConfig config;
|
||||
auto renderNode = std::make_shared<RSSurfaceRenderNode>(nodeId, std::make_shared<RSContext>(), true);
|
||||
renderNode->renderContent_->renderProperties_.SetBoundsWidth(width);
|
||||
renderNode->renderContent_->renderProperties_.SetBoundsHeight(height);
|
||||
RSMainThread::Instance()->GetContext().nodeMap.RegisterRenderNode(renderNode);
|
||||
|
||||
auto renderNodeHandle = std::make_shared<RSUiCaptureTaskParallel>(nodeId, config);
|
||||
return renderNodeHandle;
|
||||
}
|
||||
|
||||
static RSInterfaces* rsInterfaces_;
|
||||
static RenderContext* renderContext_;
|
||||
static RSDisplayNodeConfig mirrorConfig_;
|
||||
static std::shared_ptr<RSDisplayNode> displayNode_;
|
||||
|
||||
std::shared_ptr<RSSurfaceNode> surfaceNode_;
|
||||
std::shared_ptr<RSCanvasNode> canvasNode_;
|
||||
std::shared_ptr<RSCanvasDrawingNode> canvasDrawingNode_;
|
||||
};
|
||||
RSInterfaces* RSUiCaptureTaskTest::rsInterfaces_ = nullptr;
|
||||
RenderContext* RSUiCaptureTaskTest::renderContext_ = nullptr;
|
||||
RSDisplayNodeConfig RSUiCaptureTaskTest::mirrorConfig_ = {INVALID_SCREEN_ID, true, INVALID_SCREEN_ID};
|
||||
std::shared_ptr<RSDisplayNode> RSUiCaptureTaskTest::displayNode_ = nullptr;
|
||||
|
||||
/*
|
||||
* @tc.name: TakeSurfaceCaptureForUiInvalidSurface
|
||||
* @tc.desc: Test TakeSurfaceCaptureForUI with invalid surface
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, TakeSurfaceCaptureForUiInvalidSurface, Function | SmallTest | Level2)
|
||||
{
|
||||
RSSurfaceNodeConfig config;
|
||||
auto surfaceNode = RSSurfaceNode::Create(config);
|
||||
auto callback = std::make_shared<CustomizedSurfaceCapture>();
|
||||
|
||||
bool ret = rsInterfaces_->TakeSurfaceCaptureForUI(surfaceNode, callback);
|
||||
ASSERT_EQ(ret, true);
|
||||
ASSERT_EQ(CheckSurfaceCaptureCallback(callback), true);
|
||||
ASSERT_EQ(callback->captureSuccess_, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TakeSurfaceCaptureForUiSurfaceNode
|
||||
* @tc.desc: Test TakeSurfaceCaptureForUI with surface node
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, TakeSurfaceCaptureForUiSurfaceNode, Function | SmallTest | Level2)
|
||||
{
|
||||
SetUpSurface();
|
||||
|
||||
auto callback = std::make_shared<CustomizedSurfaceCapture>();
|
||||
bool ret = rsInterfaces_->TakeSurfaceCaptureForUI(surfaceNode_, callback);
|
||||
ASSERT_EQ(ret, true);
|
||||
ASSERT_EQ(CheckSurfaceCaptureCallback(callback), true);
|
||||
ASSERT_EQ(callback->captureSuccess_, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TakeSurfaceCaptureForUiCanvasNode001
|
||||
* @tc.desc: Test TakeSurfaceCaptureForUI with canvas node
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, TakeSurfaceCaptureForUiCanvasNode001, Function | SmallTest | Level2)
|
||||
{
|
||||
SetUpSurface();
|
||||
|
||||
auto callback = std::make_shared<CustomizedSurfaceCapture>();
|
||||
bool ret = rsInterfaces_->TakeSurfaceCaptureForUI(canvasNode_, callback);
|
||||
ASSERT_EQ(ret, true);
|
||||
ASSERT_EQ(CheckSurfaceCaptureCallback(callback), true);
|
||||
ASSERT_EQ(callback->captureSuccess_, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TakeSurfaceCaptureForUiCanvasNode002
|
||||
* @tc.desc: Test TakeSurfaceCaptureForUI with canvas node bounds inf
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, TakeSurfaceCaptureForUiCanvasNode002, Function | SmallTest | Level2)
|
||||
{
|
||||
auto canvasNode = RSCanvasNode::Create();
|
||||
canvasNode->SetBounds(0.0f, 0.0f, 10000, 10000);
|
||||
canvasNode->SetFrame(0.0f, 0.0f, 10000, 10000);
|
||||
RSTransactionProxy::GetInstance()->FlushImplicitTransaction();
|
||||
usleep(SLEEP_TIME_FOR_PROXY);
|
||||
|
||||
auto callback = std::make_shared<CustomizedSurfaceCapture>();
|
||||
bool ret = rsInterfaces_->TakeSurfaceCaptureForUI(canvasNode, callback);
|
||||
ASSERT_EQ(ret, true);
|
||||
ASSERT_EQ(CheckSurfaceCaptureCallback(callback), true);
|
||||
ASSERT_EQ(callback->captureSuccess_, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TakeSurfaceCaptureForUiCanvasDrawingNode
|
||||
* @tc.desc: Test TakeSurfaceCaptureForUI with canvasdrawing node
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, TakeSurfaceCaptureForUiCanvasDrawingNode, Function | SmallTest | Level2)
|
||||
{
|
||||
SetUpSurface();
|
||||
|
||||
auto callback = std::make_shared<CustomizedSurfaceCapture>();
|
||||
bool ret = rsInterfaces_->TakeSurfaceCaptureForUI(canvasDrawingNode_, callback);
|
||||
ASSERT_EQ(ret, true);
|
||||
ASSERT_EQ(CheckSurfaceCaptureCallback(callback), true);
|
||||
ASSERT_EQ(callback->captureSuccess_, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TakeSurfaceCaptureForUiProxyNode
|
||||
* @tc.desc: Test TakeSurfaceCaptureForUI with proxy node
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, TakeSurfaceCaptureForUiProxyNode, Function | SmallTest | Level2)
|
||||
{
|
||||
SetUpSurface();
|
||||
|
||||
auto proxyNode = RSProxyNode::Create(canvasNode_->GetId());
|
||||
RSTransactionProxy::GetInstance()->FlushImplicitTransaction();
|
||||
|
||||
auto callback = std::make_shared<CustomizedSurfaceCapture>();
|
||||
bool ret = rsInterfaces_->TakeSurfaceCaptureForUI(proxyNode, callback);
|
||||
ASSERT_EQ(ret, false);
|
||||
ASSERT_EQ(CheckSurfaceCaptureCallback(callback), false);
|
||||
ASSERT_EQ(callback->captureSuccess_, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TakeSurfaceCaptureForUiSync001
|
||||
* @tc.desc: Test TakeSurfaceCaptureForUI sync is false
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, TakeSurfaceCaptureForUiSync001, Function | SmallTest | Level2)
|
||||
{
|
||||
auto canvasNode = RSCanvasNode::Create();
|
||||
canvasNode->SetBounds(0.0f, 0.0f, HALF_BOUNDS_WIDTH, HALF_BOUNDS_HEIGHT);
|
||||
canvasNode->SetFrame(0.0f, 0.0f, HALF_BOUNDS_WIDTH, HALF_BOUNDS_HEIGHT);
|
||||
canvasNode->SetBackgroundColor(Drawing::Color::COLOR_YELLOW);
|
||||
auto callback = std::make_shared<CustomizedSurfaceCapture>();
|
||||
bool ret = rsInterfaces_->TakeSurfaceCaptureForUI(canvasNode, callback);
|
||||
ASSERT_EQ(ret, true);
|
||||
ASSERT_EQ(CheckSurfaceCaptureCallback(callback), true);
|
||||
ASSERT_EQ(callback->captureSuccess_, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TakeSurfaceCaptureForUiSync002
|
||||
* @tc.desc: Test TakeSurfaceCaptureForUI sync is true
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, TakeSurfaceCaptureForUiSync002, Function | SmallTest | Level2)
|
||||
{
|
||||
auto canvasNode = RSCanvasNode::Create();
|
||||
canvasNode->SetBounds(0.0f, 0.0f, HALF_BOUNDS_WIDTH, HALF_BOUNDS_HEIGHT);
|
||||
canvasNode->SetFrame(0.0f, 0.0f, HALF_BOUNDS_WIDTH, HALF_BOUNDS_HEIGHT);
|
||||
canvasNode->SetBackgroundColor(Drawing::Color::COLOR_YELLOW);
|
||||
auto callback = std::make_shared<CustomizedSurfaceCapture>();
|
||||
bool ret = rsInterfaces_->TakeSurfaceCaptureForUI(canvasNode, callback, 1.0, 1.0, true);
|
||||
ASSERT_EQ(ret, true);
|
||||
ASSERT_EQ(CheckSurfaceCaptureCallback(callback), true);
|
||||
ASSERT_EQ(callback->captureSuccess_, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TakeSurfaceCaptureForUiScale001
|
||||
* @tc.desc: Test TakeSurfaceCaptureForUI scale
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, TakeSurfaceCaptureForUiScale001, Function | SmallTest | Level2)
|
||||
{
|
||||
SetUpSurface();
|
||||
|
||||
auto callback = std::make_shared<CustomizedSurfaceCapture>();
|
||||
bool ret = rsInterfaces_->TakeSurfaceCaptureForUI(canvasNode_, callback, 0, 0);
|
||||
ASSERT_EQ(ret, true);
|
||||
ASSERT_EQ(CheckSurfaceCaptureCallback(callback), true);
|
||||
ASSERT_EQ(callback->captureSuccess_, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TakeSurfaceCaptureForUiScale002
|
||||
* @tc.desc: Test TakeSurfaceCaptureForUI scale
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, TakeSurfaceCaptureForUiScale002, Function | SmallTest | Level2)
|
||||
{
|
||||
SetUpSurface();
|
||||
|
||||
auto callback = std::make_shared<CustomizedSurfaceCapture>();
|
||||
bool ret = rsInterfaces_->TakeSurfaceCaptureForUI(canvasNode_, callback, -1, -1);
|
||||
ASSERT_EQ(ret, true);
|
||||
ASSERT_EQ(CheckSurfaceCaptureCallback(callback), true);
|
||||
ASSERT_EQ(callback->captureSuccess_, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TakeSurfaceCaptureForUiScale003
|
||||
* @tc.desc: Test TakeSurfaceCaptureForUI scale
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, TakeSurfaceCaptureForUiScale003, Function | SmallTest | Level2)
|
||||
{
|
||||
SetUpSurface();
|
||||
|
||||
auto callback = std::make_shared<CustomizedSurfaceCapture>();
|
||||
bool ret = rsInterfaces_->TakeSurfaceCaptureForUI(canvasNode_, callback, 10000, 10000);
|
||||
ASSERT_EQ(ret, true);
|
||||
ASSERT_EQ(CheckSurfaceCaptureCallback(callback), true);
|
||||
ASSERT_EQ(callback->captureSuccess_, false);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: TakeSurfaceCaptureForUiNotOnTree
|
||||
* @tc.desc: Test TakeSurfaceCaptureForUI with node not on tree
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, TakeSurfaceCaptureForUiNotOnTree, Function | SmallTest | Level2)
|
||||
{
|
||||
SetUpSurface();
|
||||
|
||||
displayNode_->RemoveChild(surfaceNode_);
|
||||
RSTransactionProxy::GetInstance()->FlushImplicitTransaction();
|
||||
|
||||
auto callback = std::make_shared<CustomizedSurfaceCapture>();
|
||||
bool ret = rsInterfaces_->TakeSurfaceCaptureForUI(canvasNode_, callback);
|
||||
ASSERT_EQ(ret, true);
|
||||
ASSERT_EQ(CheckSurfaceCaptureCallback(callback), true);
|
||||
ASSERT_EQ(callback->captureSuccess_, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: CreateResources001
|
||||
* @tc.desc: Test RSUiCaptureTaskParallel::CreateResources
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, CreateResources001, Function | SmallTest | Level2)
|
||||
{
|
||||
NodeId id = -1; // invalid id
|
||||
RSSurfaceCaptureConfig captureConfig;
|
||||
auto handle = std::make_shared<RSUiCaptureTaskParallel>(id, captureConfig);
|
||||
ASSERT_EQ(handle->CreateResources(), false);
|
||||
ASSERT_EQ(handle->captureConfig_.scaleX, 1.0f);
|
||||
ASSERT_EQ(handle->captureConfig_.scaleY, 1.0f);
|
||||
ASSERT_EQ(handle->pixelMap_, nullptr);
|
||||
ASSERT_EQ(handle->nodeDrawable_, nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: CreateResources002
|
||||
* @tc.desc: Test RSUiCaptureTaskParallel::CreateResources
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, CreateResources002, Function | SmallTest | Level2)
|
||||
{
|
||||
auto& nodeMap = RSMainThread::Instance()->GetContext().nodeMap;
|
||||
|
||||
// RSSurfaceRenderNode
|
||||
NodeId surfaceRenderNodeId = 101;
|
||||
RSSurfaceCaptureConfig config1;
|
||||
auto surfaceRenderNode = std::make_shared<RSSurfaceRenderNode>(surfaceRenderNodeId, std::make_shared<RSContext>(),
|
||||
true);
|
||||
nodeMap.RegisterRenderNode(surfaceRenderNode);
|
||||
auto surfaceRenderNodeHandle = std::make_shared<RSUiCaptureTaskParallel>(surfaceRenderNodeId, config1);
|
||||
ASSERT_EQ(surfaceRenderNodeHandle->CreateResources(), false);
|
||||
|
||||
// RSCanvasRenderNode
|
||||
NodeId canvasRenderNodeId = 102;
|
||||
RSSurfaceCaptureConfig config2;
|
||||
auto canvasRenderNode = std::make_shared<RSCanvasRenderNode>(canvasRenderNodeId, std::make_shared<RSContext>(),
|
||||
true);
|
||||
nodeMap.RegisterRenderNode(canvasRenderNode);
|
||||
auto canvasRenderNodeHandle = std::make_shared<RSUiCaptureTaskParallel>(canvasRenderNodeId, config2);
|
||||
ASSERT_EQ(canvasRenderNodeHandle->CreateResources(), false);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: CreateResources003
|
||||
* @tc.desc: Test RSUiCaptureTaskParallel::CreateResources
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, CreateResources003, Function | SmallTest | Level2)
|
||||
{
|
||||
auto& nodeMap = RSMainThread::Instance()->GetContext().nodeMap;
|
||||
|
||||
NodeId nodeId = 103;
|
||||
NodeId parentNodeId = 1003;
|
||||
RSSurfaceCaptureConfig config;
|
||||
auto renderNode = std::make_shared<RSSurfaceRenderNode>(nodeId, std::make_shared<RSContext>(), true);
|
||||
renderNode->renderContent_->renderProperties_.SetBoundsWidth(1024.0f);
|
||||
renderNode->renderContent_->renderProperties_.SetBoundsHeight(1024.0f);
|
||||
nodeMap.RegisterRenderNode(renderNode);
|
||||
|
||||
auto renderNodeHandle = std::make_shared<RSUiCaptureTaskParallel>(nodeId, config);
|
||||
ASSERT_EQ(renderNodeHandle->CreateResources(), true);
|
||||
|
||||
auto parent1 = std::make_shared<RSSurfaceRenderNode>(parentNodeId, std::make_shared<RSContext>(), true);
|
||||
parent1->nodeType_ = RSSurfaceNodeType::LEASH_WINDOW_NODE;
|
||||
parent1->hasSubNodeShouldPaint_ = false;
|
||||
renderNode->parent_ = parent1;
|
||||
ASSERT_EQ(renderNodeHandle->CreateResources(), true);
|
||||
|
||||
auto parent2 = std::make_shared<RSSurfaceRenderNode>(parentNodeId, std::make_shared<RSContext>(), true);
|
||||
parent2->nodeType_ = RSSurfaceNodeType::LEASH_WINDOW_NODE;
|
||||
parent2->hasSubNodeShouldPaint_ = true;
|
||||
renderNode->parent_ = parent2;
|
||||
ASSERT_EQ(renderNodeHandle->CreateResources(), true);
|
||||
|
||||
auto parent3 = std::make_shared<RSSurfaceRenderNode>(parentNodeId, std::make_shared<RSContext>(), true);
|
||||
parent3->nodeType_ = RSSurfaceNodeType::LEASH_WINDOW_NODE;
|
||||
parent3->hasSubNodeShouldPaint_ = true;
|
||||
parent3->lastFrameUifirstFlag_ = MultiThreadCacheType::LEASH_WINDOW;
|
||||
renderNode->parent_ = parent3;
|
||||
ASSERT_EQ(renderNodeHandle->CreateResources(), false);
|
||||
|
||||
auto parent4 = std::make_shared<RSSurfaceRenderNode>(parentNodeId, std::make_shared<RSContext>(), true);
|
||||
parent4->nodeType_ = RSSurfaceNodeType::LEASH_WINDOW_NODE;
|
||||
parent4->hasSubNodeShouldPaint_ = true;
|
||||
parent4->lastFrameUifirstFlag_ = MultiThreadCacheType::NONFOCUS_WINDOW;
|
||||
parent4->renderContent_->renderProperties_.SetBoundsWidth(1024.0f);
|
||||
parent4->renderContent_->renderProperties_.SetBoundsHeight(1024.0f);
|
||||
renderNode->parent_ = parent4;
|
||||
ASSERT_EQ(renderNodeHandle->CreateResources(), true);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: RSUiCaptureTaskParallel_CreatePixelMapByNode
|
||||
* @tc.desc: Test RSUiCaptureTaskParallel::CreatePixelMapByNode
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueIA6QID
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, RSUiCaptureTaskParallel_CreatePixelMapByNode, Function | SmallTest | Level2)
|
||||
{
|
||||
NodeId id = -1; // invalid id
|
||||
RSSurfaceCaptureConfig captureConfig;
|
||||
auto handle = std::make_shared<RSUiCaptureTaskParallel>(id, captureConfig);
|
||||
auto node = RSTestUtil::CreateSurfaceNode();
|
||||
ASSERT_EQ(handle->CreatePixelMapByNode(node), nullptr);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: RSUiCaptureTaskParallel_CreateSurfaceSyncCopyTask
|
||||
* @tc.desc: Test RSUiCaptureTaskParallel::CreateSurfaceSyncCopyTask
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(RSUiCaptureTaskTest, RSUiCaptureTaskParallel_CreateSurfaceSyncCopyTask, Function | SmallTest | Level2)
|
||||
{
|
||||
auto node = RSTestUtil::CreateSurfaceNode();
|
||||
auto mainThread = RSMainThread::Instance();
|
||||
|
||||
mainThread->context_->nodeMap.RegisterRenderNode(node);
|
||||
|
||||
auto mockCallback = sptr<MockSurfaceCaptureCallback>(new MockSurfaceCaptureCallback);
|
||||
auto pixelMap = std::make_unique<Media::PixelMap>();
|
||||
ASSERT_NE(pixelMap, nullptr);
|
||||
auto surface = std::make_shared<Drawing::Surface>();
|
||||
ASSERT_NE(surface, nullptr);
|
||||
#ifdef RS_ENABLE_UNI_RENDER
|
||||
auto copytask =
|
||||
RSUiCaptureTaskParallel::CreateSurfaceSyncCopyTask(surface, std::move(pixelMap), node->GetId(), mockCallback);
|
||||
|
||||
ASSERT_FALSE(copytask);
|
||||
mainThread->context_->nodeMap.UnregisterRenderNode(node->GetId());
|
||||
#endif
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user