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#ifndef GrTexureOpList_DEFINED
9#define GrTexureOpList_DEFINED
10
11#include "GrGpuResource.h"
12#include "GrOpList.h"
13#include "GrSurfaceProxy.h"
14
15#include "SkTArray.h"
16
17class GrAuditTrail;
18class GrGpu;
19class GrOp;
20class GrTextureProxy;
21struct SkIPoint;
22struct SkIRect;
23
24class GrTextureOpList final : public GrOpList {
25public:
26    GrTextureOpList(GrResourceProvider*, GrTextureProxy*, GrAuditTrail*);
27    ~GrTextureOpList() override;
28
29    /**
30     * Empties the draw buffer of any queued ops.
31     */
32    void endFlush() override;
33
34    /**
35     * Together these two functions flush all queued ops to GrGpuCommandBuffer. The return value
36     * of executeOps() indicates whether any commands were actually issued to the GPU.
37     */
38    void onPrepare(GrOpFlushState* flushState) override;
39    bool onExecute(GrOpFlushState* flushState) override;
40
41    /**
42     * Copies a pixel rectangle from one surface to another. This call may finalize
43     * reserved vertex/index data (as though a draw call was made). The src pixels
44     * copied are specified by srcRect. They are copied to a rect of the same
45     * size in dst with top left at dstPoint. If the src rect is clipped by the
46     * src bounds then  pixel values in the dst rect corresponding to area clipped
47     * by the src rect are not overwritten. This method is not guaranteed to succeed
48     * depending on the type of surface, configs, etc, and the backend-specific
49     * limitations.
50     */
51    bool copySurface(const GrCaps& caps,
52                     GrSurfaceProxy* dst,
53                     GrSurfaceProxy* src,
54                     const SkIRect& srcRect,
55                     const SkIPoint& dstPoint) override;
56
57    GrTextureOpList* asTextureOpList() override { return this; }
58
59    SkDEBUGCODE(void dump() const override;)
60
61    SkDEBUGCODE(int numOps() const override { return fRecordedOps.count(); })
62
63private:
64    void purgeOpsWithUninstantiatedProxies() override;
65
66    void gatherProxyIntervals(GrResourceAllocator*) const override;
67
68    void recordOp(std::unique_ptr<GrOp>);
69
70    SkSTArray<2, std::unique_ptr<GrOp>, true> fRecordedOps;
71
72    typedef GrOpList INHERITED;
73};
74
75#endif
76