skia2/tools/gpu/ManagedBackendTexture.cpp
Brian Salomon 694ff17357 Revert "Revert changes to unbreak bots."
This reverts commit 49721c8437.

Reason for revert: fixed double usage of plane release context in
 YUVUtils.

Original change's description:
> Revert changes to unbreak bots.
>
> f01a9d9020
> is the culprit
>
>
> Revert "GrRefCntedCallback has Make function."
>
> This reverts commit b2c42140ea.
>
> Revert "Add SkImage::MakeFromYUVATexturesCopyToExternal"
>
> This reverts commit f01a9d9020.
>
> Bug: skia:10632
> Change-Id: Ief076f168b63ff8ca15b607163a13d5f52a733d2
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/331798
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>

TBR=bsalomon@google.com

Change-Id: I41cdfe0d5b8587f85fae0c804c059c0d6ff92800


Bug: skia:10632
Change-Id: I41cdfe0d5b8587f85fae0c804c059c0d6ff92800
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/331876
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2020-11-05 14:35:23 +00:00

94 lines
3.3 KiB
C++

/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "tools/gpu/ManagedBackendTexture.h"
#include "include/core/SkImageInfo.h"
#include "include/private/GrTypesPriv.h"
#include "src/core/SkMipmap.h"
namespace {
struct Context {
GrGpuFinishedProc fWrappedProc = nullptr;
GrGpuFinishedContext fWrappedContext = nullptr;
sk_sp<sk_gpu_test::ManagedBackendTexture> fMBETs[SkYUVAInfo::kMaxPlanes];
};
} // anonymous namespace
namespace sk_gpu_test {
void ManagedBackendTexture::ReleaseProc(void* ctx) {
std::unique_ptr<Context> context(static_cast<Context*>(ctx));
if (context->fWrappedProc) {
context->fWrappedProc(context->fWrappedContext);
}
}
ManagedBackendTexture::~ManagedBackendTexture() {
if (fDContext && fTexture.isValid()) {
fDContext->deleteBackendTexture(fTexture);
}
}
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{wrappedProc, wrappedCtx, {sk_ref_sp(this)}};
}
void* ManagedBackendTexture::MakeYUVAReleaseContext(
const sk_sp<ManagedBackendTexture> mbets[SkYUVAInfo::kMaxPlanes]) {
auto context = new Context;
for (int i = 0; i < SkYUVAInfo::kMaxPlanes; ++i) {
context->fMBETs[i] = mbets[i];
}
return context;
}
sk_sp<GrRefCntedCallback> ManagedBackendTexture::refCountedCallback() const {
return GrRefCntedCallback::Make(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