• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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"
12 #include "GrTextureProxy.h"
13 #include "SkStringUtils.h"
14 #include "ops/GrCopySurfaceOp.h"
15 
16 ////////////////////////////////////////////////////////////////////////////////
17 
GrTextureOpList(GrTextureProxy * tex,GrGpu * gpu,GrAuditTrail * auditTrail)18 GrTextureOpList::GrTextureOpList(GrTextureProxy* tex, GrGpu* gpu, GrAuditTrail* auditTrail)
19     : INHERITED(tex, auditTrail)
20     , fGpu(SkRef(gpu)) {
21 }
22 
~GrTextureOpList()23 GrTextureOpList::~GrTextureOpList() {
24     fGpu->unref();
25 }
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 
29 #ifdef SK_DEBUG
dump() const30 void GrTextureOpList::dump() const {
31     INHERITED::dump();
32 
33     SkDebugf("ops (%d):\n", fRecordedOps.count());
34     for (int i = 0; i < fRecordedOps.count(); ++i) {
35         SkDebugf("*******************************\n");
36         SkDebugf("%d: %s\n", i, fRecordedOps[i]->name());
37         SkString str = fRecordedOps[i]->dumpInfo();
38         SkDebugf("%s\n", str.c_str());
39         const SkRect& clippedBounds = fRecordedOps[i]->bounds();
40         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 
prepareOps(GrOpFlushState * flushState)47 void GrTextureOpList::prepareOps(GrOpFlushState* flushState) {
48     // MDB TODO: add SkASSERT(this->isClosed());
49 
50     // 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             // We do not call flushState->setDrawOpArgs as this op list does not support GrDrawOps.
54             fRecordedOps[i]->prepare(flushState);
55         }
56     }
57 }
58 
executeOps(GrOpFlushState * flushState)59 bool GrTextureOpList::executeOps(GrOpFlushState* flushState) {
60     if (0 == fRecordedOps.count()) {
61         return false;
62     }
63 
64     for (int i = 0; i < fRecordedOps.count(); ++i) {
65         // We do not call flushState->setDrawOpArgs as this op list does not support GrDrawOps.
66         fRecordedOps[i]->execute(flushState);
67     }
68 
69     fGpu->finishOpList();
70     return true;
71 }
72 
reset()73 void GrTextureOpList::reset() {
74     fRecordedOps.reset();
75 }
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 
copySurface(GrSurface * dst,GrSurface * src,const SkIRect & srcRect,const SkIPoint & dstPoint)79 bool GrTextureOpList::copySurface(GrSurface* dst,
80                                   GrSurface* src,
81                                   const SkIRect& srcRect,
82                                   const SkIPoint& dstPoint) {
83     std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(dst, src, srcRect, dstPoint);
84     if (!op) {
85         return false;
86     }
87 #ifdef ENABLE_MDB
88     this->addDependency(src);
89 #endif
90 
91     // See the comment in GrRenderTargetOpList about why we pass the invalid ID here.
92     this->recordOp(std::move(op), GrGpuResource::UniqueID::InvalidID());
93     return true;
94 }
95 
recordOp(std::unique_ptr<GrOp> op,GrGpuResource::UniqueID renderTargetID)96 void GrTextureOpList::recordOp(std::unique_ptr<GrOp> op, GrGpuResource::UniqueID renderTargetID) {
97     // A closed GrOpList should never receive new/more ops
98     SkASSERT(!this->isClosed());
99 
100     GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), renderTargetID);
101     GrOP_INFO("Re-Recording (%s, B%u)\n"
102         "\tBounds LRTB (%f, %f, %f, %f)\n",
103         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());
108     GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op.get());
109 
110     fRecordedOps.emplace_back(std::move(op));
111 }
112