2021-10-06 14:43:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2022-04-07 20:08:04 +00:00
|
|
|
#ifndef skgpu_graphite_Recorder_DEFINED
|
|
|
|
#define skgpu_graphite_Recorder_DEFINED
|
2021-10-06 14:43:54 +00:00
|
|
|
|
2021-10-14 20:30:49 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
2022-02-04 18:39:21 +00:00
|
|
|
#include "include/private/SingleOwner.h"
|
2021-10-06 14:43:54 +00:00
|
|
|
|
2022-02-04 20:47:51 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2022-03-23 18:14:26 +00:00
|
|
|
class SkTextureDataBlock;
|
2022-03-21 17:23:56 +00:00
|
|
|
class SkUniformDataBlock;
|
2022-04-11 18:39:15 +00:00
|
|
|
class SkUniformDataBlockPassThrough; // TODO: remove
|
2022-03-21 17:23:56 +00:00
|
|
|
|
2022-04-07 20:08:04 +00:00
|
|
|
namespace skgpu::graphite {
|
2021-10-06 14:43:54 +00:00
|
|
|
|
2022-02-02 14:56:39 +00:00
|
|
|
class Caps;
|
2022-01-13 14:48:57 +00:00
|
|
|
class Device;
|
2021-10-29 20:33:54 +00:00
|
|
|
class DrawBufferManager;
|
2022-02-04 18:39:21 +00:00
|
|
|
class GlobalCache;
|
2022-02-02 14:56:39 +00:00
|
|
|
class Gpu;
|
2022-02-04 20:47:51 +00:00
|
|
|
class RecorderPriv;
|
2021-10-06 14:43:54 +00:00
|
|
|
class Recording;
|
2022-02-02 14:56:39 +00:00
|
|
|
class ResourceProvider;
|
2022-02-04 20:47:51 +00:00
|
|
|
class Task;
|
|
|
|
class TaskGraph;
|
2022-04-28 19:40:44 +00:00
|
|
|
class UploadBufferManager;
|
2022-03-21 17:23:56 +00:00
|
|
|
|
2022-04-05 17:26:57 +00:00
|
|
|
template<typename StorageT, typename BaseT> class PipelineDataCache;
|
2022-04-11 18:39:15 +00:00
|
|
|
using UniformDataCache = PipelineDataCache<SkUniformDataBlockPassThrough, SkUniformDataBlock>;
|
2022-04-05 17:26:57 +00:00
|
|
|
using TextureDataCache = PipelineDataCache<std::unique_ptr<SkTextureDataBlock>, SkTextureDataBlock>;
|
2021-10-06 14:43:54 +00:00
|
|
|
|
2022-01-13 14:51:23 +00:00
|
|
|
class Recorder final {
|
2021-10-06 14:43:54 +00:00
|
|
|
public:
|
2022-02-03 16:12:45 +00:00
|
|
|
Recorder(const Recorder&) = delete;
|
|
|
|
Recorder(Recorder&&) = delete;
|
|
|
|
Recorder& operator=(const Recorder&) = delete;
|
|
|
|
Recorder& operator=(Recorder&&) = delete;
|
|
|
|
|
2022-01-13 14:51:23 +00:00
|
|
|
~Recorder();
|
2021-10-06 14:43:54 +00:00
|
|
|
|
|
|
|
std::unique_ptr<Recording> snap();
|
|
|
|
|
2022-02-04 20:47:51 +00:00
|
|
|
// Provides access to functions that aren't part of the public API.
|
|
|
|
RecorderPriv priv();
|
|
|
|
const RecorderPriv priv() const; // NOLINT(readability-const-return-type)
|
|
|
|
|
2022-01-13 14:48:57 +00:00
|
|
|
#if GR_TEST_UTILS
|
|
|
|
bool deviceIsRegistered(Device*);
|
|
|
|
#endif
|
|
|
|
|
2021-10-06 14:43:54 +00:00
|
|
|
private:
|
2021-12-02 15:39:33 +00:00
|
|
|
friend class Context; // For ctor
|
2022-01-13 14:48:57 +00:00
|
|
|
friend class Device; // For registering and deregistering Devices;
|
2022-02-04 20:47:51 +00:00
|
|
|
friend class RecorderPriv; // for ctor and hidden methods
|
2022-01-13 14:48:57 +00:00
|
|
|
|
2022-02-04 18:39:21 +00:00
|
|
|
Recorder(sk_sp<Gpu>, sk_sp<GlobalCache>);
|
|
|
|
|
|
|
|
SingleOwner* singleOwner() const { return &fSingleOwner; }
|
2021-12-02 15:39:33 +00:00
|
|
|
|
2022-01-13 14:48:57 +00:00
|
|
|
// We keep track of all Devices that are connected to a Recorder. This allows the client to
|
|
|
|
// safely delete an SkSurface or a Recorder in any order. If the client deletes the Recorder
|
|
|
|
// we need to notify all Devices that the Recorder is no longer valid. If we delete the
|
|
|
|
// SkSurface/Device first we will flush all the Device's into the Recorder before deregistering
|
|
|
|
// it from the Recorder.
|
|
|
|
//
|
|
|
|
// We do not need to take a ref on the Device since the Device will flush and deregister itself
|
|
|
|
// in its dtor. There is no other need for the Recorder to know about the Device after this
|
|
|
|
// point.
|
|
|
|
//
|
|
|
|
// Note: We could probably get by with only registering Devices directly connected to
|
|
|
|
// SkSurfaces. All other one off Devices will be created in a controlled scope where the
|
|
|
|
// Recorder should still be valid by the time they need to flush their work when the Device is
|
|
|
|
// deleted. We would have to make sure we safely handle cases where a client calls saveLayer
|
|
|
|
// then either deletes the SkSurface or Recorder before calling restore. For simplicity we just
|
|
|
|
// register every device for now, but if we see extra overhead in pushing back the extra
|
|
|
|
// pointers, we can look into only registering SkSurface Devices.
|
|
|
|
void registerDevice(Device*);
|
|
|
|
void deregisterDevice(const Device*);
|
|
|
|
|
2022-02-02 14:56:39 +00:00
|
|
|
sk_sp<Gpu> fGpu;
|
|
|
|
std::unique_ptr<ResourceProvider> fResourceProvider;
|
|
|
|
|
2022-02-04 20:47:51 +00:00
|
|
|
std::unique_ptr<TaskGraph> fGraph;
|
2022-03-21 17:23:56 +00:00
|
|
|
std::unique_ptr<UniformDataCache> fUniformDataCache;
|
2022-03-23 18:14:26 +00:00
|
|
|
std::unique_ptr<TextureDataCache> fTextureDataCache;
|
2021-10-29 20:33:54 +00:00
|
|
|
std::unique_ptr<DrawBufferManager> fDrawBufferManager;
|
2022-04-28 19:40:44 +00:00
|
|
|
std::unique_ptr<UploadBufferManager> fUploadBufferManager;
|
2022-01-13 14:48:57 +00:00
|
|
|
std::vector<Device*> fTrackedDevices;
|
2022-02-04 18:39:21 +00:00
|
|
|
|
|
|
|
// In debug builds we guard against improper thread handling
|
|
|
|
// This guard is passed to the ResourceCache.
|
|
|
|
// TODO: Should we also pass this to Device, DrawContext, and similar classes?
|
|
|
|
mutable SingleOwner fSingleOwner;
|
2021-10-06 14:43:54 +00:00
|
|
|
};
|
|
|
|
|
2022-04-07 20:08:04 +00:00
|
|
|
} // namespace skgpu::graphite
|
2021-10-06 14:43:54 +00:00
|
|
|
|
2022-04-07 20:08:04 +00:00
|
|
|
#endif // skgpu_graphite_Recorder_DEFINED
|