Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | #define LOG_TAG "OpenGLRenderer" |
| 18 | #define ATRACE_TAG ATRACE_TAG_VIEW |
| 19 | |
Romain Guy | c46d07a | 2013-03-15 19:06:39 -0700 | [diff] [blame] | 20 | #include <SkCanvas.h> |
| 21 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 22 | #include <utils/Trace.h> |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 23 | #include <ui/Rect.h> |
| 24 | #include <ui/Region.h> |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 25 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 26 | #include "Caches.h" |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 27 | #include "Debug.h" |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 28 | #include "DeferredDisplayList.h" |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 29 | #include "DisplayListOp.h" |
| 30 | #include "OpenGLRenderer.h" |
| 31 | |
| 32 | #if DEBUG_DEFER |
| 33 | #define DEFER_LOGD(...) ALOGD(__VA_ARGS__) |
| 34 | #else |
| 35 | #define DEFER_LOGD(...) |
| 36 | #endif |
| 37 | |
| 38 | namespace android { |
| 39 | namespace uirenderer { |
| 40 | |
Chris Craik | 1ed30c9 | 2013-04-03 12:37:35 -0700 | [diff] [blame] | 41 | // Depth of the save stack at the beginning of batch playback at flush time |
| 42 | #define FLUSH_SAVE_STACK_DEPTH 2 |
| 43 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 44 | #define DEBUG_COLOR_BARRIER 0x1f000000 |
| 45 | #define DEBUG_COLOR_MERGEDBATCH 0x5f7f7fff |
| 46 | #define DEBUG_COLOR_MERGEDBATCH_SOLO 0x5f7fff7f |
| 47 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 48 | ///////////////////////////////////////////////////////////////////////////////// |
| 49 | // Operation Batches |
| 50 | ///////////////////////////////////////////////////////////////////////////////// |
| 51 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 52 | class Batch { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 53 | public: |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 54 | virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int index) = 0; |
| 55 | virtual ~Batch() {} |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 56 | virtual bool purelyDrawBatch() { return false; } |
| 57 | virtual bool coversBounds(const Rect& bounds) { return false; } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 58 | }; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 59 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 60 | class DrawBatch : public Batch { |
| 61 | public: |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 62 | DrawBatch(const DeferInfo& deferInfo) : mAllOpsOpaque(true), |
| 63 | mBatchId(deferInfo.batchId), mMergeId(deferInfo.mergeId) { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 64 | mOps.clear(); |
| 65 | } |
| 66 | |
| 67 | virtual ~DrawBatch() { mOps.clear(); } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 68 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 69 | virtual void add(DrawOp* op, bool opaqueOverBounds) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 70 | // NOTE: ignore empty bounds special case, since we don't merge across those ops |
| 71 | mBounds.unionWith(op->state.mBounds); |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 72 | mAllOpsOpaque &= opaqueOverBounds; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 73 | mOps.add(op); |
| 74 | } |
| 75 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 76 | bool intersects(Rect& rect) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 77 | if (!rect.intersects(mBounds)) return false; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 78 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 79 | for (unsigned int i = 0; i < mOps.size(); i++) { |
| 80 | if (rect.intersects(mOps[i]->state.mBounds)) { |
| 81 | #if DEBUG_DEFER |
| 82 | DEFER_LOGD("op intersects with op %p with bounds %f %f %f %f:", mOps[i], |
| 83 | mOps[i]->state.mBounds.left, mOps[i]->state.mBounds.top, |
| 84 | mOps[i]->state.mBounds.right, mOps[i]->state.mBounds.bottom); |
| 85 | mOps[i]->output(2); |
| 86 | #endif |
| 87 | return true; |
| 88 | } |
| 89 | } |
| 90 | return false; |
| 91 | } |
| 92 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 93 | virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int index) { |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 94 | DEFER_LOGD("%d replaying DrawBatch %p, with %d ops (batch id %x, merge id %p)", |
| 95 | index, this, mOps.size(), getBatchId(), getMergeId()); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 96 | |
| 97 | status_t status = DrawGlInfo::kStatusDone; |
| 98 | DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance(); |
| 99 | for (unsigned int i = 0; i < mOps.size(); i++) { |
| 100 | DrawOp* op = mOps[i]; |
| 101 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 102 | renderer.restoreDisplayState(op->state); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 103 | |
| 104 | #if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 105 | renderer.eventMark(op->name()); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 106 | #endif |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 107 | logBuffer.writeCommand(0, op->name()); |
Chris Craik | d4b43b3 | 2013-05-09 13:07:52 -0700 | [diff] [blame] | 108 | status |= op->applyDraw(renderer, dirty); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 109 | |
| 110 | #if DEBUG_MERGE_BEHAVIOR |
| 111 | Rect& bounds = mOps[i]->state.mBounds; |
| 112 | int batchColor = 0x1f000000; |
| 113 | if (getBatchId() & 0x1) batchColor |= 0x0000ff; |
| 114 | if (getBatchId() & 0x2) batchColor |= 0x00ff00; |
| 115 | if (getBatchId() & 0x4) batchColor |= 0xff0000; |
| 116 | renderer.drawScreenSpaceColorRect(bounds.left, bounds.top, bounds.right, bounds.bottom, |
| 117 | batchColor); |
| 118 | #endif |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 119 | } |
| 120 | return status; |
| 121 | } |
| 122 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 123 | virtual bool purelyDrawBatch() { return true; } |
| 124 | |
| 125 | virtual bool coversBounds(const Rect& bounds) { |
| 126 | if (CC_LIKELY(!mAllOpsOpaque || !mBounds.contains(bounds) || count() == 1)) return false; |
| 127 | |
| 128 | Region uncovered(android::Rect(bounds.left, bounds.top, bounds.right, bounds.bottom)); |
| 129 | for (unsigned int i = 0; i < mOps.size(); i++) { |
| 130 | Rect &r = mOps[i]->state.mBounds; |
| 131 | uncovered.subtractSelf(android::Rect(r.left, r.top, r.right, r.bottom)); |
| 132 | } |
| 133 | return uncovered.isEmpty(); |
| 134 | } |
| 135 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 136 | inline int getBatchId() const { return mBatchId; } |
| 137 | inline mergeid_t getMergeId() const { return mMergeId; } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 138 | inline int count() const { return mOps.size(); } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 139 | |
| 140 | protected: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 141 | Vector<DrawOp*> mOps; |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 142 | Rect mBounds; // union of bounds of contained ops |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 143 | private: |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 144 | bool mAllOpsOpaque; |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 145 | int mBatchId; |
| 146 | mergeid_t mMergeId; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 147 | }; |
| 148 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 149 | // compare alphas approximately, with a small margin |
| 150 | #define NEQ_FALPHA(lhs, rhs) \ |
| 151 | fabs((float)lhs - (float)rhs) > 0.001f |
| 152 | |
| 153 | class MergingDrawBatch : public DrawBatch { |
| 154 | public: |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 155 | MergingDrawBatch(DeferInfo& deferInfo, Rect viewport) : |
| 156 | DrawBatch(deferInfo), mClipRect(viewport), mClipSideFlags(kClipSide_Unclipped) {} |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | * Checks if a (mergeable) op can be merged into this batch |
| 160 | * |
| 161 | * If true, the op's multiDraw must be guaranteed to handle both ops simultaneously, so it is |
| 162 | * important to consider all paint attributes used in the draw calls in deciding both a) if an |
| 163 | * op tries to merge at all, and b) if the op |
| 164 | * |
| 165 | * False positives can lead to information from the paints of subsequent merged operations being |
| 166 | * dropped, so we make simplifying qualifications on the ops that can merge, per op type. |
| 167 | */ |
| 168 | bool canMergeWith(DrawOp* op) { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 169 | bool isTextBatch = getBatchId() == DeferredDisplayList::kOpBatch_Text || |
| 170 | getBatchId() == DeferredDisplayList::kOpBatch_ColorText; |
| 171 | |
| 172 | // Overlapping other operations is only allowed for text without shadow. For other ops, |
| 173 | // multiDraw isn't guaranteed to overdraw correctly |
| 174 | if (!isTextBatch || op->state.mDrawModifiers.mHasShadow) { |
| 175 | if (intersects(op->state.mBounds)) return false; |
| 176 | } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 177 | const DeferredDisplayState& lhs = op->state; |
| 178 | const DeferredDisplayState& rhs = mOps[0]->state; |
| 179 | |
| 180 | if (NEQ_FALPHA(lhs.mAlpha, rhs.mAlpha)) return false; |
| 181 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 182 | // If colliding flags, ensure bounds are equal |
| 183 | // NOTE: only needed if op to be added is clipped *and* within old valid clip (per dimension) |
| 184 | int collidingClipSideFlags = mClipSideFlags & op->state.mClipSideFlags; |
| 185 | if (CC_UNLIKELY(collidingClipSideFlags)) { |
| 186 | // if multiple ops are clipped on the same side, they must be clipped at the same |
| 187 | // coordinate to be merged |
| 188 | if ((collidingClipSideFlags & kClipSide_Left) && |
| 189 | mClipRect.left != op->state.mClip.left) return false; |
| 190 | if ((collidingClipSideFlags & kClipSide_Top) && |
| 191 | mClipRect.top != op->state.mClip.top) return false; |
| 192 | if ((collidingClipSideFlags & kClipSide_Right) && |
| 193 | mClipRect.right != op->state.mClip.right) return false; |
| 194 | if ((collidingClipSideFlags & kClipSide_Bottom) && |
| 195 | mClipRect.bottom != op->state.mClip.bottom) return false; |
| 196 | } |
| 197 | // if op is outside of batch clip rect, it can't share its clip |
| 198 | if (!mClipRect.contains(op->state.mBounds)) return false; |
| 199 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 200 | // if paints are equal, then modifiers + paint attribs don't need to be compared |
| 201 | if (op->mPaint == mOps[0]->mPaint) return true; |
| 202 | |
| 203 | if (op->getPaintAlpha() != mOps[0]->getPaintAlpha()) return false; |
| 204 | |
| 205 | /* Draw Modifiers compatibility check |
| 206 | * |
| 207 | * Shadows are ignored, as only text uses them, and in that case they are drawn |
| 208 | * per-DrawTextOp, before the unified text draw. Because of this, it's always safe to merge |
| 209 | * text UNLESS a later draw's shadow should overlays a previous draw's text. This is covered |
| 210 | * above with the intersection check. |
| 211 | * |
| 212 | * OverrideLayerAlpha is also ignored, as it's only used for drawing layers, which are never |
| 213 | * merged. |
| 214 | * |
| 215 | * These ignore cases prevent us from simply memcmp'ing the drawModifiers |
| 216 | */ |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 217 | const DrawModifiers& lhsMod = lhs.mDrawModifiers; |
| 218 | const DrawModifiers& rhsMod = rhs.mDrawModifiers; |
| 219 | if (lhsMod.mShader != rhsMod.mShader) return false; |
| 220 | if (lhsMod.mColorFilter != rhsMod.mColorFilter) return false; |
| 221 | |
| 222 | // Draw filter testing expects bit fields to be clear if filter not set. |
| 223 | if (lhsMod.mHasDrawFilter != rhsMod.mHasDrawFilter) return false; |
| 224 | if (lhsMod.mPaintFilterClearBits != rhsMod.mPaintFilterClearBits) return false; |
| 225 | if (lhsMod.mPaintFilterSetBits != rhsMod.mPaintFilterSetBits) return false; |
| 226 | |
| 227 | return true; |
| 228 | } |
| 229 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 230 | virtual void add(DrawOp* op, bool opaqueOverBounds) { |
| 231 | DrawBatch::add(op, opaqueOverBounds); |
| 232 | |
| 233 | const int newClipSideFlags = op->state.mClipSideFlags; |
| 234 | mClipSideFlags |= newClipSideFlags; |
| 235 | if (newClipSideFlags & kClipSide_Left) mClipRect.left = op->state.mClip.left; |
| 236 | if (newClipSideFlags & kClipSide_Top) mClipRect.top = op->state.mClip.top; |
| 237 | if (newClipSideFlags & kClipSide_Right) mClipRect.right = op->state.mClip.right; |
| 238 | if (newClipSideFlags & kClipSide_Bottom) mClipRect.bottom = op->state.mClip.bottom; |
| 239 | } |
| 240 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 241 | virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int index) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 242 | DEFER_LOGD("%d replaying MergingDrawBatch %p, with %d ops," |
| 243 | " clip flags %x (batch id %x, merge id %p)", |
| 244 | index, this, mOps.size(), mClipSideFlags, getBatchId(), getMergeId()); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 245 | if (mOps.size() == 1) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 246 | return DrawBatch::replay(renderer, dirty, -1); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 249 | // clipping in the merged case is done ahead of time since all ops share the clip (if any) |
| 250 | renderer.setupMergedMultiDraw(mClipSideFlags ? &mClipRect : NULL); |
| 251 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 252 | DrawOp* op = mOps[0]; |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 253 | DisplayListLogBuffer& buffer = DisplayListLogBuffer::getInstance(); |
| 254 | buffer.writeCommand(0, "multiDraw"); |
| 255 | buffer.writeCommand(1, op->name()); |
Chris Craik | d4b43b3 | 2013-05-09 13:07:52 -0700 | [diff] [blame] | 256 | status_t status = op->multiDraw(renderer, dirty, mOps, mBounds); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 257 | |
| 258 | #if DEBUG_MERGE_BEHAVIOR |
| 259 | renderer.drawScreenSpaceColorRect(mBounds.left, mBounds.top, mBounds.right, mBounds.bottom, |
| 260 | DEBUG_COLOR_MERGEDBATCH); |
| 261 | #endif |
| 262 | return status; |
| 263 | } |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 264 | |
| 265 | private: |
| 266 | /* |
| 267 | * Contains the effective clip rect shared by all merged ops. Initialized to the layer viewport, |
| 268 | * it will shrink if an op must be clipped on a certain side. The clipped sides are reflected in |
| 269 | * mClipSideFlags. |
| 270 | */ |
| 271 | Rect mClipRect; |
| 272 | int mClipSideFlags; |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | class StateOpBatch : public Batch { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 276 | public: |
| 277 | // creates a single operation batch |
| 278 | StateOpBatch(StateOp* op) : mOp(op) {} |
| 279 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 280 | virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int index) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 281 | DEFER_LOGD("replaying state op batch %p", this); |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 282 | renderer.restoreDisplayState(mOp->state); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 283 | |
| 284 | // use invalid save count because it won't be used at flush time - RestoreToCountOp is the |
| 285 | // only one to use it, and we don't use that class at flush time, instead calling |
| 286 | // renderer.restoreToCount directly |
| 287 | int saveCount = -1; |
| 288 | mOp->applyState(renderer, saveCount); |
| 289 | return DrawGlInfo::kStatusDone; |
| 290 | } |
| 291 | |
| 292 | private: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 293 | const StateOp* mOp; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 294 | }; |
| 295 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 296 | class RestoreToCountBatch : public Batch { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 297 | public: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 298 | RestoreToCountBatch(StateOp* op, int restoreCount) : mOp(op), mRestoreCount(restoreCount) {} |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 299 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 300 | virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int index) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 301 | DEFER_LOGD("batch %p restoring to count %d", this, mRestoreCount); |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 302 | |
| 303 | renderer.restoreDisplayState(mOp->state); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 304 | renderer.restoreToCount(mRestoreCount); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 305 | return DrawGlInfo::kStatusDone; |
| 306 | } |
| 307 | |
| 308 | private: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 309 | // we use the state storage for the RestoreToCountOp, but don't replay the op itself |
| 310 | const StateOp* mOp; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 311 | /* |
| 312 | * The count used here represents the flush() time saveCount. This is as opposed to the |
| 313 | * DisplayList record time, or defer() time values (which are RestoreToCountOp's mCount, and |
| 314 | * (saveCount + mCount) respectively). Since the count is different from the original |
| 315 | * RestoreToCountOp, we don't store a pointer to the op, as elsewhere. |
| 316 | */ |
| 317 | const int mRestoreCount; |
| 318 | }; |
| 319 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 320 | #if DEBUG_MERGE_BEHAVIOR |
| 321 | class BarrierDebugBatch : public Batch { |
| 322 | virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int index) { |
| 323 | renderer.drawScreenSpaceColorRect(0, 0, 10000, 10000, DEBUG_COLOR_BARRIER); |
| 324 | return DrawGlInfo::kStatusDrew; |
| 325 | } |
| 326 | }; |
| 327 | #endif |
| 328 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 329 | ///////////////////////////////////////////////////////////////////////////////// |
| 330 | // DeferredDisplayList |
| 331 | ///////////////////////////////////////////////////////////////////////////////// |
| 332 | |
| 333 | void DeferredDisplayList::resetBatchingState() { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 334 | for (int i = 0; i < kOpBatch_Count; i++) { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 335 | mBatchLookup[i] = NULL; |
| 336 | mMergingBatches[i].clear(); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 337 | } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 338 | #if DEBUG_MERGE_BEHAVIOR |
| 339 | if (mBatches.size() != 0) { |
| 340 | mBatches.add(new BarrierDebugBatch()); |
| 341 | } |
| 342 | #endif |
| 343 | mEarliestBatchIndex = mBatches.size(); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | void DeferredDisplayList::clear() { |
| 347 | resetBatchingState(); |
| 348 | mComplexClipStackStart = -1; |
| 349 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 350 | for (unsigned int i = 0; i < mBatches.size(); i++) { |
| 351 | delete mBatches[i]; |
| 352 | } |
| 353 | mBatches.clear(); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 354 | mSaveStack.clear(); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 355 | mEarliestBatchIndex = 0; |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 356 | mEarliestUnclearedIndex = 0; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 359 | ///////////////////////////////////////////////////////////////////////////////// |
| 360 | // Operation adding |
| 361 | ///////////////////////////////////////////////////////////////////////////////// |
| 362 | |
| 363 | int DeferredDisplayList::getStateOpDeferFlags() const { |
| 364 | // For both clipOp and save(Layer)Op, we don't want to save drawing info, and only want to save |
| 365 | // the clip if we aren't recording a complex clip (and can thus trust it to be a rect) |
| 366 | return recordingComplexClip() ? 0 : kStateDeferFlag_Clip; |
| 367 | } |
| 368 | |
| 369 | int DeferredDisplayList::getDrawOpDeferFlags() const { |
| 370 | return kStateDeferFlag_Draw | getStateOpDeferFlags(); |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * When an clipping operation occurs that could cause a complex clip, record the operation and all |
| 375 | * subsequent clipOps, save/restores (if the clip flag is set). During a flush, instead of loading |
| 376 | * the clip from deferred state, we play back all of the relevant state operations that generated |
| 377 | * the complex clip. |
| 378 | * |
| 379 | * Note that we don't need to record the associated restore operation, since operations at defer |
| 380 | * time record whether they should store the renderer's current clip |
| 381 | */ |
| 382 | void DeferredDisplayList::addClip(OpenGLRenderer& renderer, ClipOp* op) { |
| 383 | if (recordingComplexClip() || op->canCauseComplexClip() || !renderer.hasRectToRectTransform()) { |
| 384 | DEFER_LOGD("%p Received complex clip operation %p", this, op); |
| 385 | |
| 386 | // NOTE: defer clip op before setting mComplexClipStackStart so previous clip is recorded |
| 387 | storeStateOpBarrier(renderer, op); |
| 388 | |
| 389 | if (!recordingComplexClip()) { |
| 390 | mComplexClipStackStart = renderer.getSaveCount() - 1; |
| 391 | DEFER_LOGD(" Starting complex clip region, start is %d", mComplexClipStackStart); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 392 | } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * For now, we record save layer operations as barriers in the batch list, preventing drawing |
| 398 | * operations from reordering around the saveLayer and it's associated restore() |
| 399 | * |
| 400 | * In the future, we should send saveLayer commands (if they can be played out of order) and their |
| 401 | * contained drawing operations to a seperate list of batches, so that they may draw at the |
| 402 | * beginning of the frame. This would avoid targetting and removing an FBO in the middle of a frame. |
| 403 | * |
| 404 | * saveLayer operations should be pulled to the beginning of the frame if the canvas doesn't have a |
| 405 | * complex clip, and if the flags (kClip_SaveFlag & kClipToLayer_SaveFlag) are set. |
| 406 | */ |
| 407 | void DeferredDisplayList::addSaveLayer(OpenGLRenderer& renderer, |
| 408 | SaveLayerOp* op, int newSaveCount) { |
| 409 | DEFER_LOGD("%p adding saveLayerOp %p, flags %x, new count %d", |
| 410 | this, op, op->getFlags(), newSaveCount); |
| 411 | |
| 412 | storeStateOpBarrier(renderer, op); |
| 413 | mSaveStack.push(newSaveCount); |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Takes save op and it's return value - the new save count - and stores it into the stream as a |
| 418 | * barrier if it's needed to properly modify a complex clip |
| 419 | */ |
| 420 | void DeferredDisplayList::addSave(OpenGLRenderer& renderer, SaveOp* op, int newSaveCount) { |
| 421 | int saveFlags = op->getFlags(); |
| 422 | DEFER_LOGD("%p adding saveOp %p, flags %x, new count %d", this, op, saveFlags, newSaveCount); |
| 423 | |
| 424 | if (recordingComplexClip() && (saveFlags & SkCanvas::kClip_SaveFlag)) { |
| 425 | // store and replay the save operation, as it may be needed to correctly playback the clip |
| 426 | DEFER_LOGD(" adding save barrier with new save count %d", newSaveCount); |
| 427 | storeStateOpBarrier(renderer, op); |
| 428 | mSaveStack.push(newSaveCount); |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * saveLayer() commands must be associated with a restoreToCount batch that will clean up and draw |
| 434 | * the layer in the deferred list |
| 435 | * |
| 436 | * other save() commands which occur as children of a snapshot with complex clip will be deferred, |
| 437 | * and must be restored |
| 438 | * |
| 439 | * Either will act as a barrier to draw operation reordering, as we want to play back layer |
| 440 | * save/restore and complex canvas modifications (including save/restore) in order. |
| 441 | */ |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 442 | void DeferredDisplayList::addRestoreToCount(OpenGLRenderer& renderer, StateOp* op, |
| 443 | int newSaveCount) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 444 | DEFER_LOGD("%p addRestoreToCount %d", this, newSaveCount); |
| 445 | |
| 446 | if (recordingComplexClip() && newSaveCount <= mComplexClipStackStart) { |
| 447 | mComplexClipStackStart = -1; |
| 448 | resetBatchingState(); |
| 449 | } |
| 450 | |
| 451 | if (mSaveStack.isEmpty() || newSaveCount > mSaveStack.top()) { |
| 452 | return; |
| 453 | } |
| 454 | |
| 455 | while (!mSaveStack.isEmpty() && mSaveStack.top() >= newSaveCount) mSaveStack.pop(); |
| 456 | |
Chris Craik | 1ed30c9 | 2013-04-03 12:37:35 -0700 | [diff] [blame] | 457 | storeRestoreToCountBarrier(renderer, op, mSaveStack.size() + FLUSH_SAVE_STACK_DEPTH); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | void DeferredDisplayList::addDrawOp(OpenGLRenderer& renderer, DrawOp* op) { |
| 461 | if (renderer.storeDisplayState(op->state, getDrawOpDeferFlags())) { |
| 462 | return; // quick rejected |
| 463 | } |
| 464 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 465 | DeferInfo deferInfo; |
| 466 | op->onDefer(renderer, deferInfo); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 467 | |
| 468 | // complex clip has a complex set of expectations on the renderer state - for now, avoid taking |
| 469 | // the merge path in those cases |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 470 | deferInfo.mergeable &= !recordingComplexClip(); |
| 471 | |
| 472 | if (CC_LIKELY(mAvoidOverdraw) && mBatches.size() && |
| 473 | deferInfo.opaqueOverBounds && op->state.mBounds.contains(mBounds)) { |
Chris Craik | f70119c | 2013-06-13 11:21:22 -0700 | [diff] [blame^] | 474 | // avoid overdraw by resetting drawing state + discarding drawing ops |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 475 | discardDrawingBatches(mBatches.size() - 1); |
Chris Craik | f70119c | 2013-06-13 11:21:22 -0700 | [diff] [blame^] | 476 | resetBatchingState(); |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 477 | } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 478 | |
| 479 | if (CC_UNLIKELY(renderer.getCaches().drawReorderDisabled)) { |
| 480 | // TODO: elegant way to reuse batches? |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 481 | DrawBatch* b = new DrawBatch(deferInfo); |
| 482 | b->add(op, deferInfo.opaqueOverBounds); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 483 | mBatches.add(b); |
| 484 | return; |
| 485 | } |
| 486 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 487 | // find the latest batch of the new op's type, and try to merge the new op into it |
| 488 | DrawBatch* targetBatch = NULL; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 489 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 490 | // insertion point of a new batch, will hopefully be immediately after similar batch |
| 491 | // (eventually, should be similar shader) |
| 492 | int insertBatchIndex = mBatches.size(); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 493 | if (!mBatches.isEmpty()) { |
| 494 | if (op->state.mBounds.isEmpty()) { |
| 495 | // don't know the bounds for op, so add to last batch and start from scratch on next op |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 496 | DrawBatch* b = new DrawBatch(deferInfo); |
| 497 | b->add(op, deferInfo.opaqueOverBounds); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 498 | mBatches.add(b); |
| 499 | resetBatchingState(); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 500 | #if DEBUG_DEFER |
| 501 | DEFER_LOGD("Warning: Encountered op with empty bounds, resetting batches"); |
| 502 | op->output(2); |
| 503 | #endif |
| 504 | return; |
| 505 | } |
| 506 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 507 | if (deferInfo.mergeable) { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 508 | // Try to merge with any existing batch with same mergeId. |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 509 | if (mMergingBatches[deferInfo.batchId].get(deferInfo.mergeId, targetBatch)) { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 510 | if (!((MergingDrawBatch*) targetBatch)->canMergeWith(op)) { |
| 511 | targetBatch = NULL; |
| 512 | } |
| 513 | } |
| 514 | } else { |
| 515 | // join with similar, non-merging batch |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 516 | targetBatch = (DrawBatch*)mBatchLookup[deferInfo.batchId]; |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 517 | } |
| 518 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 519 | if (targetBatch || deferInfo.mergeable) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 520 | // iterate back toward target to see if anything drawn since should overlap the new op |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 521 | // if no target, merging ops still interate to find similar batch to insert after |
| 522 | for (int i = mBatches.size() - 1; i >= mEarliestBatchIndex; i--) { |
| 523 | DrawBatch* overBatch = (DrawBatch*)mBatches[i]; |
| 524 | |
| 525 | if (overBatch == targetBatch) break; |
| 526 | |
| 527 | // TODO: also consider shader shared between batch types |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 528 | if (deferInfo.batchId == overBatch->getBatchId()) { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 529 | insertBatchIndex = i + 1; |
| 530 | if (!targetBatch) break; // found insert position, quit |
| 531 | } |
| 532 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 533 | if (overBatch->intersects(op->state.mBounds)) { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 534 | // NOTE: it may be possible to optimize for special cases where two operations |
| 535 | // of the same batch/paint could swap order, such as with a non-mergeable |
| 536 | // (clipped) and a mergeable text operation |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 537 | targetBatch = NULL; |
| 538 | #if DEBUG_DEFER |
| 539 | DEFER_LOGD("op couldn't join batch %d, was intersected by batch %d", |
| 540 | targetIndex, i); |
| 541 | op->output(2); |
| 542 | #endif |
| 543 | break; |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 548 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 549 | if (!targetBatch) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 550 | if (deferInfo.mergeable) { |
| 551 | targetBatch = new MergingDrawBatch(deferInfo, mBounds); |
| 552 | mMergingBatches[deferInfo.batchId].put(deferInfo.mergeId, targetBatch); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 553 | } else { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 554 | targetBatch = new DrawBatch(deferInfo); |
| 555 | mBatchLookup[deferInfo.batchId] = targetBatch; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 556 | } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 557 | |
Chris Craik | f70119c | 2013-06-13 11:21:22 -0700 | [diff] [blame^] | 558 | DEFER_LOGD("creating %singBatch %p, bid %x, at %d", |
| 559 | deferInfo.mergeable ? "Merg" : "Draw", |
| 560 | targetBatch, deferInfo.batchId, insertBatchIndex); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 561 | mBatches.insertAt(targetBatch, insertBatchIndex); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 562 | } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 563 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 564 | targetBatch->add(op, deferInfo.opaqueOverBounds); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 565 | } |
| 566 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 567 | void DeferredDisplayList::storeStateOpBarrier(OpenGLRenderer& renderer, StateOp* op) { |
| 568 | DEFER_LOGD("%p adding state op barrier at pos %d", this, mBatches.size()); |
| 569 | |
| 570 | renderer.storeDisplayState(op->state, getStateOpDeferFlags()); |
| 571 | mBatches.add(new StateOpBatch(op)); |
| 572 | resetBatchingState(); |
| 573 | } |
| 574 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 575 | void DeferredDisplayList::storeRestoreToCountBarrier(OpenGLRenderer& renderer, StateOp* op, |
| 576 | int newSaveCount) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 577 | DEFER_LOGD("%p adding restore to count %d barrier, pos %d", |
| 578 | this, newSaveCount, mBatches.size()); |
| 579 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 580 | // store displayState for the restore operation, as it may be associated with a saveLayer that |
| 581 | // doesn't have kClip_SaveFlag set |
| 582 | renderer.storeDisplayState(op->state, getStateOpDeferFlags()); |
| 583 | mBatches.add(new RestoreToCountBatch(op, newSaveCount)); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 584 | resetBatchingState(); |
| 585 | } |
| 586 | |
| 587 | ///////////////////////////////////////////////////////////////////////////////// |
| 588 | // Replay / flush |
| 589 | ///////////////////////////////////////////////////////////////////////////////// |
| 590 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 591 | static status_t replayBatchList(const Vector<Batch*>& batchList, |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 592 | OpenGLRenderer& renderer, Rect& dirty) { |
| 593 | status_t status = DrawGlInfo::kStatusDone; |
| 594 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 595 | for (unsigned int i = 0; i < batchList.size(); i++) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 596 | if (batchList[i]) { |
| 597 | status |= batchList[i]->replay(renderer, dirty, i); |
| 598 | } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 599 | } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 600 | DEFER_LOGD("--flushed, drew %d batches", batchList.size()); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 601 | return status; |
| 602 | } |
| 603 | |
| 604 | status_t DeferredDisplayList::flush(OpenGLRenderer& renderer, Rect& dirty) { |
| 605 | ATRACE_NAME("flush drawing commands"); |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 606 | Caches::getInstance().fontRenderer->endPrecaching(); |
| 607 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 608 | status_t status = DrawGlInfo::kStatusDone; |
| 609 | |
| 610 | if (isEmpty()) return status; // nothing to flush |
Chris Craik | a4e16c5 | 2013-03-22 10:00:48 -0700 | [diff] [blame] | 611 | renderer.restoreToCount(1); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 612 | |
| 613 | DEFER_LOGD("--flushing"); |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 614 | renderer.eventMark("Flush"); |
| 615 | |
Chris Craik | a4e16c5 | 2013-03-22 10:00:48 -0700 | [diff] [blame] | 616 | // save and restore (with draw modifiers) so that reordering doesn't affect final state |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 617 | DrawModifiers restoreDrawModifiers = renderer.getDrawModifiers(); |
Chris Craik | a4e16c5 | 2013-03-22 10:00:48 -0700 | [diff] [blame] | 618 | renderer.save(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag); |
| 619 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 620 | if (CC_LIKELY(mAvoidOverdraw)) { |
| 621 | for (unsigned int i = 1; i < mBatches.size(); i++) { |
| 622 | if (mBatches[i] && mBatches[i]->coversBounds(mBounds)) { |
| 623 | discardDrawingBatches(i - 1); |
| 624 | } |
| 625 | } |
| 626 | } |
Chris Craik | 1ed30c9 | 2013-04-03 12:37:35 -0700 | [diff] [blame] | 627 | // NOTE: depth of the save stack at this point, before playback, should be reflected in |
| 628 | // FLUSH_SAVE_STACK_DEPTH, so that save/restores match up correctly |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 629 | status |= replayBatchList(mBatches, renderer, dirty); |
Chris Craik | a4e16c5 | 2013-03-22 10:00:48 -0700 | [diff] [blame] | 630 | |
| 631 | renderer.restoreToCount(1); |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 632 | renderer.setDrawModifiers(restoreDrawModifiers); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 633 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 634 | DEFER_LOGD("--flush complete, returning %x", status); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 635 | clear(); |
| 636 | return status; |
| 637 | } |
| 638 | |
Chris Craik | f70119c | 2013-06-13 11:21:22 -0700 | [diff] [blame^] | 639 | void DeferredDisplayList::discardDrawingBatches(const unsigned int maxIndex) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 640 | for (unsigned int i = mEarliestUnclearedIndex; i <= maxIndex; i++) { |
Chris Craik | f70119c | 2013-06-13 11:21:22 -0700 | [diff] [blame^] | 641 | // leave deferred state ops alone for simplicity (empty save restore pairs may now exist) |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 642 | if (mBatches[i] && mBatches[i]->purelyDrawBatch()) { |
| 643 | DrawBatch* b = (DrawBatch*) mBatches[i]; |
| 644 | delete mBatches[i]; |
| 645 | mBatches.replaceAt(NULL, i); |
| 646 | } |
| 647 | } |
| 648 | mEarliestUnclearedIndex = maxIndex + 1; |
| 649 | } |
| 650 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 651 | }; // namespace uirenderer |
| 652 | }; // namespace android |