blob: 2a021d231a5c99fe62746d298d449a965136be8d [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
79bool GrTextureOpList::copySurface(GrSurface* dst,
80 GrSurface* src,
81 const SkIRect& srcRect,
82 const SkIPoint& dstPoint) {
Brian Salomonf8334782017-01-03 09:42:58 -050083 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -050084 if (!op) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040085 return false;
86 }
87#ifdef ENABLE_MDB
88 this->addDependency(src);
89#endif
90
Brian Salomon69868af2016-12-22 15:42:51 -050091 // See the comment in GrRenderTargetOpList about why we pass the invalid ID here.
92 this->recordOp(std::move(op), GrGpuResource::UniqueID::InvalidID());
Brian Osman62e7b5f2016-10-26 12:02:18 -040093 return true;
94}
95
Brian Salomonf8334782017-01-03 09:42:58 -050096void GrTextureOpList::recordOp(std::unique_ptr<GrOp> op, GrGpuResource::UniqueID renderTargetID) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050097 // A closed GrOpList should never receive new/more ops
Brian Osman62e7b5f2016-10-26 12:02:18 -040098 SkASSERT(!this->isClosed());
99
Brian Salomon69868af2016-12-22 15:42:51 -0500100 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), renderTargetID);
Brian Salomon25a88092016-12-01 09:36:50 -0500101 GrOP_INFO("Re-Recording (%s, B%u)\n"
Brian Osman62e7b5f2016-10-26 12:02:18 -0400102 "\tBounds LRTB (%f, %f, %f, %f)\n",
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500103 op->name(),
104 op->uniqueID(),
105 op->bounds().fLeft, op->bounds().fRight,
106 op->bounds().fTop, op->bounds().fBottom);
107 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon42ad83a2016-12-20 16:14:45 -0500108 GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op.get());
Brian Osman62e7b5f2016-10-26 12:02:18 -0400109
Brian Salomon2790c522016-12-09 16:32:23 -0500110 fRecordedOps.emplace_back(std::move(op));
Brian Osman62e7b5f2016-10-26 12:02:18 -0400111}