blob: d396b2a5ea2ca698d78f75e8227f09b4dc0a478b [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]) {
53 fRecordedOps[i]->prepare(flushState);
Brian Osman62e7b5f2016-10-26 12:02:18 -040054 }
55 }
56}
57
Brian Salomon742e31d2016-12-07 17:06:19 -050058bool GrTextureOpList::executeOps(GrOpFlushState* flushState) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050059 if (0 == fRecordedOps.count()) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040060 return false;
61 }
62
Brian Salomon1e41f4a2016-12-07 15:05:04 -050063 for (int i = 0; i < fRecordedOps.count(); ++i) {
Brian Salomon9e50f7b2017-03-06 12:02:34 -050064 fRecordedOps[i]->execute(flushState);
Brian Osman62e7b5f2016-10-26 12:02:18 -040065 }
66
67 fGpu->finishOpList();
68 return true;
69}
70
71void GrTextureOpList::reset() {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050072 fRecordedOps.reset();
Brian Osman62e7b5f2016-10-26 12:02:18 -040073}
74
75////////////////////////////////////////////////////////////////////////////////
76
77bool GrTextureOpList::copySurface(GrSurface* dst,
78 GrSurface* src,
79 const SkIRect& srcRect,
80 const SkIPoint& dstPoint) {
Brian Salomonf8334782017-01-03 09:42:58 -050081 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -050082 if (!op) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040083 return false;
84 }
85#ifdef ENABLE_MDB
86 this->addDependency(src);
87#endif
88
Brian Salomon69868af2016-12-22 15:42:51 -050089 // See the comment in GrRenderTargetOpList about why we pass the invalid ID here.
90 this->recordOp(std::move(op), GrGpuResource::UniqueID::InvalidID());
Brian Osman62e7b5f2016-10-26 12:02:18 -040091 return true;
92}
93
Brian Salomonf8334782017-01-03 09:42:58 -050094void GrTextureOpList::recordOp(std::unique_ptr<GrOp> op, GrGpuResource::UniqueID renderTargetID) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050095 // A closed GrOpList should never receive new/more ops
Brian Osman62e7b5f2016-10-26 12:02:18 -040096 SkASSERT(!this->isClosed());
97
Brian Salomon69868af2016-12-22 15:42:51 -050098 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), renderTargetID);
Brian Salomon25a88092016-12-01 09:36:50 -050099 GrOP_INFO("Re-Recording (%s, B%u)\n"
Brian Osman62e7b5f2016-10-26 12:02:18 -0400100 "\tBounds LRTB (%f, %f, %f, %f)\n",
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500101 op->name(),
102 op->uniqueID(),
103 op->bounds().fLeft, op->bounds().fRight,
104 op->bounds().fTop, op->bounds().fBottom);
105 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon42ad83a2016-12-20 16:14:45 -0500106 GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op.get());
Brian Osman62e7b5f2016-10-26 12:02:18 -0400107
Brian Salomon2790c522016-12-09 16:32:23 -0500108 fRecordedOps.emplace_back(std::move(op));
Brian Osman62e7b5f2016-10-26 12:02:18 -0400109}