chromium/third_party/skia/src/gpu/graphite/ScratchResourceManager.h

/*
 * Copyright 2024 Google LLC
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef skgpu_graphite_ScratchResourceManager_DEFINED
#define skgpu_graphite_ScratchResourceManager_DEFINED

#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include "include/private/base/SkTArray.h"
#include "src/core/SkTHash.h"

#include <string_view>

namespace skgpu::graphite {

class Resource;
class ResourceProvider;
class Texture;
class TextureInfo;
class TextureProxy;

// NOTE: This is temporary while atlas management requires flushing an entire Recorder. That
// can break a scratch Device into multiple DrawTasks and the proxy read count needs to count
// all reads regardless of which DrawTask is referenced. Once scratch devices only produce a
// single DrawTask, DrawTask can hold the pending read count directly.
class ProxyReadCountMap {};

/**
 * ScratchResourceManager helps coordinate the reuse of resources *within* a Recording that would
 * not otherwise be returned from the ResourceProvider/Cache because the Recorder is holds usage
 * refs on the resources and they are typically not Shareable.
 *
 * A ScratchResourceManager maintains a pool of resources that have been handed out for some use
 * case and then been explicitly returned by the original holder. It is up to the callers to
 * return resources in an optimal manner (for best reuse) and not use them after they've been
 * returned for a later task's use. To help callers manage when they can return resources,
 * the manager maintains a stack that corresponds with the depth-first traversal of the tasks
 * during prepareResources() and provides hooks to register listeners that are invoked when tasks
 * read or sample resources.
 *
 * Once all uninstantiated resources are assigned and prepareResources() succeeds, the
 * ScratchResourceManager can be discarded. The reuse within a Recording's task graph is fixed at
 * that point and remains valid even if the recording is replayed.
 */
class ScratchResourceManager {};

} // namespace skgpu::graphite

#endif // skgpu_graphite_ResourceReuseManager_DEFINED