Revert "Reland "Revert "Use ManagedBackendTexture in place of TestUtils backend texture helpers."""
This reverts commit 4efaf5e9feada3eddf286fb362f60d3b11a24e34.
Cq-Include-Trybots: luci.skia.skia.primary:Test-Win10-MSVC-Golo-GPU-QuadroP400-x86_64-Debug-All-Direct3D,Test-Win10-Clang-ShuttleA-GPU-RadeonHD7770-x86_64-Debug-All-Direct3D
Change-Id: I0f5f1c427e8892a67b027b0fbe4863d9fcee2363
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325863
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/tools/gpu/ManagedBackendTexture.cpp b/tools/gpu/ManagedBackendTexture.cpp
index 8409caa..192a57c 100644
--- a/tools/gpu/ManagedBackendTexture.cpp
+++ b/tools/gpu/ManagedBackendTexture.cpp
@@ -7,10 +7,27 @@
#include "tools/gpu/ManagedBackendTexture.h"
+#include "include/core/SkImageInfo.h"
+#include "include/private/GrTypesPriv.h"
+#include "src/core/SkMipmap.h"
+
+namespace {
+
+struct Context {
+ sk_sp<sk_gpu_test::ManagedBackendTexture> fMBET;
+ GrGpuFinishedProc fWrappedProc = nullptr;
+ GrGpuFinishedContext fWrappedContext = nullptr;
+};
+
+} // anonymous namespace
+
namespace sk_gpu_test {
-void ManagedBackendTexture::ReleaseProc(void* context) {
- static_cast<ManagedBackendTexture*>(context)->unref();
+void ManagedBackendTexture::ReleaseProc(void* ctx) {
+ std::unique_ptr<Context> context(static_cast<Context*>(ctx));
+ if (context->fWrappedProc) {
+ context->fWrappedProc(context->fWrappedContext);
+ }
}
ManagedBackendTexture::~ManagedBackendTexture() {
@@ -19,9 +36,49 @@
}
}
-void* ManagedBackendTexture::releaseContext() {
- this->ref();
- return static_cast<void*>(this);
+void* ManagedBackendTexture::releaseContext(GrGpuFinishedProc wrappedProc,
+ GrGpuFinishedContext wrappedCtx) const {
+ // Make sure we don't get a wrapped ctx without a wrapped proc
+ SkASSERT(!wrappedCtx || wrappedProc);
+ return new Context{sk_ref_sp(this), wrappedProc, wrappedCtx};
+}
+
+sk_sp<GrRefCntedCallback> ManagedBackendTexture::refCountedCallback() const {
+ return sk_make_sp<GrRefCntedCallback>(ReleaseProc, this->releaseContext());
+}
+
+void ManagedBackendTexture::wasAdopted() { fTexture = {}; }
+
+sk_sp<ManagedBackendTexture> ManagedBackendTexture::MakeFromInfo(GrDirectContext* dContext,
+ const SkImageInfo& ii,
+ GrMipmapped mipmapped,
+ GrRenderable renderable,
+ GrProtected isProtected) {
+ return MakeWithoutData(
+ dContext, ii.width(), ii.height(), ii.colorType(), mipmapped, renderable, isProtected);
+}
+
+sk_sp<ManagedBackendTexture> ManagedBackendTexture::MakeFromBitmap(GrDirectContext* dContext,
+ const SkBitmap& bitmap,
+ GrMipmapped mipmapped,
+ GrRenderable renderable,
+ GrProtected isProtected) {
+ std::vector<SkPixmap> levels({bitmap.pixmap()});
+ std::unique_ptr<SkMipmap> mm;
+
+ if (mipmapped == GrMipmapped::kYes) {
+ mm.reset(SkMipmap::Build(bitmap, nullptr));
+ if (!mm) {
+ return nullptr;
+ }
+ for (int i = 0; i < mm->countLevels(); ++i) {
+ SkMipmap::Level level;
+ SkAssertResult(mm->getLevel(i, &level));
+ levels.push_back(level.fPixmap);
+ }
+ }
+ return MakeWithData(
+ dContext, levels.data(), static_cast<int>(levels.size()), renderable, isProtected);
}
} // namespace sk_gpu_test