blob: d2d922643a19a38111e4e5f7ef515edeff0897f2 [file] [log] [blame]
Brian Osman62e7b5f2016-10-26 12:02:18 -04001/*
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 Phillipsc7635fa2016-10-28 13:25:24 -040012#include "GrTextureProxy.h"
Brian Salomon69868af2016-12-22 15:42:51 -050013#include "SkStringUtils.h"
Brian Salomon89527432016-12-16 09:52:16 -050014#include "ops/GrCopySurfaceOp.h"
Brian Osman62e7b5f2016-10-26 12:02:18 -040015
16////////////////////////////////////////////////////////////////////////////////
17
Robert Phillipsc7635fa2016-10-28 13:25:24 -040018GrTextureOpList::GrTextureOpList(GrTextureProxy* tex, GrGpu* gpu, GrAuditTrail* auditTrail)
Brian Osman62e7b5f2016-10-26 12:02:18 -040019 : INHERITED(tex, auditTrail)
20 , fGpu(SkRef(gpu)) {
21}
22
23GrTextureOpList::~GrTextureOpList() {
24 fGpu->unref();
25}
26
27////////////////////////////////////////////////////////////////////////////////
28
29#ifdef SK_DEBUG
30void GrTextureOpList::dump() const {
31 INHERITED::dump();
32
Brian Salomon1e41f4a2016-12-07 15:05:04 -050033 SkDebugf("ops (%d):\n", fRecordedOps.count());
34 for (int i = 0; i < fRecordedOps.count(); ++i) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040035 SkDebugf("*******************************\n");
Brian Salomon1e41f4a2016-12-07 15:05:04 -050036 SkDebugf("%d: %s\n", i, fRecordedOps[i]->name());
37 SkString str = fRecordedOps[i]->dumpInfo();
Brian Osman62e7b5f2016-10-26 12:02:18 -040038 SkDebugf("%s\n", str.c_str());
Brian Salomon1e41f4a2016-12-07 15:05:04 -050039 const SkRect& clippedBounds = fRecordedOps[i]->bounds();
Brian Osman62e7b5f2016-10-26 12:02:18 -040040 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 Salomon742e31d2016-12-07 17:06:19 -050047void GrTextureOpList::prepareOps(GrOpFlushState* flushState) {
Robert Phillipseb35f4d2017-03-21 07:56:47 -040048 // MDB TODO: add SkASSERT(this->isClosed());
Brian Osman62e7b5f2016-10-26 12:02:18 -040049
Brian Salomon1e41f4a2016-12-07 15:05:04 -050050 // 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 Salomon54d212e2017-03-21 14:22:38 -040053 // We do not call flushState->setDrawOpArgs as this op list does not support GrDrawOps.
Brian Salomon1e41f4a2016-12-07 15:05:04 -050054 fRecordedOps[i]->prepare(flushState);
Brian Osman62e7b5f2016-10-26 12:02:18 -040055 }
56 }
57}
58
Brian Salomon742e31d2016-12-07 17:06:19 -050059bool GrTextureOpList::executeOps(GrOpFlushState* flushState) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050060 if (0 == fRecordedOps.count()) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040061 return false;
62 }
63
Brian Salomon1e41f4a2016-12-07 15:05:04 -050064 for (int i = 0; i < fRecordedOps.count(); ++i) {
Brian Salomon54d212e2017-03-21 14:22:38 -040065 // We do not call flushState->setDrawOpArgs as this op list does not support GrDrawOps.
Brian Salomon9e50f7b2017-03-06 12:02:34 -050066 fRecordedOps[i]->execute(flushState);
Brian Osman62e7b5f2016-10-26 12:02:18 -040067 }
68
69 fGpu->finishOpList();
70 return true;
71}
72
73void GrTextureOpList::reset() {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050074 fRecordedOps.reset();
Brian Osman62e7b5f2016-10-26 12:02:18 -040075}
76
77////////////////////////////////////////////////////////////////////////////////
78
Robert Phillipsbf25d432017-04-07 10:08:53 -040079bool GrTextureOpList::copySurface(GrResourceProvider* resourceProvider,
80 GrSurfaceProxy* dst,
81 GrSurfaceProxy* src,
Brian Osman62e7b5f2016-10-26 12:02:18 -040082 const SkIRect& srcRect,
83 const SkIPoint& dstPoint) {
Robert Phillipsbf25d432017-04-07 10:08:53 -040084 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(resourceProvider, dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -050085 if (!op) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040086 return false;
87 }
88#ifdef ENABLE_MDB
89 this->addDependency(src);
90#endif
91
Brian Salomon69868af2016-12-22 15:42:51 -050092 // See the comment in GrRenderTargetOpList about why we pass the invalid ID here.
Robert Phillipsf7a72612017-03-31 10:03:45 -040093 this->recordOp(std::move(op),
94 GrGpuResource::UniqueID::InvalidID(),
95 GrSurfaceProxy::UniqueID::InvalidID());
Brian Osman62e7b5f2016-10-26 12:02:18 -040096 return true;
97}
98
Robert Phillipsf7a72612017-03-31 10:03:45 -040099void GrTextureOpList::recordOp(std::unique_ptr<GrOp> op,
100 GrGpuResource::UniqueID resourceUniqueID,
101 GrSurfaceProxy::UniqueID proxyUniqueID) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500102 // A closed GrOpList should never receive new/more ops
Brian Osman62e7b5f2016-10-26 12:02:18 -0400103 SkASSERT(!this->isClosed());
104
Robert Phillipsf7a72612017-03-31 10:03:45 -0400105 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), resourceUniqueID, proxyUniqueID);
Brian Salomon25a88092016-12-01 09:36:50 -0500106 GrOP_INFO("Re-Recording (%s, B%u)\n"
Brian Osman62e7b5f2016-10-26 12:02:18 -0400107 "\tBounds LRTB (%f, %f, %f, %f)\n",
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500108 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 Salomon42ad83a2016-12-20 16:14:45 -0500113 GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op.get());
Brian Osman62e7b5f2016-10-26 12:02:18 -0400114
Brian Salomon2790c522016-12-09 16:32:23 -0500115 fRecordedOps.emplace_back(std::move(op));
Brian Osman62e7b5f2016-10-26 12:02:18 -0400116}