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> |
| 23 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame^] | 24 | #include "Caches.h" |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 25 | #include "Debug.h" |
| 26 | #include "DisplayListOp.h" |
| 27 | #include "OpenGLRenderer.h" |
| 28 | |
| 29 | #if DEBUG_DEFER |
| 30 | #define DEFER_LOGD(...) ALOGD(__VA_ARGS__) |
| 31 | #else |
| 32 | #define DEFER_LOGD(...) |
| 33 | #endif |
| 34 | |
| 35 | namespace android { |
| 36 | namespace uirenderer { |
| 37 | |
Chris Craik | 1ed30c9 | 2013-04-03 12:37:35 -0700 | [diff] [blame] | 38 | // Depth of the save stack at the beginning of batch playback at flush time |
| 39 | #define FLUSH_SAVE_STACK_DEPTH 2 |
| 40 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 41 | ///////////////////////////////////////////////////////////////////////////////// |
| 42 | // Operation Batches |
| 43 | ///////////////////////////////////////////////////////////////////////////////// |
| 44 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 45 | class DrawOpBatch { |
| 46 | public: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 47 | DrawOpBatch() { mOps.clear(); } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 48 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 49 | virtual ~DrawOpBatch() { mOps.clear(); } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 50 | |
| 51 | void add(DrawOp* op) { |
| 52 | // NOTE: ignore empty bounds special case, since we don't merge across those ops |
| 53 | mBounds.unionWith(op->state.mBounds); |
| 54 | mOps.add(op); |
| 55 | } |
| 56 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 57 | virtual bool intersects(Rect& rect) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 58 | if (!rect.intersects(mBounds)) return false; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 59 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 60 | for (unsigned int i = 0; i < mOps.size(); i++) { |
| 61 | if (rect.intersects(mOps[i]->state.mBounds)) { |
| 62 | #if DEBUG_DEFER |
| 63 | DEFER_LOGD("op intersects with op %p with bounds %f %f %f %f:", mOps[i], |
| 64 | mOps[i]->state.mBounds.left, mOps[i]->state.mBounds.top, |
| 65 | mOps[i]->state.mBounds.right, mOps[i]->state.mBounds.bottom); |
| 66 | mOps[i]->output(2); |
| 67 | #endif |
| 68 | return true; |
| 69 | } |
| 70 | } |
| 71 | return false; |
| 72 | } |
| 73 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 74 | virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty) { |
| 75 | DEFER_LOGD("replaying draw batch %p", this); |
| 76 | |
| 77 | status_t status = DrawGlInfo::kStatusDone; |
| 78 | DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance(); |
| 79 | for (unsigned int i = 0; i < mOps.size(); i++) { |
| 80 | DrawOp* op = mOps[i]; |
| 81 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 82 | renderer.restoreDisplayState(op->state); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 83 | |
| 84 | #if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 85 | renderer.eventMark(op->name()); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 86 | #endif |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 87 | status |= op->applyDraw(renderer, dirty, 0); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 88 | logBuffer.writeCommand(0, op->name()); |
| 89 | } |
| 90 | return status; |
| 91 | } |
| 92 | |
| 93 | inline int count() const { return mOps.size(); } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 94 | private: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 95 | Vector<DrawOp*> mOps; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 96 | Rect mBounds; |
| 97 | }; |
| 98 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 99 | class StateOpBatch : public DrawOpBatch { |
| 100 | public: |
| 101 | // creates a single operation batch |
| 102 | StateOpBatch(StateOp* op) : mOp(op) {} |
| 103 | |
| 104 | bool intersects(Rect& rect) { |
| 105 | // if something checks for intersection, it's trying to go backwards across a state op, |
| 106 | // something not currently supported - state ops are always barriers |
| 107 | CRASH(); |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty) { |
| 112 | DEFER_LOGD("replaying state op batch %p", this); |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 113 | renderer.restoreDisplayState(mOp->state); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 114 | |
| 115 | // use invalid save count because it won't be used at flush time - RestoreToCountOp is the |
| 116 | // only one to use it, and we don't use that class at flush time, instead calling |
| 117 | // renderer.restoreToCount directly |
| 118 | int saveCount = -1; |
| 119 | mOp->applyState(renderer, saveCount); |
| 120 | return DrawGlInfo::kStatusDone; |
| 121 | } |
| 122 | |
| 123 | private: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 124 | const StateOp* mOp; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | class RestoreToCountBatch : public DrawOpBatch { |
| 128 | public: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 129 | RestoreToCountBatch(StateOp* op, int restoreCount) : mOp(op), mRestoreCount(restoreCount) {} |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 130 | |
| 131 | bool intersects(Rect& rect) { |
| 132 | // if something checks for intersection, it's trying to go backwards across a state op, |
| 133 | // something not currently supported - state ops are always barriers |
| 134 | CRASH(); |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty) { |
| 139 | DEFER_LOGD("batch %p restoring to count %d", this, mRestoreCount); |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 140 | |
| 141 | renderer.restoreDisplayState(mOp->state); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 142 | renderer.restoreToCount(mRestoreCount); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 143 | return DrawGlInfo::kStatusDone; |
| 144 | } |
| 145 | |
| 146 | private: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 147 | // we use the state storage for the RestoreToCountOp, but don't replay the op itself |
| 148 | const StateOp* mOp; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 149 | /* |
| 150 | * The count used here represents the flush() time saveCount. This is as opposed to the |
| 151 | * DisplayList record time, or defer() time values (which are RestoreToCountOp's mCount, and |
| 152 | * (saveCount + mCount) respectively). Since the count is different from the original |
| 153 | * RestoreToCountOp, we don't store a pointer to the op, as elsewhere. |
| 154 | */ |
| 155 | const int mRestoreCount; |
| 156 | }; |
| 157 | |
| 158 | ///////////////////////////////////////////////////////////////////////////////// |
| 159 | // DeferredDisplayList |
| 160 | ///////////////////////////////////////////////////////////////////////////////// |
| 161 | |
| 162 | void DeferredDisplayList::resetBatchingState() { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 163 | for (int i = 0; i < kOpBatch_Count; i++) { |
| 164 | mBatchIndices[i] = -1; |
| 165 | } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | void DeferredDisplayList::clear() { |
| 169 | resetBatchingState(); |
| 170 | mComplexClipStackStart = -1; |
| 171 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 172 | for (unsigned int i = 0; i < mBatches.size(); i++) { |
| 173 | delete mBatches[i]; |
| 174 | } |
| 175 | mBatches.clear(); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 176 | mSaveStack.clear(); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 179 | ///////////////////////////////////////////////////////////////////////////////// |
| 180 | // Operation adding |
| 181 | ///////////////////////////////////////////////////////////////////////////////// |
| 182 | |
| 183 | int DeferredDisplayList::getStateOpDeferFlags() const { |
| 184 | // For both clipOp and save(Layer)Op, we don't want to save drawing info, and only want to save |
| 185 | // the clip if we aren't recording a complex clip (and can thus trust it to be a rect) |
| 186 | return recordingComplexClip() ? 0 : kStateDeferFlag_Clip; |
| 187 | } |
| 188 | |
| 189 | int DeferredDisplayList::getDrawOpDeferFlags() const { |
| 190 | return kStateDeferFlag_Draw | getStateOpDeferFlags(); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * When an clipping operation occurs that could cause a complex clip, record the operation and all |
| 195 | * subsequent clipOps, save/restores (if the clip flag is set). During a flush, instead of loading |
| 196 | * the clip from deferred state, we play back all of the relevant state operations that generated |
| 197 | * the complex clip. |
| 198 | * |
| 199 | * Note that we don't need to record the associated restore operation, since operations at defer |
| 200 | * time record whether they should store the renderer's current clip |
| 201 | */ |
| 202 | void DeferredDisplayList::addClip(OpenGLRenderer& renderer, ClipOp* op) { |
| 203 | if (recordingComplexClip() || op->canCauseComplexClip() || !renderer.hasRectToRectTransform()) { |
| 204 | DEFER_LOGD("%p Received complex clip operation %p", this, op); |
| 205 | |
| 206 | // NOTE: defer clip op before setting mComplexClipStackStart so previous clip is recorded |
| 207 | storeStateOpBarrier(renderer, op); |
| 208 | |
| 209 | if (!recordingComplexClip()) { |
| 210 | mComplexClipStackStart = renderer.getSaveCount() - 1; |
| 211 | DEFER_LOGD(" Starting complex clip region, start is %d", mComplexClipStackStart); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 212 | } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * For now, we record save layer operations as barriers in the batch list, preventing drawing |
| 218 | * operations from reordering around the saveLayer and it's associated restore() |
| 219 | * |
| 220 | * In the future, we should send saveLayer commands (if they can be played out of order) and their |
| 221 | * contained drawing operations to a seperate list of batches, so that they may draw at the |
| 222 | * beginning of the frame. This would avoid targetting and removing an FBO in the middle of a frame. |
| 223 | * |
| 224 | * saveLayer operations should be pulled to the beginning of the frame if the canvas doesn't have a |
| 225 | * complex clip, and if the flags (kClip_SaveFlag & kClipToLayer_SaveFlag) are set. |
| 226 | */ |
| 227 | void DeferredDisplayList::addSaveLayer(OpenGLRenderer& renderer, |
| 228 | SaveLayerOp* op, int newSaveCount) { |
| 229 | DEFER_LOGD("%p adding saveLayerOp %p, flags %x, new count %d", |
| 230 | this, op, op->getFlags(), newSaveCount); |
| 231 | |
| 232 | storeStateOpBarrier(renderer, op); |
| 233 | mSaveStack.push(newSaveCount); |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Takes save op and it's return value - the new save count - and stores it into the stream as a |
| 238 | * barrier if it's needed to properly modify a complex clip |
| 239 | */ |
| 240 | void DeferredDisplayList::addSave(OpenGLRenderer& renderer, SaveOp* op, int newSaveCount) { |
| 241 | int saveFlags = op->getFlags(); |
| 242 | DEFER_LOGD("%p adding saveOp %p, flags %x, new count %d", this, op, saveFlags, newSaveCount); |
| 243 | |
| 244 | if (recordingComplexClip() && (saveFlags & SkCanvas::kClip_SaveFlag)) { |
| 245 | // store and replay the save operation, as it may be needed to correctly playback the clip |
| 246 | DEFER_LOGD(" adding save barrier with new save count %d", newSaveCount); |
| 247 | storeStateOpBarrier(renderer, op); |
| 248 | mSaveStack.push(newSaveCount); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * saveLayer() commands must be associated with a restoreToCount batch that will clean up and draw |
| 254 | * the layer in the deferred list |
| 255 | * |
| 256 | * other save() commands which occur as children of a snapshot with complex clip will be deferred, |
| 257 | * and must be restored |
| 258 | * |
| 259 | * Either will act as a barrier to draw operation reordering, as we want to play back layer |
| 260 | * save/restore and complex canvas modifications (including save/restore) in order. |
| 261 | */ |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 262 | void DeferredDisplayList::addRestoreToCount(OpenGLRenderer& renderer, StateOp* op, |
| 263 | int newSaveCount) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 264 | DEFER_LOGD("%p addRestoreToCount %d", this, newSaveCount); |
| 265 | |
| 266 | if (recordingComplexClip() && newSaveCount <= mComplexClipStackStart) { |
| 267 | mComplexClipStackStart = -1; |
| 268 | resetBatchingState(); |
| 269 | } |
| 270 | |
| 271 | if (mSaveStack.isEmpty() || newSaveCount > mSaveStack.top()) { |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | while (!mSaveStack.isEmpty() && mSaveStack.top() >= newSaveCount) mSaveStack.pop(); |
| 276 | |
Chris Craik | 1ed30c9 | 2013-04-03 12:37:35 -0700 | [diff] [blame] | 277 | storeRestoreToCountBarrier(renderer, op, mSaveStack.size() + FLUSH_SAVE_STACK_DEPTH); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void DeferredDisplayList::addDrawOp(OpenGLRenderer& renderer, DrawOp* op) { |
| 281 | if (renderer.storeDisplayState(op->state, getDrawOpDeferFlags())) { |
| 282 | return; // quick rejected |
| 283 | } |
| 284 | |
| 285 | op->onDrawOpDeferred(renderer); |
| 286 | |
| 287 | if (CC_UNLIKELY(renderer.getCaches().drawReorderDisabled)) { |
| 288 | // TODO: elegant way to reuse batches? |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 289 | DrawOpBatch* b = new DrawOpBatch(); |
| 290 | b->add(op); |
| 291 | mBatches.add(b); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | // disallowReorder isn't set, so find the latest batch of the new op's type, and try to merge |
| 296 | // the new op into it |
| 297 | DrawOpBatch* targetBatch = NULL; |
| 298 | int batchId = op->getBatchId(); |
| 299 | |
| 300 | if (!mBatches.isEmpty()) { |
| 301 | if (op->state.mBounds.isEmpty()) { |
| 302 | // don't know the bounds for op, so add to last batch and start from scratch on next op |
| 303 | mBatches.top()->add(op); |
| 304 | for (int i = 0; i < kOpBatch_Count; i++) { |
| 305 | mBatchIndices[i] = -1; |
| 306 | } |
| 307 | #if DEBUG_DEFER |
| 308 | DEFER_LOGD("Warning: Encountered op with empty bounds, resetting batches"); |
| 309 | op->output(2); |
| 310 | #endif |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | if (batchId >= 0 && mBatchIndices[batchId] != -1) { |
| 315 | int targetIndex = mBatchIndices[batchId]; |
| 316 | targetBatch = mBatches[targetIndex]; |
| 317 | // iterate back toward target to see if anything drawn since should overlap the new op |
| 318 | for (int i = mBatches.size() - 1; i > targetIndex; i--) { |
| 319 | DrawOpBatch* overBatch = mBatches[i]; |
| 320 | if (overBatch->intersects(op->state.mBounds)) { |
| 321 | targetBatch = NULL; |
| 322 | #if DEBUG_DEFER |
| 323 | DEFER_LOGD("op couldn't join batch %d, was intersected by batch %d", |
| 324 | targetIndex, i); |
| 325 | op->output(2); |
| 326 | #endif |
| 327 | break; |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | if (!targetBatch) { |
| 333 | targetBatch = new DrawOpBatch(); |
| 334 | mBatches.add(targetBatch); |
| 335 | if (batchId >= 0) { |
| 336 | mBatchIndices[batchId] = mBatches.size() - 1; |
| 337 | } |
| 338 | } |
| 339 | targetBatch->add(op); |
| 340 | } |
| 341 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 342 | void DeferredDisplayList::storeStateOpBarrier(OpenGLRenderer& renderer, StateOp* op) { |
| 343 | DEFER_LOGD("%p adding state op barrier at pos %d", this, mBatches.size()); |
| 344 | |
| 345 | renderer.storeDisplayState(op->state, getStateOpDeferFlags()); |
| 346 | mBatches.add(new StateOpBatch(op)); |
| 347 | resetBatchingState(); |
| 348 | } |
| 349 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 350 | void DeferredDisplayList::storeRestoreToCountBarrier(OpenGLRenderer& renderer, StateOp* op, |
| 351 | int newSaveCount) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 352 | DEFER_LOGD("%p adding restore to count %d barrier, pos %d", |
| 353 | this, newSaveCount, mBatches.size()); |
| 354 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 355 | // store displayState for the restore operation, as it may be associated with a saveLayer that |
| 356 | // doesn't have kClip_SaveFlag set |
| 357 | renderer.storeDisplayState(op->state, getStateOpDeferFlags()); |
| 358 | mBatches.add(new RestoreToCountBatch(op, newSaveCount)); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 359 | resetBatchingState(); |
| 360 | } |
| 361 | |
| 362 | ///////////////////////////////////////////////////////////////////////////////// |
| 363 | // Replay / flush |
| 364 | ///////////////////////////////////////////////////////////////////////////////// |
| 365 | |
| 366 | static status_t replayBatchList(Vector<DrawOpBatch*>& batchList, |
| 367 | OpenGLRenderer& renderer, Rect& dirty) { |
| 368 | status_t status = DrawGlInfo::kStatusDone; |
| 369 | |
| 370 | int opCount = 0; |
| 371 | for (unsigned int i = 0; i < batchList.size(); i++) { |
| 372 | status |= batchList[i]->replay(renderer, dirty); |
| 373 | opCount += batchList[i]->count(); |
| 374 | } |
| 375 | DEFER_LOGD("--flushed, drew %d batches (total %d ops)", batchList.size(), opCount); |
| 376 | return status; |
| 377 | } |
| 378 | |
| 379 | status_t DeferredDisplayList::flush(OpenGLRenderer& renderer, Rect& dirty) { |
| 380 | ATRACE_NAME("flush drawing commands"); |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame^] | 381 | Caches::getInstance().fontRenderer->endPrecaching(); |
| 382 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 383 | status_t status = DrawGlInfo::kStatusDone; |
| 384 | |
| 385 | if (isEmpty()) return status; // nothing to flush |
Chris Craik | a4e16c5 | 2013-03-22 10:00:48 -0700 | [diff] [blame] | 386 | renderer.restoreToCount(1); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 387 | |
| 388 | DEFER_LOGD("--flushing"); |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 389 | renderer.eventMark("Flush"); |
| 390 | |
Chris Craik | a4e16c5 | 2013-03-22 10:00:48 -0700 | [diff] [blame] | 391 | // 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] | 392 | DrawModifiers restoreDrawModifiers = renderer.getDrawModifiers(); |
Chris Craik | a4e16c5 | 2013-03-22 10:00:48 -0700 | [diff] [blame] | 393 | renderer.save(SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag); |
| 394 | |
Chris Craik | 1ed30c9 | 2013-04-03 12:37:35 -0700 | [diff] [blame] | 395 | // NOTE: depth of the save stack at this point, before playback, should be reflected in |
| 396 | // FLUSH_SAVE_STACK_DEPTH, so that save/restores match up correctly |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 397 | status |= replayBatchList(mBatches, renderer, dirty); |
Chris Craik | a4e16c5 | 2013-03-22 10:00:48 -0700 | [diff] [blame] | 398 | |
| 399 | renderer.restoreToCount(1); |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 400 | renderer.setDrawModifiers(restoreDrawModifiers); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 401 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 402 | DEFER_LOGD("--flush complete, returning %x", status); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 403 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 404 | clear(); |
| 405 | return status; |
| 406 | } |
| 407 | |
| 408 | }; // namespace uirenderer |
| 409 | }; // namespace android |