Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [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 | |
Chris Craik | f158b49 | 2016-01-12 14:45:08 -0800 | [diff] [blame] | 17 | #include "LayerBuilder.h" |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 18 | |
| 19 | #include "BakedOpState.h" |
| 20 | #include "RenderNode.h" |
| 21 | #include "utils/PaintUtils.h" |
| 22 | #include "utils/TraceUtils.h" |
| 23 | |
| 24 | #include <utils/TypeHelpers.h> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace uirenderer { |
| 28 | |
| 29 | class BatchBase { |
| 30 | public: |
| 31 | BatchBase(batchid_t batchId, BakedOpState* op, bool merging) |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 32 | : mBatchId(batchId), mMerging(merging) { |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 33 | mBounds = op->computedState.clippedBounds; |
| 34 | mOps.push_back(op); |
| 35 | } |
| 36 | |
| 37 | bool intersects(const Rect& rect) const { |
| 38 | if (!rect.intersects(mBounds)) return false; |
| 39 | |
| 40 | for (const BakedOpState* op : mOps) { |
| 41 | if (rect.intersects(op->computedState.clippedBounds)) { |
| 42 | return true; |
| 43 | } |
| 44 | } |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | batchid_t getBatchId() const { return mBatchId; } |
| 49 | bool isMerging() const { return mMerging; } |
| 50 | |
| 51 | const std::vector<BakedOpState*>& getOps() const { return mOps; } |
| 52 | |
| 53 | void dump() const { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 54 | ALOGD(" Batch %p, id %d, merging %d, count %d, bounds " RECT_STRING, this, mBatchId, |
| 55 | mMerging, (int)mOps.size(), RECT_ARGS(mBounds)); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 56 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 57 | |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 58 | protected: |
| 59 | batchid_t mBatchId; |
| 60 | Rect mBounds; |
| 61 | std::vector<BakedOpState*> mOps; |
| 62 | bool mMerging; |
| 63 | }; |
| 64 | |
| 65 | class OpBatch : public BatchBase { |
| 66 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 67 | OpBatch(batchid_t batchId, BakedOpState* op) : BatchBase(batchId, op, false) {} |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 68 | |
| 69 | void batchOp(BakedOpState* op) { |
| 70 | mBounds.unionWith(op->computedState.clippedBounds); |
| 71 | mOps.push_back(op); |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | class MergingOpBatch : public BatchBase { |
| 76 | public: |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 77 | MergingOpBatch(batchid_t batchId, BakedOpState* op) |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 78 | : BatchBase(batchId, op, true), mClipSideFlags(op->computedState.clipSideFlags) {} |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * Helper for determining if a new op can merge with a MergingDrawBatch based on their bounds |
| 82 | * and clip side flags. Positive bounds delta means new bounds fit in old. |
| 83 | */ |
| 84 | static inline bool checkSide(const int currentFlags, const int newFlags, const int side, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 85 | float boundsDelta) { |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 86 | bool currentClipExists = currentFlags & side; |
| 87 | bool newClipExists = newFlags & side; |
| 88 | |
| 89 | // if current is clipped, we must be able to fit new bounds in current |
| 90 | if (boundsDelta > 0 && currentClipExists) return false; |
| 91 | |
| 92 | // if new is clipped, we must be able to fit current bounds in new |
| 93 | if (boundsDelta < 0 && newClipExists) return false; |
| 94 | |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | static bool paintIsDefault(const SkPaint& paint) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 99 | return paint.getAlpha() == 255 && paint.getColorFilter() == nullptr && |
| 100 | paint.getShader() == nullptr; |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static bool paintsAreEquivalent(const SkPaint& a, const SkPaint& b) { |
| 104 | // Note: don't check color, since all currently mergeable ops can merge across colors |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 105 | return a.getAlpha() == b.getAlpha() && a.getColorFilter() == b.getColorFilter() && |
| 106 | a.getShader() == b.getShader(); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /* |
| 110 | * Checks if a (mergeable) op can be merged into this batch |
| 111 | * |
| 112 | * If true, the op's multiDraw must be guaranteed to handle both ops simultaneously, so it is |
| 113 | * important to consider all paint attributes used in the draw calls in deciding both a) if an |
| 114 | * op tries to merge at all, and b) if the op can merge with another set of ops |
| 115 | * |
| 116 | * False positives can lead to information from the paints of subsequent merged operations being |
| 117 | * dropped, so we make simplifying qualifications on the ops that can merge, per op type. |
| 118 | */ |
| 119 | bool canMergeWith(BakedOpState* op) const { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 120 | bool isTextBatch = |
| 121 | getBatchId() == OpBatchType::Text || getBatchId() == OpBatchType::ColorText; |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 122 | |
| 123 | // Overlapping other operations is only allowed for text without shadow. For other ops, |
| 124 | // multiDraw isn't guaranteed to overdraw correctly |
| 125 | if (!isTextBatch || PaintUtils::hasTextShadow(op->op->paint)) { |
| 126 | if (intersects(op->computedState.clippedBounds)) return false; |
| 127 | } |
| 128 | |
| 129 | const BakedOpState* lhs = op; |
| 130 | const BakedOpState* rhs = mOps[0]; |
| 131 | |
| 132 | if (!MathUtils::areEqual(lhs->alpha, rhs->alpha)) return false; |
| 133 | |
| 134 | // Identical round rect clip state means both ops will clip in the same way, or not at all. |
| 135 | // As the state objects are const, we can compare their pointers to determine mergeability |
| 136 | if (lhs->roundRectClipState != rhs->roundRectClipState) return false; |
Chris Craik | 678ff81 | 2016-03-01 13:27:54 -0800 | [diff] [blame] | 137 | |
| 138 | // Local masks prevent merge, since they're potentially in different coordinate spaces |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 139 | if (lhs->computedState.localProjectionPathMask || |
| 140 | rhs->computedState.localProjectionPathMask) |
| 141 | return false; |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 142 | |
| 143 | /* Clipping compatibility check |
| 144 | * |
| 145 | * Exploits the fact that if a op or batch is clipped on a side, its bounds will equal its |
| 146 | * clip for that side. |
| 147 | */ |
| 148 | const int currentFlags = mClipSideFlags; |
| 149 | const int newFlags = op->computedState.clipSideFlags; |
| 150 | if (currentFlags != OpClipSideFlags::None || newFlags != OpClipSideFlags::None) { |
| 151 | const Rect& opBounds = op->computedState.clippedBounds; |
| 152 | float boundsDelta = mBounds.left - opBounds.left; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 153 | if (!checkSide(currentFlags, newFlags, OpClipSideFlags::Left, boundsDelta)) |
| 154 | return false; |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 155 | boundsDelta = mBounds.top - opBounds.top; |
| 156 | if (!checkSide(currentFlags, newFlags, OpClipSideFlags::Top, boundsDelta)) return false; |
| 157 | |
| 158 | // right and bottom delta calculation reversed to account for direction |
| 159 | boundsDelta = opBounds.right - mBounds.right; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 160 | if (!checkSide(currentFlags, newFlags, OpClipSideFlags::Right, boundsDelta)) |
| 161 | return false; |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 162 | boundsDelta = opBounds.bottom - mBounds.bottom; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 163 | if (!checkSide(currentFlags, newFlags, OpClipSideFlags::Bottom, boundsDelta)) |
| 164 | return false; |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | const SkPaint* newPaint = op->op->paint; |
| 168 | const SkPaint* oldPaint = mOps[0]->op->paint; |
| 169 | |
| 170 | if (newPaint == oldPaint) { |
| 171 | // if paints are equal, then modifiers + paint attribs don't need to be compared |
| 172 | return true; |
| 173 | } else if (newPaint && !oldPaint) { |
| 174 | return paintIsDefault(*newPaint); |
| 175 | } else if (!newPaint && oldPaint) { |
| 176 | return paintIsDefault(*oldPaint); |
| 177 | } |
| 178 | return paintsAreEquivalent(*newPaint, *oldPaint); |
| 179 | } |
| 180 | |
| 181 | void mergeOp(BakedOpState* op) { |
| 182 | mBounds.unionWith(op->computedState.clippedBounds); |
| 183 | mOps.push_back(op); |
| 184 | |
| 185 | // Because a new op must have passed canMergeWith(), we know it's passed the clipping compat |
| 186 | // check, and doesn't extend past a side of the clip that's in use by the merged batch. |
| 187 | // Therefore it's safe to simply always merge flags, and use the bounds as the clip rect. |
| 188 | mClipSideFlags |= op->computedState.clipSideFlags; |
| 189 | } |
| 190 | |
| 191 | int getClipSideFlags() const { return mClipSideFlags; } |
| 192 | const Rect& getClipRect() const { return mBounds; } |
| 193 | |
| 194 | private: |
| 195 | int mClipSideFlags; |
| 196 | }; |
| 197 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 198 | LayerBuilder::LayerBuilder(uint32_t width, uint32_t height, const Rect& repaintRect, |
| 199 | const BeginLayerOp* beginLayerOp, RenderNode* renderNode) |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 200 | : width(width) |
| 201 | , height(height) |
| 202 | , repaintRect(repaintRect) |
Chris Craik | 4876de1 | 2016-02-25 16:54:08 -0800 | [diff] [blame] | 203 | , repaintClip(repaintRect) |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 204 | , offscreenBuffer(renderNode ? renderNode->getLayer() : nullptr) |
| 205 | , beginLayerOp(beginLayerOp) |
Chris Craik | 4876de1 | 2016-02-25 16:54:08 -0800 | [diff] [blame] | 206 | , renderNode(renderNode) {} |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 207 | |
| 208 | // iterate back toward target to see if anything drawn since should overlap the new op |
| 209 | // if no target, merging ops still iterate to find similar batch to insert after |
Chris Craik | f158b49 | 2016-01-12 14:45:08 -0800 | [diff] [blame] | 210 | void LayerBuilder::locateInsertIndex(int batchId, const Rect& clippedBounds, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 211 | BatchBase** targetBatch, size_t* insertBatchIndex) const { |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 212 | for (int i = mBatches.size() - 1; i >= 0; i--) { |
| 213 | BatchBase* overBatch = mBatches[i]; |
| 214 | |
| 215 | if (overBatch == *targetBatch) break; |
| 216 | |
| 217 | // TODO: also consider shader shared between batch types |
| 218 | if (batchId == overBatch->getBatchId()) { |
| 219 | *insertBatchIndex = i + 1; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 220 | if (!*targetBatch) break; // found insert position, quit |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | if (overBatch->intersects(clippedBounds)) { |
| 224 | // NOTE: it may be possible to optimize for special cases where two operations |
| 225 | // of the same batch/paint could swap order, such as with a non-mergeable |
| 226 | // (clipped) and a mergeable text operation |
| 227 | *targetBatch = nullptr; |
| 228 | break; |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
Chris Craik | f158b49 | 2016-01-12 14:45:08 -0800 | [diff] [blame] | 233 | void LayerBuilder::deferLayerClear(const Rect& rect) { |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 234 | mClearRects.push_back(rect); |
| 235 | } |
| 236 | |
Chris Craik | 80d2ade | 2016-03-28 12:54:07 -0700 | [diff] [blame] | 237 | void LayerBuilder::onDeferOp(LinearAllocator& allocator, const BakedOpState* bakedState) { |
| 238 | if (bakedState->op->opId != RecordedOpId::CopyToLayerOp) { |
| 239 | // First non-CopyToLayer, so stop stashing up layer clears for unclipped save layers, |
| 240 | // and issue them together in one draw. |
| 241 | flushLayerClears(allocator); |
| 242 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 243 | if (CC_UNLIKELY(activeUnclippedSaveLayers.empty() && |
| 244 | bakedState->computedState.opaqueOverClippedBounds && |
| 245 | bakedState->computedState.clippedBounds.contains(repaintRect) && |
| 246 | !Properties::debugOverdraw)) { |
Chris Craik | 80d2ade | 2016-03-28 12:54:07 -0700 | [diff] [blame] | 247 | // discard all deferred drawing ops, since new one will occlude them |
| 248 | clear(); |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
Chris Craik | f158b49 | 2016-01-12 14:45:08 -0800 | [diff] [blame] | 253 | void LayerBuilder::flushLayerClears(LinearAllocator& allocator) { |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 254 | if (CC_UNLIKELY(!mClearRects.empty())) { |
| 255 | const int vertCount = mClearRects.size() * 4; |
| 256 | // put the verts in the frame allocator, since |
| 257 | // 1) SimpleRectsOps needs verts, not rects |
| 258 | // 2) even if mClearRects stored verts, std::vectors will move their contents |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 259 | Vertex* const verts = (Vertex*)allocator.create_trivial_array<Vertex>(vertCount); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 260 | |
| 261 | Vertex* currentVert = verts; |
| 262 | Rect bounds = mClearRects[0]; |
| 263 | for (auto&& rect : mClearRects) { |
| 264 | bounds.unionWith(rect); |
| 265 | Vertex::set(currentVert++, rect.left, rect.top); |
| 266 | Vertex::set(currentVert++, rect.right, rect.top); |
| 267 | Vertex::set(currentVert++, rect.left, rect.bottom); |
| 268 | Vertex::set(currentVert++, rect.right, rect.bottom); |
| 269 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 270 | mClearRects.clear(); // discard rects before drawing so this method isn't reentrant |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 271 | |
| 272 | // One or more unclipped saveLayers have been enqueued, with deferred clears. |
| 273 | // Flush all of these clears with a single draw |
| 274 | SkPaint* paint = allocator.create<SkPaint>(); |
Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 275 | paint->setBlendMode(SkBlendMode::kClear); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 276 | SimpleRectsOp* op = allocator.create_trivial<SimpleRectsOp>( |
| 277 | bounds, Matrix4::identity(), nullptr, paint, verts, vertCount); |
| 278 | BakedOpState* bakedState = |
| 279 | BakedOpState::directConstruct(allocator, &repaintClip, bounds, *op); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 280 | deferUnmergeableOp(allocator, bakedState, OpBatchType::Vertices); |
| 281 | } |
| 282 | } |
| 283 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 284 | void LayerBuilder::deferUnmergeableOp(LinearAllocator& allocator, BakedOpState* op, |
| 285 | batchid_t batchId) { |
Chris Craik | 80d2ade | 2016-03-28 12:54:07 -0700 | [diff] [blame] | 286 | onDeferOp(allocator, op); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 287 | OpBatch* targetBatch = mBatchLookup[batchId]; |
| 288 | |
| 289 | size_t insertBatchIndex = mBatches.size(); |
| 290 | if (targetBatch) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 291 | locateInsertIndex(batchId, op->computedState.clippedBounds, (BatchBase**)(&targetBatch), |
| 292 | &insertBatchIndex); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | if (targetBatch) { |
| 296 | targetBatch->batchOp(op); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 297 | } else { |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 298 | // new non-merging batch |
John Reck | 7df9ff2 | 2016-02-10 16:08:08 -0800 | [diff] [blame] | 299 | targetBatch = allocator.create<OpBatch>(batchId, op); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 300 | mBatchLookup[batchId] = targetBatch; |
| 301 | mBatches.insert(mBatches.begin() + insertBatchIndex, targetBatch); |
| 302 | } |
| 303 | } |
| 304 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 305 | void LayerBuilder::deferMergeableOp(LinearAllocator& allocator, BakedOpState* op, batchid_t batchId, |
| 306 | mergeid_t mergeId) { |
Chris Craik | 80d2ade | 2016-03-28 12:54:07 -0700 | [diff] [blame] | 307 | onDeferOp(allocator, op); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 308 | MergingOpBatch* targetBatch = nullptr; |
| 309 | |
| 310 | // Try to merge with any existing batch with same mergeId |
| 311 | auto getResult = mMergingBatchLookup[batchId].find(mergeId); |
| 312 | if (getResult != mMergingBatchLookup[batchId].end()) { |
| 313 | targetBatch = getResult->second; |
| 314 | if (!targetBatch->canMergeWith(op)) { |
| 315 | targetBatch = nullptr; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | size_t insertBatchIndex = mBatches.size(); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 320 | locateInsertIndex(batchId, op->computedState.clippedBounds, (BatchBase**)(&targetBatch), |
| 321 | &insertBatchIndex); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 322 | |
| 323 | if (targetBatch) { |
| 324 | targetBatch->mergeOp(op); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 325 | } else { |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 326 | // new merging batch |
John Reck | 7df9ff2 | 2016-02-10 16:08:08 -0800 | [diff] [blame] | 327 | targetBatch = allocator.create<MergingOpBatch>(batchId, op); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 328 | mMergingBatchLookup[batchId].insert(std::make_pair(mergeId, targetBatch)); |
| 329 | |
| 330 | mBatches.insert(mBatches.begin() + insertBatchIndex, targetBatch); |
| 331 | } |
| 332 | } |
| 333 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 334 | void LayerBuilder::replayBakedOpsImpl(void* arg, BakedOpReceiver* unmergedReceivers, |
| 335 | MergedOpReceiver* mergedReceivers) const { |
Chris Craik | aff230f | 2016-05-04 16:27:28 -0700 | [diff] [blame] | 336 | if (renderNode) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 337 | ATRACE_FORMAT_BEGIN("Issue HW Layer DisplayList %s %ux%u", renderNode->getName(), width, |
| 338 | height); |
Chris Craik | aff230f | 2016-05-04 16:27:28 -0700 | [diff] [blame] | 339 | } else { |
| 340 | ATRACE_BEGIN("flush drawing commands"); |
| 341 | } |
| 342 | |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 343 | for (const BatchBase* batch : mBatches) { |
| 344 | size_t size = batch->getOps().size(); |
| 345 | if (size > 1 && batch->isMerging()) { |
| 346 | int opId = batch->getOps()[0]->op->opId; |
| 347 | const MergingOpBatch* mergingBatch = static_cast<const MergingOpBatch*>(batch); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 348 | MergedBakedOpList data = {batch->getOps().data(), size, |
| 349 | mergingBatch->getClipSideFlags(), |
| 350 | mergingBatch->getClipRect()}; |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 351 | mergedReceivers[opId](arg, data); |
| 352 | } else { |
| 353 | for (const BakedOpState* op : batch->getOps()) { |
| 354 | unmergedReceivers[op->op->opId](arg, *op); |
| 355 | } |
| 356 | } |
| 357 | } |
Chris Craik | aff230f | 2016-05-04 16:27:28 -0700 | [diff] [blame] | 358 | ATRACE_END(); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 359 | } |
| 360 | |
Chris Craik | 80d2ade | 2016-03-28 12:54:07 -0700 | [diff] [blame] | 361 | void LayerBuilder::clear() { |
| 362 | mBatches.clear(); |
| 363 | for (int i = 0; i < OpBatchType::Count; i++) { |
| 364 | mBatchLookup[i] = nullptr; |
| 365 | mMergingBatchLookup[i].clear(); |
| 366 | } |
| 367 | } |
| 368 | |
Chris Craik | f158b49 | 2016-01-12 14:45:08 -0800 | [diff] [blame] | 369 | void LayerBuilder::dump() const { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 370 | ALOGD("LayerBuilder %p, %ux%u buffer %p, blo %p, rn %p (%s)", this, width, height, |
| 371 | offscreenBuffer, beginLayerOp, renderNode, renderNode ? renderNode->getName() : "-"); |
Chris Craik | 5ea1724 | 2016-01-11 14:07:59 -0800 | [diff] [blame] | 372 | for (const BatchBase* batch : mBatches) { |
| 373 | batch->dump(); |
| 374 | } |
| 375 | } |
| 376 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 377 | } // namespace uirenderer |
| 378 | } // namespace android |