Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | */ |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 16 | |
| 17 | #pragma once |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 18 | |
Chris Craik | 76caecf | 2015-11-02 19:17:45 -0800 | [diff] [blame] | 19 | #include <DeviceInfo.h> |
Chris Craik | 161f54b | 2015-11-05 11:08:52 -0800 | [diff] [blame] | 20 | #include <DisplayList.h> |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 21 | #include <Matrix.h> |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 22 | #include <Properties.h> |
Chris Craik | 0a24b14 | 2015-10-19 17:10:19 -0700 | [diff] [blame] | 23 | #include <Rect.h> |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 24 | #include <RenderNode.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 25 | #include <Snapshot.h> |
sergeyv | c1c5406 | 2016-10-19 18:47:26 -0700 | [diff] [blame] | 26 | #include <hwui/Bitmap.h> |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 27 | #include <pipeline/skia/SkiaRecordingCanvas.h> |
Chris Craik | 0a24b14 | 2015-10-19 17:10:19 -0700 | [diff] [blame] | 28 | #include <renderstate/RenderState.h> |
| 29 | #include <renderthread/RenderThread.h> |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 30 | |
Chris Craik | 161f54b | 2015-11-05 11:08:52 -0800 | [diff] [blame] | 31 | #include <RecordedOp.h> |
Chris Craik | 161f54b | 2015-11-05 11:08:52 -0800 | [diff] [blame] | 32 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 33 | #include <memory> |
| 34 | |
| 35 | namespace android { |
| 36 | namespace uirenderer { |
| 37 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 38 | #define EXPECT_MATRIX_APPROX_EQ(a, b) EXPECT_TRUE(TestUtils::matricesAreApproxEqual(a, b)) |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 39 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 40 | #define EXPECT_RECT_APPROX_EQ(a, b) \ |
| 41 | EXPECT_TRUE(MathUtils::areEqual((a).left, (b).left) && \ |
| 42 | MathUtils::areEqual((a).top, (b).top) && \ |
| 43 | MathUtils::areEqual((a).right, (b).right) && \ |
| 44 | MathUtils::areEqual((a).bottom, (b).bottom)); |
Chris Craik | 6fe991e5 | 2015-10-20 09:39:42 -0700 | [diff] [blame] | 45 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 46 | #define EXPECT_CLIP_RECT(expRect, clipStatePtr) \ |
| 47 | EXPECT_NE(nullptr, (clipStatePtr)) << "Op is unclipped"; \ |
| 48 | if ((clipStatePtr)->mode == ClipMode::Rectangle) { \ |
| 49 | EXPECT_EQ((expRect), reinterpret_cast<const ClipRect*>(clipStatePtr)->rect); \ |
| 50 | } else { \ |
| 51 | ADD_FAILURE() << "ClipState not a rect"; \ |
| 52 | } |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 53 | |
| 54 | #define INNER_PIPELINE_TEST(test_case_name, test_name, pipeline, functionCall) \ |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 55 | TEST(test_case_name, test_name##_##pipeline) { \ |
| 56 | RenderPipelineType oldType = Properties::getRenderPipelineType(); \ |
| 57 | Properties::overrideRenderPipelineType(RenderPipelineType::pipeline); \ |
| 58 | functionCall; \ |
| 59 | Properties::overrideRenderPipelineType(oldType); \ |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 60 | }; |
| 61 | |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 62 | #define INNER_PIPELINE_RENDERTHREAD_TEST(test_case_name, test_name, pipeline) \ |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 63 | INNER_PIPELINE_TEST(test_case_name, test_name, pipeline, \ |
| 64 | TestUtils::runOnRenderThread( \ |
| 65 | test_case_name##_##test_name##_RenderThreadTest::doTheThing)) |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 66 | |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 67 | /** |
| 68 | * Like gtest's TEST, but runs on the RenderThread, and 'renderThread' is passed, in top level scope |
| 69 | * (for e.g. accessing its RenderState) |
| 70 | */ |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 71 | #define RENDERTHREAD_TEST(test_case_name, test_name) \ |
| 72 | class test_case_name##_##test_name##_RenderThreadTest { \ |
| 73 | public: \ |
| 74 | static void doTheThing(renderthread::RenderThread& renderThread); \ |
| 75 | }; \ |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 76 | INNER_PIPELINE_RENDERTHREAD_TEST(test_case_name, test_name, SkiaGL); \ |
Derek Sollenberger | 0f89539 | 2017-04-27 11:30:20 -0400 | [diff] [blame] | 77 | /* Temporarily disabling Vulkan until we can figure out a way to stub out the driver */ \ |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 78 | /* INNER_PIPELINE_RENDERTHREAD_TEST(test_case_name, test_name, SkiaVulkan); */ \ |
| 79 | void test_case_name##_##test_name##_RenderThreadTest::doTheThing( \ |
| 80 | renderthread::RenderThread& renderThread) |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 81 | |
| 82 | /** |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 83 | * Like RENDERTHREAD_TEST, but only runs with the Skia RenderPipelineTypes |
| 84 | */ |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 85 | #define RENDERTHREAD_SKIA_PIPELINE_TEST(test_case_name, test_name) \ |
| 86 | class test_case_name##_##test_name##_RenderThreadTest { \ |
| 87 | public: \ |
| 88 | static void doTheThing(renderthread::RenderThread& renderThread); \ |
| 89 | }; \ |
| 90 | INNER_PIPELINE_RENDERTHREAD_TEST(test_case_name, test_name, SkiaGL); \ |
Derek Sollenberger | 0f89539 | 2017-04-27 11:30:20 -0400 | [diff] [blame] | 91 | /* Temporarily disabling Vulkan until we can figure out a way to stub out the driver */ \ |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 92 | /* INNER_PIPELINE_RENDERTHREAD_TEST(test_case_name, test_name, SkiaVulkan); */ \ |
| 93 | void test_case_name##_##test_name##_RenderThreadTest::doTheThing( \ |
| 94 | renderthread::RenderThread& renderThread) |
Chris Craik | 98787e6 | 2015-11-13 10:55:30 -0800 | [diff] [blame] | 95 | |
Chris Craik | 3741328 | 2016-05-12 17:48:51 -0700 | [diff] [blame] | 96 | /** |
| 97 | * Sets a property value temporarily, generally for the duration of a test, restoring the previous |
| 98 | * value when going out of scope. |
| 99 | * |
| 100 | * Can be used e.g. to test behavior only active while Properties::debugOverdraw is enabled. |
| 101 | */ |
| 102 | template <typename T> |
| 103 | class ScopedProperty { |
| 104 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 105 | ScopedProperty(T& property, T newValue) : mPropertyPtr(&property), mOldValue(property) { |
Chris Craik | 3741328 | 2016-05-12 17:48:51 -0700 | [diff] [blame] | 106 | property = newValue; |
| 107 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 108 | ~ScopedProperty() { *mPropertyPtr = mOldValue; } |
| 109 | |
Chris Craik | 3741328 | 2016-05-12 17:48:51 -0700 | [diff] [blame] | 110 | private: |
| 111 | T* mPropertyPtr; |
| 112 | T mOldValue; |
| 113 | }; |
| 114 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 115 | class TestUtils { |
| 116 | public: |
Chris Craik | 76ace11 | 2015-10-29 12:46:19 -0700 | [diff] [blame] | 117 | class SignalingDtor { |
| 118 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 119 | SignalingDtor() : mSignal(nullptr) {} |
| 120 | explicit SignalingDtor(int* signal) : mSignal(signal) {} |
| 121 | void setSignal(int* signal) { mSignal = signal; } |
Chris Craik | 76ace11 | 2015-10-29 12:46:19 -0700 | [diff] [blame] | 122 | ~SignalingDtor() { |
| 123 | if (mSignal) { |
| 124 | (*mSignal)++; |
| 125 | } |
| 126 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 127 | |
Chris Craik | 76ace11 | 2015-10-29 12:46:19 -0700 | [diff] [blame] | 128 | private: |
| 129 | int* mSignal; |
| 130 | }; |
| 131 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 132 | class MockTreeObserver : public TreeObserver { |
| 133 | public: |
| 134 | virtual void onMaybeRemovedFromTree(RenderNode* node) {} |
| 135 | }; |
| 136 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 137 | static bool matricesAreApproxEqual(const Matrix4& a, const Matrix4& b) { |
| 138 | for (int i = 0; i < 16; i++) { |
| 139 | if (!MathUtils::areEqual(a[i], b[i])) { |
| 140 | return false; |
| 141 | } |
| 142 | } |
| 143 | return true; |
| 144 | } |
| 145 | |
| 146 | static std::unique_ptr<Snapshot> makeSnapshot(const Matrix4& transform, const Rect& clip) { |
| 147 | std::unique_ptr<Snapshot> snapshot(new Snapshot()); |
Mike Reed | 6e49c9f | 2016-12-02 15:36:59 -0500 | [diff] [blame] | 148 | // store clip first, so it isn't transformed |
| 149 | snapshot->setClip(clip.left, clip.top, clip.right, clip.bottom); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 150 | *(snapshot->transform) = transform; |
| 151 | return snapshot; |
| 152 | } |
| 153 | |
sergeyv | aed7f58 | 2016-10-14 16:30:21 -0700 | [diff] [blame] | 154 | static sk_sp<Bitmap> createBitmap(int width, int height, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 155 | SkColorType colorType = kN32_SkColorType) { |
sergeyv | aed7f58 | 2016-10-14 16:30:21 -0700 | [diff] [blame] | 156 | SkImageInfo info = SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType); |
sergeyv | fc999950 | 2016-10-17 13:07:38 -0700 | [diff] [blame] | 157 | return Bitmap::allocateHeapBitmap(info); |
sergeyv | aed7f58 | 2016-10-14 16:30:21 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static sk_sp<Bitmap> createBitmap(int width, int height, SkBitmap* outBitmap) { |
| 161 | SkImageInfo info = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); |
| 162 | outBitmap->setInfo(info); |
Leon Scroggins III | f51a80d | 2017-07-12 10:46:35 -0400 | [diff] [blame] | 163 | return Bitmap::allocateHeapBitmap(outBitmap); |
sergeyv | aed7f58 | 2016-10-14 16:30:21 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Chris Craik | d2dfd8f | 2015-12-16 14:27:20 -0800 | [diff] [blame] | 166 | static sp<DeferredLayerUpdater> createTextureLayerUpdater( |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 167 | renderthread::RenderThread& renderThread); |
| 168 | |
| 169 | static sp<DeferredLayerUpdater> createTextureLayerUpdater( |
Chris Craik | d2dfd8f | 2015-12-16 14:27:20 -0800 | [diff] [blame] | 170 | renderthread::RenderThread& renderThread, uint32_t width, uint32_t height, |
Chris Craik | 243e85b | 2016-03-25 15:26:11 -0700 | [diff] [blame] | 171 | const SkMatrix& transform); |
Chris Craik | d2dfd8f | 2015-12-16 14:27:20 -0800 | [diff] [blame] | 172 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 173 | template <class CanvasType> |
| 174 | static std::unique_ptr<DisplayList> createDisplayList( |
| 175 | int width, int height, std::function<void(CanvasType& canvas)> canvasCallback) { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 176 | CanvasType canvas(width, height); |
| 177 | canvasCallback(canvas); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 178 | return std::unique_ptr<DisplayList>(canvas.finishRecording()); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 179 | } |
| 180 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 181 | static sp<RenderNode> createNode( |
| 182 | int left, int top, int right, int bottom, |
Stan Iliev | 06152cd | 2016-07-27 17:55:43 -0400 | [diff] [blame] | 183 | std::function<void(RenderProperties& props, Canvas& canvas)> setup) { |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 184 | #if HWUI_NULL_GPU |
Chris Craik | 76caecf | 2015-11-02 19:17:45 -0800 | [diff] [blame] | 185 | // if RenderNodes are being sync'd/used, device info will be needed, since |
| 186 | // DeviceInfo::maxTextureSize() affects layer property |
| 187 | DeviceInfo::initialize(); |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 188 | #endif |
Chris Craik | 76caecf | 2015-11-02 19:17:45 -0800 | [diff] [blame] | 189 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 190 | sp<RenderNode> node = new RenderNode(); |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 191 | RenderProperties& props = node->mutateStagingProperties(); |
| 192 | props.setLeftTopRightBottom(left, top, right, bottom); |
| 193 | if (setup) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 194 | std::unique_ptr<Canvas> canvas( |
| 195 | Canvas::create_recording_canvas(props.getWidth(), props.getHeight())); |
Stan Iliev | 06152cd | 2016-07-27 17:55:43 -0400 | [diff] [blame] | 196 | setup(props, *canvas.get()); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 197 | node->setStagingDisplayList(canvas->finishRecording()); |
Stan Iliev | 06152cd | 2016-07-27 17:55:43 -0400 | [diff] [blame] | 198 | } |
| 199 | node->setPropertyFieldsDirty(0xFFFFFFFF); |
| 200 | return node; |
| 201 | } |
| 202 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 203 | template <class RecordingCanvasType> |
| 204 | static sp<RenderNode> createNode( |
| 205 | int left, int top, int right, int bottom, |
Stan Iliev | 06152cd | 2016-07-27 17:55:43 -0400 | [diff] [blame] | 206 | std::function<void(RenderProperties& props, RecordingCanvasType& canvas)> setup) { |
| 207 | #if HWUI_NULL_GPU |
| 208 | // if RenderNodes are being sync'd/used, device info will be needed, since |
| 209 | // DeviceInfo::maxTextureSize() affects layer property |
| 210 | DeviceInfo::initialize(); |
| 211 | #endif |
| 212 | |
| 213 | sp<RenderNode> node = new RenderNode(); |
| 214 | RenderProperties& props = node->mutateStagingProperties(); |
| 215 | props.setLeftTopRightBottom(left, top, right, bottom); |
| 216 | if (setup) { |
| 217 | RecordingCanvasType canvas(props.getWidth(), props.getHeight()); |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 218 | setup(props, canvas); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 219 | node->setStagingDisplayList(canvas.finishRecording()); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 220 | } |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 221 | node->setPropertyFieldsDirty(0xFFFFFFFF); |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 222 | return node; |
| 223 | } |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 224 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 225 | static void recordNode(RenderNode& node, std::function<void(Canvas&)> contentCallback) { |
| 226 | std::unique_ptr<Canvas> canvas(Canvas::create_recording_canvas( |
Stan Iliev | 4f901c8 | 2018-04-13 10:21:26 -0400 | [diff] [blame] | 227 | node.stagingProperties().getWidth(), node.stagingProperties().getHeight(), |
| 228 | &node)); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 229 | contentCallback(*canvas.get()); |
| 230 | node.setStagingDisplayList(canvas->finishRecording()); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 231 | } |
| 232 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 233 | static sp<RenderNode> createSkiaNode( |
| 234 | int left, int top, int right, int bottom, |
| 235 | std::function<void(RenderProperties& props, skiapipeline::SkiaRecordingCanvas& canvas)> |
| 236 | setup, |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 237 | const char* name = nullptr, skiapipeline::SkiaDisplayList* displayList = nullptr) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 238 | #if HWUI_NULL_GPU |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 239 | // if RenderNodes are being sync'd/used, device info will be needed, since |
| 240 | // DeviceInfo::maxTextureSize() affects layer property |
| 241 | DeviceInfo::initialize(); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 242 | #endif |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 243 | sp<RenderNode> node = new RenderNode(); |
| 244 | if (name) { |
| 245 | node->setName(name); |
| 246 | } |
| 247 | RenderProperties& props = node->mutateStagingProperties(); |
| 248 | props.setLeftTopRightBottom(left, top, right, bottom); |
| 249 | if (displayList) { |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 250 | node->setStagingDisplayList(displayList); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 251 | } |
| 252 | if (setup) { |
| 253 | std::unique_ptr<skiapipeline::SkiaRecordingCanvas> canvas( |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 254 | new skiapipeline::SkiaRecordingCanvas(nullptr, props.getWidth(), |
| 255 | props.getHeight())); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 256 | setup(props, *canvas.get()); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 257 | node->setStagingDisplayList(canvas->finishRecording()); |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 258 | } |
| 259 | node->setPropertyFieldsDirty(0xFFFFFFFF); |
| 260 | TestUtils::syncHierarchyPropertiesAndDisplayList(node); |
| 261 | return node; |
| 262 | } |
| 263 | |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 264 | /** |
| 265 | * Forces a sync of a tree of RenderNode, such that every descendant will have its staging |
| 266 | * properties and DisplayList moved to the render copies. |
| 267 | * |
| 268 | * Note: does not check dirtiness bits, so any non-staging DisplayLists will be discarded. |
| 269 | * For this reason, this should generally only be called once on a tree. |
| 270 | */ |
Chris Craik | 161f54b | 2015-11-05 11:08:52 -0800 | [diff] [blame] | 271 | static void syncHierarchyPropertiesAndDisplayList(sp<RenderNode>& node) { |
| 272 | syncHierarchyPropertiesAndDisplayListImpl(node.get()); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 273 | } |
Chris Craik | 0a24b14 | 2015-10-19 17:10:19 -0700 | [diff] [blame] | 274 | |
Chris Craik | 9cd1bbe | 2016-04-14 16:08:25 -0700 | [diff] [blame] | 275 | static sp<RenderNode>& getSyncedNode(sp<RenderNode>& node) { |
| 276 | syncHierarchyPropertiesAndDisplayList(node); |
| 277 | return node; |
John Reck | 7db5ffb | 2016-01-15 13:17:09 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 280 | typedef std::function<void(renderthread::RenderThread& thread)> RtCallback; |
Chris Craik | 0a24b14 | 2015-10-19 17:10:19 -0700 | [diff] [blame] | 281 | |
| 282 | class TestTask : public renderthread::RenderTask { |
| 283 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 284 | explicit TestTask(RtCallback rtCallback) : rtCallback(rtCallback) {} |
Chris Craik | 0a24b14 | 2015-10-19 17:10:19 -0700 | [diff] [blame] | 285 | virtual ~TestTask() {} |
John Reck | e5da4ef | 2016-01-14 12:34:46 -0800 | [diff] [blame] | 286 | virtual void run() override; |
Chris Craik | 0a24b14 | 2015-10-19 17:10:19 -0700 | [diff] [blame] | 287 | RtCallback rtCallback; |
| 288 | }; |
| 289 | |
| 290 | /** |
| 291 | * NOTE: requires surfaceflinger to run, otherwise this method will wait indefinitely. |
| 292 | */ |
| 293 | static void runOnRenderThread(RtCallback rtCallback) { |
| 294 | TestTask task(rtCallback); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 295 | renderthread::RenderThread::getInstance().queue().runSync([&]() { task.run(); }); |
Chris Craik | 0a24b14 | 2015-10-19 17:10:19 -0700 | [diff] [blame] | 296 | } |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 297 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 298 | static bool isRenderThreadRunning() { return renderthread::RenderThread::hasInstance(); } |
John Reck | 38e0c32 | 2015-11-10 12:19:17 -0800 | [diff] [blame] | 299 | |
John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 300 | static SkColor interpolateColor(float fraction, SkColor start, SkColor end); |
| 301 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 302 | static void drawUtf8ToCanvas(Canvas* canvas, const char* text, const SkPaint& paint, float x, |
| 303 | float y); |
Chris Craik | a171727 | 2015-11-19 13:02:43 -0800 | [diff] [blame] | 304 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 305 | static void drawUtf8ToCanvas(Canvas* canvas, const char* text, const SkPaint& paint, |
| 306 | const SkPath& path); |
Chris Craik | d7448e6 | 2015-12-15 10:34:36 -0800 | [diff] [blame] | 307 | |
Derek Sollenberger | 79abbf2 | 2016-03-24 11:07:19 -0400 | [diff] [blame] | 308 | static std::unique_ptr<uint16_t[]> asciiToUtf16(const char* str); |
sergeyv | dccca44 | 2016-03-21 15:38:21 -0700 | [diff] [blame] | 309 | |
Derek Sollenberger | 835b3a69 | 2016-10-28 13:57:14 -0400 | [diff] [blame] | 310 | class MockFunctor : public Functor { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 311 | public: |
| 312 | virtual status_t operator()(int what, void* data) { |
| 313 | mLastMode = what; |
| 314 | return DrawGlInfo::kStatusDone; |
| 315 | } |
| 316 | int getLastMode() const { return mLastMode; } |
| 317 | |
| 318 | private: |
| 319 | int mLastMode = -1; |
| 320 | }; |
Derek Sollenberger | 835b3a69 | 2016-10-28 13:57:14 -0400 | [diff] [blame] | 321 | |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 322 | static SkColor getColor(const sk_sp<SkSurface>& surface, int x, int y); |
| 323 | |
Stan Iliev | 5277127 | 2016-11-17 09:54:38 -0500 | [diff] [blame] | 324 | static SkRect getClipBounds(const SkCanvas* canvas); |
| 325 | static SkRect getLocalClipBounds(const SkCanvas* canvas); |
| 326 | |
Chris Craik | 161f54b | 2015-11-05 11:08:52 -0800 | [diff] [blame] | 327 | private: |
| 328 | static void syncHierarchyPropertiesAndDisplayListImpl(RenderNode* node) { |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 329 | MarkAndSweepRemoved observer(nullptr); |
Chris Craik | 161f54b | 2015-11-05 11:08:52 -0800 | [diff] [blame] | 330 | node->syncProperties(); |
John Reck | 3afd637 | 2017-01-30 10:15:48 -0800 | [diff] [blame] | 331 | if (node->mNeedsDisplayListSync) { |
| 332 | node->mNeedsDisplayListSync = false; |
| 333 | node->syncDisplayList(observer, nullptr); |
| 334 | } |
Chris Craik | 161f54b | 2015-11-05 11:08:52 -0800 | [diff] [blame] | 335 | auto displayList = node->getDisplayList(); |
| 336 | if (displayList) { |
John Reck | d9d7f12 | 2018-05-03 14:40:56 -0700 | [diff] [blame^] | 337 | for (auto&& childDr : static_cast<skiapipeline::SkiaDisplayList*>( |
| 338 | const_cast<DisplayList*>(displayList)) |
| 339 | ->mChildNodes) { |
| 340 | syncHierarchyPropertiesAndDisplayListImpl(childDr.getRenderNode()); |
Chris Craik | 161f54b | 2015-11-05 11:08:52 -0800 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 345 | }; // class TestUtils |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 346 | |
| 347 | } /* namespace uirenderer */ |
| 348 | } /* namespace android */ |