Derek Sollenberger | daf7229 | 2016-10-25 12:09:18 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <gtest/gtest.h> |
| 18 | |
| 19 | #include "AnimationContext.h" |
| 20 | #include "IContextFactory.h" |
| 21 | #include "renderthread/CanvasContext.h" |
John Reck | 20a4d68 | 2023-07-11 17:11:51 -0400 | [diff] [blame^] | 22 | #include "renderthread/VulkanManager.h" |
Derek Sollenberger | daf7229 | 2016-10-25 12:09:18 -0400 | [diff] [blame] | 23 | #include "tests/common/TestUtils.h" |
| 24 | |
| 25 | using namespace android; |
| 26 | using namespace android::uirenderer; |
| 27 | using namespace android::uirenderer::renderthread; |
| 28 | |
| 29 | class ContextFactory : public IContextFactory { |
| 30 | public: |
| 31 | virtual AnimationContext* createAnimationContext(renderthread::TimeLord& clock) override { |
| 32 | return new AnimationContext(clock); |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | RENDERTHREAD_TEST(CanvasContext, create) { |
| 37 | auto rootNode = TestUtils::createNode(0, 0, 200, 400, nullptr); |
| 38 | ContextFactory contextFactory; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 39 | std::unique_ptr<CanvasContext> canvasContext( |
Matt Buckley | e9023cf | 2022-11-23 22:39:25 +0000 | [diff] [blame] | 40 | CanvasContext::create(renderThread, false, rootNode.get(), &contextFactory, 0, 0)); |
Derek Sollenberger | daf7229 | 2016-10-25 12:09:18 -0400 | [diff] [blame] | 41 | |
Nader Jawad | a352185 | 2023-01-30 20:23:46 -0800 | [diff] [blame] | 42 | ASSERT_FALSE(canvasContext->hasOutputTarget()); |
Derek Sollenberger | daf7229 | 2016-10-25 12:09:18 -0400 | [diff] [blame] | 43 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 44 | canvasContext->destroy(); |
Derek Sollenberger | daf7229 | 2016-10-25 12:09:18 -0400 | [diff] [blame] | 45 | } |
John Reck | 20a4d68 | 2023-07-11 17:11:51 -0400 | [diff] [blame^] | 46 | |
| 47 | RENDERTHREAD_TEST(CanvasContext, buildLayerDoesntLeak) { |
| 48 | auto node = TestUtils::createNode(0, 0, 200, 400, [](RenderProperties& props, Canvas& canvas) { |
| 49 | canvas.drawColor(0xFFFF0000, SkBlendMode::kSrc); |
| 50 | }); |
| 51 | ASSERT_TRUE(node->isValid()); |
| 52 | EXPECT_EQ(LayerType::None, node->stagingProperties().effectiveLayerType()); |
| 53 | node->mutateStagingProperties().mutateLayerProperties().setType(LayerType::RenderLayer); |
| 54 | |
| 55 | auto& cacheManager = renderThread.cacheManager(); |
| 56 | EXPECT_TRUE(cacheManager.areAllContextsStopped()); |
| 57 | ContextFactory contextFactory; |
| 58 | std::unique_ptr<CanvasContext> canvasContext( |
| 59 | CanvasContext::create(renderThread, false, node.get(), &contextFactory, 0, 0)); |
| 60 | canvasContext->buildLayer(node.get()); |
| 61 | EXPECT_TRUE(node->hasLayer()); |
| 62 | if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaVulkan) { |
| 63 | auto instance = VulkanManager::peekInstance(); |
| 64 | if (instance) { |
| 65 | EXPECT_TRUE(instance->hasVkContext()); |
| 66 | } else { |
| 67 | ADD_FAILURE() << "VulkanManager wasn't initialized to buildLayer?"; |
| 68 | } |
| 69 | } |
| 70 | renderThread.destroyRenderingContext(); |
| 71 | EXPECT_FALSE(node->hasLayer()) << "Node still has a layer after rendering context destroyed"; |
| 72 | |
| 73 | if (Properties::getRenderPipelineType() == RenderPipelineType::SkiaVulkan) { |
| 74 | auto instance = VulkanManager::peekInstance(); |
| 75 | if (instance) { |
| 76 | ADD_FAILURE() << "VulkanManager still exists"; |
| 77 | EXPECT_FALSE(instance->hasVkContext()); |
| 78 | } |
| 79 | } |
| 80 | } |