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 | |
| 33 | SkDebugf("batches (%d):\n", fRecordedBatches.count()); |
| 34 | for (int i = 0; i < fRecordedBatches.count(); ++i) { |
| 35 | SkDebugf("*******************************\n"); |
| 36 | SkDebugf("%d: %s\n", i, fRecordedBatches[i]->name()); |
| 37 | SkString str = fRecordedBatches[i]->dumpInfo(); |
| 38 | SkDebugf("%s\n", str.c_str()); |
| 39 | const SkRect& clippedBounds = fRecordedBatches[i]->bounds(); |
| 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 | |
| 47 | void GrTextureOpList::prepareBatches(GrBatchFlushState* flushState) { |
| 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 | |
| 54 | // Loop over the batches that haven't yet generated their geometry |
| 55 | for (int i = 0; i < fRecordedBatches.count(); ++i) { |
| 56 | if (fRecordedBatches[i]) { |
| 57 | fRecordedBatches[i]->prepare(flushState); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | bool GrTextureOpList::drawBatches(GrBatchFlushState* flushState) { |
| 63 | if (0 == fRecordedBatches.count()) { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | for (int i = 0; i < fRecordedBatches.count(); ++i) { |
| 68 | fRecordedBatches[i]->draw(flushState, fRecordedBatches[i]->bounds()); |
| 69 | } |
| 70 | |
| 71 | fGpu->finishOpList(); |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | void GrTextureOpList::reset() { |
| 76 | fRecordedBatches.reset(); |
| 77 | } |
| 78 | |
| 79 | //////////////////////////////////////////////////////////////////////////////// |
| 80 | |
| 81 | bool GrTextureOpList::copySurface(GrSurface* dst, |
| 82 | GrSurface* src, |
| 83 | const SkIRect& srcRect, |
| 84 | const SkIPoint& dstPoint) { |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 85 | GrOp* batch = GrCopySurfaceBatch::Create(dst, src, srcRect, dstPoint); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 86 | if (!batch) { |
| 87 | return false; |
| 88 | } |
| 89 | #ifdef ENABLE_MDB |
| 90 | this->addDependency(src); |
| 91 | #endif |
| 92 | |
| 93 | this->recordBatch(batch); |
| 94 | batch->unref(); |
| 95 | return true; |
| 96 | } |
| 97 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 98 | void GrTextureOpList::recordBatch(GrOp* batch) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 99 | // A closed GrOpList should never receive new/more batches |
| 100 | SkASSERT(!this->isClosed()); |
| 101 | |
| 102 | GR_AUDIT_TRAIL_ADDBATCH(fAuditTrail, batch); |
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", |
| 105 | batch->name(), |
| 106 | batch->uniqueID(), |
| 107 | batch->bounds().fLeft, batch->bounds().fRight, |
| 108 | batch->bounds().fTop, batch->bounds().fBottom); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame^] | 109 | GrOP_INFO(SkTabString(batch->dumpInfo(), 1).c_str()); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 110 | GR_AUDIT_TRAIL_BATCHING_RESULT_NEW(fAuditTrail, batch); |
| 111 | |
| 112 | fRecordedBatches.emplace_back(sk_ref_sp(batch)); |
| 113 | } |