Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrTextureOpList.h" |
| 9 | |
| 10 | #include "GrAuditTrail.h" |
| 11 | #include "GrGpu.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 12 | #include "GrTextureProxy.h" |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 13 | |
| 14 | #include "batches/GrCopySurfaceBatch.h" |
| 15 | |
| 16 | //////////////////////////////////////////////////////////////////////////////// |
| 17 | |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 18 | GrTextureOpList::GrTextureOpList(GrTextureProxy* tex, GrGpu* gpu, GrAuditTrail* auditTrail) |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 19 | : INHERITED(tex, auditTrail) |
| 20 | , fGpu(SkRef(gpu)) { |
| 21 | } |
| 22 | |
| 23 | GrTextureOpList::~GrTextureOpList() { |
| 24 | fGpu->unref(); |
| 25 | } |
| 26 | |
| 27 | //////////////////////////////////////////////////////////////////////////////// |
| 28 | |
| 29 | #ifdef SK_DEBUG |
| 30 | void GrTextureOpList::dump() const { |
| 31 | INHERITED::dump(); |
| 32 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 33 | SkDebugf("ops (%d):\n", fRecordedOps.count()); |
| 34 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 35 | SkDebugf("*******************************\n"); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 36 | SkDebugf("%d: %s\n", i, fRecordedOps[i]->name()); |
| 37 | SkString str = fRecordedOps[i]->dumpInfo(); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 38 | SkDebugf("%s\n", str.c_str()); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 39 | const SkRect& clippedBounds = fRecordedOps[i]->bounds(); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 40 | SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", |
| 41 | clippedBounds.fLeft, clippedBounds.fTop, clippedBounds.fRight, |
| 42 | clippedBounds.fBottom); |
| 43 | } |
| 44 | } |
| 45 | #endif |
| 46 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame^] | 47 | void GrTextureOpList::prepareOps(GrOpFlushState* flushState) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 48 | // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh |
| 49 | // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed |
| 50 | // but need to be flushed anyway. Closing such GrOpLists here will mean new |
| 51 | // GrOpLists will be created to replace them if the SkGpuDevice(s) write to them again. |
| 52 | this->makeClosed(); |
| 53 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 54 | // Loop over the ops that haven't yet generated their geometry |
| 55 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 56 | if (fRecordedOps[i]) { |
| 57 | fRecordedOps[i]->prepare(flushState); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame^] | 62 | bool GrTextureOpList::executeOps(GrOpFlushState* flushState) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 63 | if (0 == fRecordedOps.count()) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 64 | return false; |
| 65 | } |
| 66 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 67 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 68 | fRecordedOps[i]->draw(flushState, fRecordedOps[i]->bounds()); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | fGpu->finishOpList(); |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | void GrTextureOpList::reset() { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 76 | fRecordedOps.reset(); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | //////////////////////////////////////////////////////////////////////////////// |
| 80 | |
| 81 | bool GrTextureOpList::copySurface(GrSurface* dst, |
| 82 | GrSurface* src, |
| 83 | const SkIRect& srcRect, |
| 84 | const SkIPoint& dstPoint) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 85 | GrOp* op = GrCopySurfaceBatch::Create(dst, src, srcRect, dstPoint); |
| 86 | if (!op) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 87 | return false; |
| 88 | } |
| 89 | #ifdef ENABLE_MDB |
| 90 | this->addDependency(src); |
| 91 | #endif |
| 92 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 93 | this->recordOp(op); |
| 94 | op->unref(); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 95 | return true; |
| 96 | } |
| 97 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 98 | void GrTextureOpList::recordOp(GrOp* op) { |
| 99 | // A closed GrOpList should never receive new/more ops |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 100 | SkASSERT(!this->isClosed()); |
| 101 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 102 | GR_AUDIT_TRAIL_ADDBATCH(fAuditTrail, op); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 103 | GrOP_INFO("Re-Recording (%s, B%u)\n" |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 104 | "\tBounds LRTB (%f, %f, %f, %f)\n", |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 105 | op->name(), |
| 106 | op->uniqueID(), |
| 107 | op->bounds().fLeft, op->bounds().fRight, |
| 108 | op->bounds().fTop, op->bounds().fBottom); |
| 109 | GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
| 110 | GR_AUDIT_TRAIL_BATCHING_RESULT_NEW(fAuditTrail, op); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 111 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 112 | fRecordedOps.emplace_back(sk_ref_sp(op)); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 113 | } |