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 Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 13 | #include "SkStringUtils.h" |
Brian Salomon | 8952743 | 2016-12-16 09:52:16 -0500 | [diff] [blame] | 14 | #include "ops/GrCopySurfaceOp.h" |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 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) { |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 48 | // MDB TODO: add SkASSERT(this->isClosed()); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 49 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 50 | // Loop over the ops that haven't yet generated their geometry |
| 51 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
| 52 | if (fRecordedOps[i]) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 53 | // We do not call flushState->setDrawOpArgs as this op list does not support GrDrawOps. |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 54 | fRecordedOps[i]->prepare(flushState); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 59 | bool GrTextureOpList::executeOps(GrOpFlushState* flushState) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 60 | if (0 == fRecordedOps.count()) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 61 | return false; |
| 62 | } |
| 63 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 64 | for (int i = 0; i < fRecordedOps.count(); ++i) { |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 65 | // We do not call flushState->setDrawOpArgs as this op list does not support GrDrawOps. |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 66 | fRecordedOps[i]->execute(flushState); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | fGpu->finishOpList(); |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | void GrTextureOpList::reset() { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 74 | fRecordedOps.reset(); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | //////////////////////////////////////////////////////////////////////////////// |
| 78 | |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 79 | bool GrTextureOpList::copySurface(GrResourceProvider* resourceProvider, |
| 80 | GrSurfaceProxy* dst, |
| 81 | GrSurfaceProxy* src, |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 82 | const SkIRect& srcRect, |
| 83 | const SkIPoint& dstPoint) { |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 84 | std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(resourceProvider, dst, src, srcRect, dstPoint); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 85 | if (!op) { |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 86 | return false; |
| 87 | } |
| 88 | #ifdef ENABLE_MDB |
| 89 | this->addDependency(src); |
| 90 | #endif |
| 91 | |
Brian Salomon | 69868af | 2016-12-22 15:42:51 -0500 | [diff] [blame] | 92 | // See the comment in GrRenderTargetOpList about why we pass the invalid ID here. |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 93 | this->recordOp(std::move(op), |
| 94 | GrGpuResource::UniqueID::InvalidID(), |
| 95 | GrSurfaceProxy::UniqueID::InvalidID()); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 96 | return true; |
| 97 | } |
| 98 | |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 99 | void GrTextureOpList::recordOp(std::unique_ptr<GrOp> op, |
| 100 | GrGpuResource::UniqueID resourceUniqueID, |
| 101 | GrSurfaceProxy::UniqueID proxyUniqueID) { |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 102 | // A closed GrOpList should never receive new/more ops |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 103 | SkASSERT(!this->isClosed()); |
| 104 | |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 105 | GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), resourceUniqueID, proxyUniqueID); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 106 | GrOP_INFO("Re-Recording (%s, B%u)\n" |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 107 | "\tBounds LRTB (%f, %f, %f, %f)\n", |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 108 | op->name(), |
| 109 | op->uniqueID(), |
| 110 | op->bounds().fLeft, op->bounds().fRight, |
| 111 | op->bounds().fTop, op->bounds().fBottom); |
| 112 | GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
Brian Salomon | 42ad83a | 2016-12-20 16:14:45 -0500 | [diff] [blame] | 113 | GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op.get()); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 114 | |
Brian Salomon | 2790c52 | 2016-12-09 16:32:23 -0500 | [diff] [blame] | 115 | fRecordedOps.emplace_back(std::move(op)); |
Brian Osman | 62e7b5f | 2016-10-26 12:02:18 -0400 | [diff] [blame] | 116 | } |