c0bd9f9fe5
Current strategy: everything from the top Things to look at first are the manual changes: - added tools/rewrite_includes.py - removed -Idirectives from BUILD.gn - various compile.sh simplifications - tweak tools/embed_resources.py - update gn/find_headers.py to write paths from the top - update gn/gn_to_bp.py SkUserConfig.h layout so that #include "include/config/SkUserConfig.h" always gets the header we want. No-Presubmit: true Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706 Commit-Queue: Mike Klein <mtklein@google.com> Reviewed-by: Hal Canary <halcanary@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
89 lines
2.6 KiB
C++
89 lines
2.6 KiB
C++
/*
|
|
* Copyright 2019 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "tools/gpu/YUVUtils.h"
|
|
|
|
#include "include/core/SkData.h"
|
|
#include "include/gpu/GrContext.h"
|
|
#include "src/codec/SkCodecImageGenerator.h"
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
namespace sk_gpu_test {
|
|
|
|
std::unique_ptr<LazyYUVImage> LazyYUVImage::Make(sk_sp<SkData> data) {
|
|
std::unique_ptr<LazyYUVImage> image(new LazyYUVImage());
|
|
if (image->reset(std::move(data))) {
|
|
return image;
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
sk_sp<SkImage> LazyYUVImage::refImage(GrContext* context) {
|
|
if (this->ensureYUVImage(context)) {
|
|
return fYUVImage;
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
const SkImage* LazyYUVImage::getImage(GrContext* context) {
|
|
if (this->ensureYUVImage(context)) {
|
|
return fYUVImage.get();
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
bool LazyYUVImage::reset(sk_sp<SkData> data) {
|
|
auto codec = SkCodecImageGenerator::MakeFromEncodedCodec(data);
|
|
if (!codec) {
|
|
return false;
|
|
}
|
|
|
|
if (!codec->queryYUVA8(&fSizeInfo, fComponents, &fColorSpace)) {
|
|
return false;
|
|
}
|
|
|
|
fPlaneData.reset(fSizeInfo.computeTotalBytes());
|
|
void* planes[SkYUVASizeInfo::kMaxCount];
|
|
fSizeInfo.computePlanes(fPlaneData.get(), planes);
|
|
if (!codec->getYUVA8Planes(fSizeInfo, fComponents, planes)) {
|
|
return false;
|
|
}
|
|
|
|
for (int i = 0; i < SkYUVASizeInfo::kMaxCount; ++i) {
|
|
if (fSizeInfo.fSizes[i].isEmpty()) {
|
|
fPlanes[i].reset();
|
|
} else {
|
|
SkASSERT(planes[i]);
|
|
auto planeInfo = SkImageInfo::Make(fSizeInfo.fSizes[i].fWidth,
|
|
fSizeInfo.fSizes[i].fHeight,
|
|
kGray_8_SkColorType, kOpaque_SkAlphaType, nullptr);
|
|
fPlanes[i].reset(planeInfo, planes[i], fSizeInfo.fWidthBytes[i]);
|
|
}
|
|
}
|
|
// The SkPixmap data is fully configured now for MakeFromYUVAPixmaps once we get a GrContext
|
|
return true;
|
|
}
|
|
|
|
bool LazyYUVImage::ensureYUVImage(GrContext* context) {
|
|
if (!context) {
|
|
return false; // Cannot make a YUV image from planes
|
|
}
|
|
if (context->priv().contextID() == fOwningContextID) {
|
|
return fYUVImage != nullptr; // Have already made a YUV image (or tried and failed)
|
|
}
|
|
// Must make a new YUV image
|
|
fYUVImage = SkImage::MakeFromYUVAPixmaps(context, fColorSpace, fPlanes, fComponents,
|
|
fSizeInfo.fSizes[0], kTopLeft_GrSurfaceOrigin, false, false);
|
|
fOwningContextID = context->priv().contextID();
|
|
return fYUVImage != nullptr;
|
|
}
|
|
|
|
} // namespace sk_gpu_test
|