diff --git a/experimental/graphite/src/DrawContext.cpp b/experimental/graphite/src/DrawContext.cpp index cd2551f4eb..a7d48393f3 100644 --- a/experimental/graphite/src/DrawContext.cpp +++ b/experimental/graphite/src/DrawContext.cpp @@ -178,7 +178,7 @@ sk_sp DrawContext::snapRenderPassTask(Recorder* recorder, } sk_sp DrawContext::snapUploadTask(Recorder* recorder) { - if (!fPendingUploads) { + if (!fPendingUploads || fPendingUploads->size() == 0) { return nullptr; } diff --git a/experimental/graphite/src/UploadTask.cpp b/experimental/graphite/src/UploadTask.cpp index 5e2629f9d0..56ca2f03d3 100644 --- a/experimental/graphite/src/UploadTask.cpp +++ b/experimental/graphite/src/UploadTask.cpp @@ -20,24 +20,12 @@ namespace skgpu { -void UploadCommand::addCommand(ResourceProvider* resourceProvider, - CommandBuffer* commandBuffer) const { - if (!fTextureProxy) { - SKGPU_LOG_E("No texture proxy specified for UploadTask"); - return; - } - if (!fTextureProxy->instantiate(resourceProvider)) { - SKGPU_LOG_E("Could not instantiate texture proxy for UploadTask!"); - return; - } - - commandBuffer->copyBufferToTexture(std::move(fBuffer), - fTextureProxy->refTexture(), - fCopyData.data(), - fCopyData.size()); -} - -//--------------------------------------------------------------------------- +UploadInstance::UploadInstance(sk_sp buffer, + sk_sp textureProxy, + std::vector copyData) + : fBuffer(buffer) + , fTextureProxy(textureProxy) + , fCopyData(copyData) {} size_t compute_combined_buffer_size(int mipLevelCount, size_t bytesPerPixel, @@ -68,11 +56,11 @@ size_t compute_combined_buffer_size(int mipLevelCount, return combinedBufferSize; } -bool UploadList::appendUpload(Recorder* recorder, - sk_sp textureProxy, - SkColorType dataColorType, - const std::vector& levels, - const SkIRect& dstRect) { +UploadInstance UploadInstance::Make(Recorder* recorder, + sk_sp textureProxy, + SkColorType dataColorType, + const std::vector& levels, + const SkIRect& dstRect) { const Caps* caps = recorder->priv().caps(); SkASSERT(caps->isTexturable(textureProxy->textureInfo())); @@ -85,20 +73,20 @@ bool UploadList::appendUpload(Recorder* recorder, SkASSERT(mipLevelCount == 1 || mipLevelCount == textureProxy->textureInfo().numMipLevels()); if (dstRect.isEmpty()) { - return false; + return {}; } SkASSERT(caps->areColorTypeAndTextureInfoCompatible(dataColorType, textureProxy->textureInfo())); if (mipLevelCount == 1 && !levels[0].fPixels) { - return true; // no data to upload + return {}; // no data to upload } for (unsigned int i = 0; i < mipLevelCount; ++i) { // We do not allow any gaps in the mip data if (!levels[i].fPixels) { - return false; + return {}; } } @@ -118,7 +106,7 @@ bool UploadList::appendUpload(Recorder* recorder, std::vector copyData(mipLevelCount); if (!buffer) { - return false; + return {}; } char* bufferData = (char*) buffer->map(); // TODO: get from staging buffer instead size_t baseOffset = 0; @@ -149,25 +137,69 @@ bool UploadList::appendUpload(Recorder* recorder, buffer->unmap(); - fCommands.push_back({std::move(buffer), std::move(textureProxy), std::move(copyData)}); + return {std::move(buffer), std::move(textureProxy), std::move(copyData)}; +} +void UploadInstance::addCommand(ResourceProvider* resourceProvider, + CommandBuffer* commandBuffer) const { + if (!fTextureProxy) { + SKGPU_LOG_E("No texture proxy specified for UploadTask"); + return; + } + if (!fTextureProxy->instantiate(resourceProvider)) { + SKGPU_LOG_E("Could not instantiate texture proxy for UploadTask!"); + return; + } + + commandBuffer->copyBufferToTexture(std::move(fBuffer), + fTextureProxy->refTexture(), + fCopyData.data(), + fCopyData.size()); +} + +//--------------------------------------------------------------------------- + +bool UploadList::appendUpload(Recorder* recorder, + sk_sp textureProxy, + SkColorType dataColorType, + const std::vector& levels, + const SkIRect& dstRect) { + UploadInstance instance = UploadInstance::Make(recorder, textureProxy, dataColorType, + levels, dstRect); + if (!instance.isValid()) { + return false; + } + + fInstances.push_back(instance); return true; } //--------------------------------------------------------------------------- sk_sp UploadTask::Make(UploadList* uploadList) { - return sk_sp(new UploadTask(std::move(uploadList->fCommands))); + SkASSERT(uploadList && uploadList->fInstances.size() > 0); + return sk_sp(new UploadTask(std::move(uploadList->fInstances))); } -UploadTask::UploadTask(std::vector commands) : fCommands(std::move(commands)) {} +sk_sp UploadTask::Make(const UploadInstance& instance) { + if (!instance.isValid()) { + return nullptr; + } + return sk_sp(new UploadTask(instance)); +} + +UploadTask::UploadTask(std::vector instances) : fInstances(std::move(instances)) {} + +UploadTask::UploadTask(const UploadInstance& instance) { + fInstances.push_back(instance); +} UploadTask::~UploadTask() {} void UploadTask::addCommands(ResourceProvider* resourceProvider, CommandBuffer* commandBuffer) { - for (unsigned int i = 0; i < fCommands.size(); ++i) { - fCommands[i].addCommand(resourceProvider, commandBuffer); + for (unsigned int i = 0; i < fInstances.size(); ++i) { + fInstances[i].addCommand(resourceProvider, commandBuffer); } } diff --git a/experimental/graphite/src/UploadTask.h b/experimental/graphite/src/UploadTask.h index 0804f4f117..4b67497c2c 100644 --- a/experimental/graphite/src/UploadTask.h +++ b/experimental/graphite/src/UploadTask.h @@ -31,12 +31,26 @@ struct MipLevel { }; /** - * An UploadCommand represents a single set of uploads from a buffer to texture that + * An UploadInstance represents a single set of uploads from a buffer to texture that * can be processed in a single command. */ -struct UploadCommand { +class UploadInstance { +public: + static UploadInstance Make(Recorder*, + sk_sp targetProxy, + SkColorType colorType, + const std::vector& levels, + const SkIRect& dstRect); + + bool isValid() const { return fBuffer != nullptr; } + + // Adds upload command to the given CommandBuffer void addCommand(ResourceProvider*, CommandBuffer*) const; +private: + UploadInstance() {} + UploadInstance(sk_sp, sk_sp, std::vector); + sk_sp fBuffer; sk_sp fTextureProxy; std::vector fCopyData; @@ -60,10 +74,12 @@ public: const std::vector& levels, const SkIRect& dstRect); + int size() { return fInstances.size(); } + private: friend class UploadTask; - std::vector fCommands; + std::vector fInstances; }; /* @@ -75,15 +91,17 @@ private: class UploadTask final : public Task { public: static sk_sp Make(UploadList*); + static sk_sp Make(const UploadInstance&); ~UploadTask() override; void addCommands(ResourceProvider*, CommandBuffer*) override; private: - UploadTask(std::vector); + UploadTask(std::vector); + UploadTask(const UploadInstance&); - std::vector fCommands; + std::vector fInstances; }; } // namespace skgpu