dd1c8403b092cd945d33940e331b571a5e785cd6
[platform/upstream/libSkiaSharp.git] / src / gpu / GrTextureOpList.cpp
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
18 GrTextureOpList::GrTextureOpList(GrTextureProxy* proxy, GrAuditTrail* auditTrail)
19     : INHERITED(proxy, auditTrail) {
20 }
21
22 GrTextureOpList::~GrTextureOpList() {
23 }
24
25 ////////////////////////////////////////////////////////////////////////////////
26
27 #ifdef SK_DEBUG
28 void GrTextureOpList::dump() const {
29     INHERITED::dump();
30
31     SkDebugf("ops (%d):\n", fRecordedOps.count());
32     for (int i = 0; i < fRecordedOps.count(); ++i) {
33         SkDebugf("*******************************\n");
34         SkDebugf("%d: %s\n", i, fRecordedOps[i]->name());
35         SkString str = fRecordedOps[i]->dumpInfo();
36         SkDebugf("%s\n", str.c_str());
37         const SkRect& clippedBounds = fRecordedOps[i]->bounds();
38         SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
39                     clippedBounds.fLeft, clippedBounds.fTop, clippedBounds.fRight,
40                     clippedBounds.fBottom);
41     }
42 }
43
44 void GrTextureOpList::validateTargetsSingleRenderTarget() const {
45     SkASSERT(1 == fRecordedOps.count() || 0 == fRecordedOps.count());
46 }
47
48 #endif
49
50 void GrTextureOpList::prepareOps(GrOpFlushState* flushState) {
51     SkASSERT(this->isClosed());
52
53     // Loop over the ops that haven't yet generated their geometry
54     for (int i = 0; i < fRecordedOps.count(); ++i) {
55         if (fRecordedOps[i]) {
56             // We do not call flushState->setDrawOpArgs as this op list does not support GrDrawOps.
57             fRecordedOps[i]->prepare(flushState);
58         }
59     }
60 }
61
62 bool GrTextureOpList::executeOps(GrOpFlushState* flushState) {
63     if (0 == fRecordedOps.count()) {
64         return false;
65     }
66
67     for (int i = 0; i < fRecordedOps.count(); ++i) {
68         // We do not call flushState->setDrawOpArgs as this op list does not support GrDrawOps.
69         fRecordedOps[i]->execute(flushState);
70     }
71
72     return true;
73 }
74
75 void GrTextureOpList::reset() {
76     fRecordedOps.reset();
77     INHERITED::reset();
78 }
79
80 ////////////////////////////////////////////////////////////////////////////////
81
82 // MDB TODO: fuse with GrRenderTargetOpList::copySurface
83 bool GrTextureOpList::copySurface(GrResourceProvider* resourceProvider,
84                                   GrSurfaceProxy* dst,
85                                   GrSurfaceProxy* src,
86                                   const SkIRect& srcRect,
87                                   const SkIPoint& dstPoint) {
88     std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(resourceProvider, dst, src, srcRect, dstPoint);
89     if (!op) {
90         return false;
91     }
92 #ifdef ENABLE_MDB
93     this->addDependency(src);
94 #endif
95
96     // See the comment in GrRenderTargetOpList about why we pass the invalid ID here.
97     this->recordOp(std::move(op),
98                    GrGpuResource::UniqueID::InvalidID(),
99                    GrSurfaceProxy::UniqueID::InvalidID());
100     return true;
101 }
102
103 void GrTextureOpList::recordOp(std::unique_ptr<GrOp> op,
104                                GrGpuResource::UniqueID resourceUniqueID,
105                                GrSurfaceProxy::UniqueID proxyUniqueID) {
106     // A closed GrOpList should never receive new/more ops
107     SkASSERT(!this->isClosed());
108
109     GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), resourceUniqueID, proxyUniqueID);
110     GrOP_INFO("Re-Recording (%s, opID: %u)\n"
111         "\tBounds LRTB (%f, %f, %f, %f)\n",
112         op->name(),
113         op->uniqueID(),
114         op->bounds().fLeft, op->bounds().fRight,
115         op->bounds().fTop, op->bounds().fBottom);
116     GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str());
117     GR_AUDIT_TRAIL_OP_RESULT_NEW(fAuditTrail, op.get());
118
119     fRecordedOps.emplace_back(std::move(op));
120 }