blob: 61990ded4d5356b62b34823776ee3d5134858e7f [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) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040048 // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh
49 // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed
50 // but need to be flushed anyway. Closing such GrOpLists here will mean new
51 // GrOpLists will be created to replace them if the SkGpuDevice(s) write to them again.
52 this->makeClosed();
53
Brian Salomon1e41f4a2016-12-07 15:05:04 -050054 // Loop over the ops that haven't yet generated their geometry
55 for (int i = 0; i < fRecordedOps.count(); ++i) {
56 if (fRecordedOps[i]) {
57 fRecordedOps[i]->prepare(flushState);
Brian Osman62e7b5f2016-10-26 12:02:18 -040058 }
59 }
60}
61
Brian Salomon742e31d2016-12-07 17:06:19 -050062bool GrTextureOpList::executeOps(GrOpFlushState* flushState) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050063 if (0 == fRecordedOps.count()) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040064 return false;
65 }
66
Brian Salomon1e41f4a2016-12-07 15:05:04 -050067 for (int i = 0; i < fRecordedOps.count(); ++i) {
Brian Salomonbde42852016-12-21 11:37:49 -050068 fRecordedOps[i]->execute(flushState, fRecordedOps[i]->bounds());
Brian Osman62e7b5f2016-10-26 12:02:18 -040069 }
70
71 fGpu->finishOpList();
72 return true;
73}
74
75void GrTextureOpList::reset() {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050076 fRecordedOps.reset();
Brian Osman62e7b5f2016-10-26 12:02:18 -040077}
78
79////////////////////////////////////////////////////////////////////////////////
80
81bool GrTextureOpList::copySurface(GrSurface* dst,
82 GrSurface* src,
83 const SkIRect& srcRect,
84 const SkIPoint& dstPoint) {
Brian Salomonf8334782017-01-03 09:42:58 -050085 std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
Brian Salomon1e41f4a2016-12-07 15:05:04 -050086 if (!op) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040087 return false;
88 }
89#ifdef ENABLE_MDB
90 this->addDependency(src);
91#endif
92
Brian Salomon69868af2016-12-22 15:42:51 -050093 // See the comment in GrRenderTargetOpList about why we pass the invalid ID here.
94 this->recordOp(std::move(op), GrGpuResource::UniqueID::InvalidID());
Brian Osman62e7b5f2016-10-26 12:02:18 -040095 return true;
96}
97
Brian Salomonf8334782017-01-03 09:42:58 -050098void GrTextureOpList::recordOp(std::unique_ptr<GrOp> op, GrGpuResource::UniqueID renderTargetID) {
Brian Salomon1e41f4a2016-12-07 15:05:04 -050099 // A closed GrOpList should never receive new/more ops
Brian Osman62e7b5f2016-10-26 12:02:18 -0400100 SkASSERT(!this->isClosed());
101
Brian Salomon69868af2016-12-22 15:42:51 -0500102 GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), renderTargetID);
Brian Salomon25a88092016-12-01 09:36:50 -0500103 GrOP_INFO("Re-Recording (%s, B%u)\n"
Brian Osman62e7b5f2016-10-26 12:02:18 -0400104 "\tBounds LRTB (%f, %f, %f, %f)\n",
Brian Salomon1e41f4a2016-12-07 15:05:04 -0500105 op->name(),
106 op->uniqueID(),
107 op->bounds().fLeft, op->bounds().fRight,
108 op->bounds().fTop, op->bounds().fBottom);
109 GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
Brian Salomon42ad83a2016-12-20 16:14:45 -0500110 GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op.get());
Brian Osman62e7b5f2016-10-26 12:02:18 -0400111
Brian Salomon2790c522016-12-09 16:32:23 -0500112 fRecordedOps.emplace_back(std::move(op));
Brian Osman62e7b5f2016-10-26 12:02:18 -0400113}