blob: eb2380f7bec6627608d84193b8b79cb02d30e5c6 [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 Phillips5efd5ea2017-05-30 13:47:32 -040018GrTextureOpList::GrTextureOpList(GrResourceProvider* resourceProvider,
19 GrTextureProxy* proxy,
20 GrAuditTrail* auditTrail)
21 : INHERITED(resourceProvider, proxy, auditTrail) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040022}
23
24GrTextureOpList::~GrTextureOpList() {
Brian Osman62e7b5f2016-10-26 12:02:18 -040025}
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}
Robert Phillipsc589b0b2017-04-17 07:53:07 -040045
Brian Osman62e7b5f2016-10-26 12:02:18 -040046#endif
47
Brian Salomon742e31d2016-12-07 17:06:19 -050048void GrTextureOpList::prepareOps(GrOpFlushState* flushState) {
Robert Phillips6cdc22c2017-05-11 16:29:14 -040049 SkASSERT(this->isClosed());
Brian Osman62e7b5f2016-10-26 12:02:18 -040050
Brian Salomon1e41f4a2016-12-07 15:05:04 -050051 // Loop over the ops that haven't yet generated their geometry
52 for (int i = 0; i < fRecordedOps.count(); ++i) {
53 if (fRecordedOps[i]) {
Brian Salomon54d212e2017-03-21 14:22:38 -040054 // We do not call flushState->setDrawOpArgs as this op list does not support GrDrawOps.
Brian Salomon1e41f4a2016-12-07 15:05:04 -050055 fRecordedOps[i]->prepare(flushState);
Brian Osman62e7b5f2016-10-26 12:02:18 -040056 }
57 }
58}
59
Brian Salomon742e31d2016-12-07 17:06:19 -050060bool GrTextureOpList::executeOps(GrOpFlushState* flushState) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050061 if (0 == fRecordedOps.count()) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040062 return false;
63 }
64
Brian Salomon1e41f4a2016-12-07 15:05:04 -050065 for (int i = 0; i < fRecordedOps.count(); ++i) {
Brian Salomon54d212e2017-03-21 14:22:38 -040066 // We do not call flushState->setDrawOpArgs as this op list does not support GrDrawOps.
Brian Salomon9e50f7b2017-03-06 12:02:34 -050067 fRecordedOps[i]->execute(flushState);
Brian Osman62e7b5f2016-10-26 12:02:18 -040068 }
69
Brian Osman62e7b5f2016-10-26 12:02:18 -040070 return true;
71}
72
73void GrTextureOpList::reset() {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050074 fRecordedOps.reset();
Robert Phillips6cdc22c2017-05-11 16:29:14 -040075 INHERITED::reset();
Brian Osman62e7b5f2016-10-26 12:02:18 -040076}
77
78////////////////////////////////////////////////////////////////////////////////
79
Robert Phillips81dd3e02017-06-23 11:59:24 -040080// This closely parallels GrRenderTargetOpList::copySurface but renderTargetOpList
81// stores extra data with the op
Robert Phillipsa16f6cb2017-06-01 11:06:13 -040082bool GrTextureOpList::copySurface(const GrCaps& caps,
Robert Phillipsbf25d432017-04-07 10:08:53 -040083 GrSurfaceProxy* dst,
84 GrSurfaceProxy* src,
Brian Osman62e7b5f2016-10-26 12:02:18 -040085 const SkIRect& srcRect,
86 const SkIPoint& dstPoint) {
Robert Phillipsa16f6cb2017-06-01 11:06:13 -040087 SkASSERT(dst == fTarget.get());
88
89 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -050090 if (!op) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040091 return false;
92 }
93#ifdef ENABLE_MDB
94 this->addDependency(src);
95#endif
96
Robert Phillips318c4192017-05-17 09:36:38 -040097 this->recordOp(std::move(op));
Brian Osman62e7b5f2016-10-26 12:02:18 -040098 return true;
99}
100
Robert Phillips318c4192017-05-17 09:36:38 -0400101void GrTextureOpList::recordOp(std::unique_ptr<GrOp> op) {
102 SkASSERT(fTarget.get());
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500103 // A closed GrOpList should never receive new/more ops
Brian Osman62e7b5f2016-10-26 12:02:18 -0400104 SkASSERT(!this->isClosed());
105
Robert Phillips318c4192017-05-17 09:36:38 -0400106 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget.get()->uniqueID());
Robert Phillipsf5442bb2017-04-17 14:18:34 -0400107 GrOP_INFO("Re-Recording (%s, opID: %u)\n"
Brian Osman62e7b5f2016-10-26 12:02:18 -0400108 "\tBounds LRTB (%f, %f, %f, %f)\n",
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500109 op->name(),
110 op->uniqueID(),
111 op->bounds().fLeft, op->bounds().fRight,
112 op->bounds().fTop, op->bounds().fBottom);
113 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon42ad83a2016-12-20 16:14:45 -0500114 GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op.get());
Brian Osman62e7b5f2016-10-26 12:02:18 -0400115
Brian Salomon2790c522016-12-09 16:32:23 -0500116 fRecordedOps.emplace_back(std::move(op));
Brian Osman62e7b5f2016-10-26 12:02:18 -0400117}