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