2017-08-30 16:06:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkDeferredDisplayList_DEFINED
|
|
|
|
#define SkDeferredDisplayList_DEFINED
|
|
|
|
|
2019-05-17 20:29:34 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSurfaceCharacterization.h"
|
2019-05-17 20:29:34 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2017-08-30 16:06:35 +00:00
|
|
|
|
2019-05-17 20:29:34 +00:00
|
|
|
class SkDeferredDisplayListPriv;
|
2018-09-19 14:28:59 +00:00
|
|
|
|
2019-05-17 20:29:34 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
2019-05-17 20:29:34 +00:00
|
|
|
#include "include/private/SkTArray.h"
|
2018-09-19 14:28:59 +00:00
|
|
|
#include <map>
|
2019-08-01 20:14:52 +00:00
|
|
|
class GrRenderTask;
|
2020-02-21 18:38:15 +00:00
|
|
|
class GrRenderTargetProxy;
|
2019-08-22 20:19:24 +00:00
|
|
|
struct GrCCPerOpsTaskPaths;
|
2020-06-09 18:15:09 +00:00
|
|
|
#else
|
|
|
|
using GrRenderTargetProxy = SkRefCnt;
|
2018-02-01 14:10:04 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-30 16:06:35 +00:00
|
|
|
/*
|
|
|
|
* This class contains pre-processed gpu operations that can be replayed into
|
2020-02-21 19:24:40 +00:00
|
|
|
* an SkSurface via SkSurface::draw(SkDeferredDisplayList*).
|
2017-08-30 16:06:35 +00:00
|
|
|
*/
|
2020-06-29 14:00:08 +00:00
|
|
|
class SkDeferredDisplayList : public SkNVRefCnt<SkDeferredDisplayList> {
|
2017-08-30 16:06:35 +00:00
|
|
|
public:
|
2020-02-21 19:24:40 +00:00
|
|
|
SK_API ~SkDeferredDisplayList();
|
|
|
|
|
|
|
|
SK_API const SkSurfaceCharacterization& characterization() const {
|
|
|
|
return fCharacterization;
|
|
|
|
}
|
|
|
|
|
2020-02-24 13:38:34 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
/**
|
|
|
|
* Iterate through the programs required by the DDL.
|
|
|
|
*/
|
|
|
|
class SK_API ProgramIterator {
|
|
|
|
public:
|
2020-08-13 20:03:16 +00:00
|
|
|
ProgramIterator(GrDirectContext*, SkDeferredDisplayList*);
|
2020-02-24 13:38:34 +00:00
|
|
|
~ProgramIterator();
|
|
|
|
|
2020-05-06 17:34:45 +00:00
|
|
|
// This returns true if any work was done. Getting a cache hit does not count as work.
|
|
|
|
bool compile();
|
2020-02-24 13:38:34 +00:00
|
|
|
bool done() const;
|
|
|
|
void next();
|
|
|
|
|
|
|
|
private:
|
2020-08-13 20:03:16 +00:00
|
|
|
GrDirectContext* fDContext;
|
2020-02-24 13:38:34 +00:00
|
|
|
const SkTArray<GrRecordingContext::ProgramData>& fProgramData;
|
|
|
|
int fIndex;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2020-02-21 19:24:40 +00:00
|
|
|
// Provides access to functions that aren't part of the public API.
|
|
|
|
SkDeferredDisplayListPriv priv();
|
2020-08-07 17:05:14 +00:00
|
|
|
const SkDeferredDisplayListPriv priv() const; // NOLINT(readability-const-return-type)
|
2020-02-21 19:24:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class GrDrawingManager; // for access to 'fRenderTasks', 'fLazyProxyData', 'fArenas'
|
|
|
|
friend class SkDeferredDisplayListRecorder; // for access to 'fLazyProxyData'
|
|
|
|
friend class SkDeferredDisplayListPriv;
|
2020-02-21 18:38:15 +00:00
|
|
|
|
|
|
|
// This object is the source from which the lazy proxy backing the DDL will pull its backing
|
|
|
|
// texture when the DDL is replayed. It has to be separately ref counted bc the lazy proxy
|
|
|
|
// can outlive the DDL.
|
2020-02-21 19:24:40 +00:00
|
|
|
class LazyProxyData : public SkRefCnt {
|
|
|
|
#if SK_SUPPORT_GPU
|
2020-02-21 18:38:15 +00:00
|
|
|
public:
|
|
|
|
// Upon being replayed - this field will be filled in (by the DrawingManager) with the
|
|
|
|
// proxy backing the destination SkSurface. Note that, since there is no good place to
|
2020-04-16 20:27:45 +00:00
|
|
|
// clear it, it can become a dangling pointer. Additionally, since the renderTargetProxy
|
|
|
|
// doesn't get a ref here, the SkSurface that owns it must remain alive until the DDL
|
|
|
|
// is flushed.
|
|
|
|
// TODO: the drawing manager could ref the renderTargetProxy for the DDL and then add
|
|
|
|
// a renderingTask to unref it after the DDL's ops have been executed.
|
2020-02-21 18:38:15 +00:00
|
|
|
GrRenderTargetProxy* fReplayDest = nullptr;
|
|
|
|
#endif
|
2020-02-21 19:24:40 +00:00
|
|
|
};
|
2020-02-21 18:38:15 +00:00
|
|
|
|
|
|
|
SK_API SkDeferredDisplayList(const SkSurfaceCharacterization& characterization,
|
2020-06-09 18:15:09 +00:00
|
|
|
sk_sp<GrRenderTargetProxy> fTargetProxy,
|
2020-02-21 18:38:15 +00:00
|
|
|
sk_sp<LazyProxyData>);
|
2018-02-01 14:10:04 +00:00
|
|
|
|
2019-12-06 18:05:49 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2020-02-21 19:24:40 +00:00
|
|
|
const SkTArray<GrRecordingContext::ProgramData>& programData() const {
|
2020-02-18 19:26:46 +00:00
|
|
|
return fProgramData;
|
2019-12-06 18:05:49 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-11-30 16:22:14 +00:00
|
|
|
const SkSurfaceCharacterization fCharacterization;
|
2017-08-30 16:06:35 +00:00
|
|
|
|
2018-02-01 14:10:04 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2018-05-31 16:43:27 +00:00
|
|
|
// This needs to match the same type in GrCoverageCountingPathRenderer.h
|
2019-08-22 20:19:24 +00:00
|
|
|
using PendingPathsMap = std::map<uint32_t, sk_sp<GrCCPerOpsTaskPaths>>;
|
2018-05-31 16:43:27 +00:00
|
|
|
|
2020-03-03 18:20:17 +00:00
|
|
|
// When programs are stored in 'fProgramData' their memory is actually allocated in
|
|
|
|
// 'fArenas.fRecordTimeAllocator'. In that case that arena must be freed before
|
|
|
|
// 'fPendingPaths' which relies on uniquely holding the atlas proxies used by the
|
|
|
|
// GrCCClipPaths.
|
|
|
|
PendingPathsMap fPendingPaths; // This is the path data from CCPR.
|
2019-12-12 18:59:20 +00:00
|
|
|
// These are ordered such that the destructor cleans op tasks up first (which may refer back
|
|
|
|
// to the arena and memory pool in their destructors).
|
2019-12-19 19:50:44 +00:00
|
|
|
GrRecordingContext::OwnedArenas fArenas;
|
2019-12-12 18:59:20 +00:00
|
|
|
SkTArray<sk_sp<GrRenderTask>> fRenderTasks;
|
2019-12-06 18:05:49 +00:00
|
|
|
|
2020-02-18 19:26:46 +00:00
|
|
|
SkTArray<GrRecordingContext::ProgramData> fProgramData;
|
2020-06-09 18:15:09 +00:00
|
|
|
sk_sp<GrRenderTargetProxy> fTargetProxy;
|
2020-02-21 18:38:15 +00:00
|
|
|
sk_sp<LazyProxyData> fLazyProxyData;
|
2020-02-21 19:24:40 +00:00
|
|
|
#endif
|
2017-08-30 16:06:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|