blob: ffffa0b031ac39d31453675efd9a5505a6e16b02 [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 Osman62e7b5f2016-10-26 12:02:18 -040013
14#include "batches/GrCopySurfaceBatch.h"
15
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
33 SkDebugf("batches (%d):\n", fRecordedBatches.count());
34 for (int i = 0; i < fRecordedBatches.count(); ++i) {
35 SkDebugf("*******************************\n");
36 SkDebugf("%d: %s\n", i, fRecordedBatches[i]->name());
37 SkString str = fRecordedBatches[i]->dumpInfo();
38 SkDebugf("%s\n", str.c_str());
39 const SkRect& clippedBounds = fRecordedBatches[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
47void GrTextureOpList::prepareBatches(GrBatchFlushState* flushState) {
48 // 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
54 // Loop over the batches that haven't yet generated their geometry
55 for (int i = 0; i < fRecordedBatches.count(); ++i) {
56 if (fRecordedBatches[i]) {
57 fRecordedBatches[i]->prepare(flushState);
58 }
59 }
60}
61
62bool GrTextureOpList::drawBatches(GrBatchFlushState* flushState) {
63 if (0 == fRecordedBatches.count()) {
64 return false;
65 }
66
67 for (int i = 0; i < fRecordedBatches.count(); ++i) {
68 fRecordedBatches[i]->draw(flushState, fRecordedBatches[i]->bounds());
69 }
70
71 fGpu->finishOpList();
72 return true;
73}
74
75void GrTextureOpList::reset() {
76 fRecordedBatches.reset();
77}
78
79////////////////////////////////////////////////////////////////////////////////
80
81bool GrTextureOpList::copySurface(GrSurface* dst,
82 GrSurface* src,
83 const SkIRect& srcRect,
84 const SkIPoint& dstPoint) {
Brian Salomon25a88092016-12-01 09:36:50 -050085 GrOp* batch = GrCopySurfaceBatch::Create(dst, src, srcRect, dstPoint);
Brian Osman62e7b5f2016-10-26 12:02:18 -040086 if (!batch) {
87 return false;
88 }
89#ifdef ENABLE_MDB
90 this->addDependency(src);
91#endif
92
93 this->recordBatch(batch);
94 batch->unref();
95 return true;
96}
97
Brian Salomon25a88092016-12-01 09:36:50 -050098void GrTextureOpList::recordBatch(GrOp* batch) {
Brian Osman62e7b5f2016-10-26 12:02:18 -040099 // A closed GrOpList should never receive new/more batches
100 SkASSERT(!this->isClosed());
101
102 GR_AUDIT_TRAIL_ADDBATCH(fAuditTrail, batch);
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",
105 batch->name(),
106 batch->uniqueID(),
107 batch->bounds().fLeft, batch->bounds().fRight,
108 batch->bounds().fTop, batch->bounds().fBottom);
Brian Salomon25a88092016-12-01 09:36:50 -0500109 GrOP_INFO(SkTabString(batch->dumpInfo(), 1).c_str());
Brian Osman62e7b5f2016-10-26 12:02:18 -0400110 GR_AUDIT_TRAIL_BATCHING_RESULT_NEW(fAuditTrail, batch);
111
112 fRecordedBatches.emplace_back(sk_ref_sp(batch));
113}