2020-06-26 17:32:09 +00:00
|
|
|
/*
|
|
|
|
* 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/BackendTextureImageFactory.h"
|
|
|
|
|
2022-03-31 19:07:44 +00:00
|
|
|
#include "include/core/SkColorSpace.h"
|
2020-06-26 17:32:09 +00:00
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkPixmap.h"
|
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-07-20 20:02:05 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-06-26 17:32:09 +00:00
|
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
2020-10-08 20:00:14 +00:00
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
2020-06-26 17:32:09 +00:00
|
|
|
|
|
|
|
namespace sk_gpu_test {
|
2020-07-20 20:02:05 +00:00
|
|
|
sk_sp<SkImage> MakeBackendTextureImage(GrDirectContext* dContext,
|
2020-06-26 17:32:09 +00:00
|
|
|
const SkPixmap& pixmap,
|
|
|
|
GrRenderable renderable,
|
|
|
|
GrSurfaceOrigin origin) {
|
2020-12-07 16:30:16 +00:00
|
|
|
auto mbet = ManagedBackendTexture::MakeWithData(dContext,
|
|
|
|
pixmap,
|
|
|
|
origin,
|
|
|
|
renderable,
|
|
|
|
GrProtected::kNo);
|
2020-11-05 16:11:20 +00:00
|
|
|
if (!mbet) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-07-20 20:02:05 +00:00
|
|
|
return SkImage::MakeFromTexture(dContext,
|
2020-07-01 16:12:04 +00:00
|
|
|
mbet->texture(),
|
|
|
|
origin,
|
2020-12-07 16:30:16 +00:00
|
|
|
pixmap.colorType(),
|
|
|
|
pixmap.alphaType(),
|
|
|
|
pixmap.refColorSpace(),
|
2020-10-08 20:00:14 +00:00
|
|
|
ManagedBackendTexture::ReleaseProc,
|
|
|
|
mbet->releaseContext());
|
2020-06-26 17:32:09 +00:00
|
|
|
}
|
2020-10-13 00:45:06 +00:00
|
|
|
|
|
|
|
sk_sp<SkImage> MakeBackendTextureImage(GrDirectContext* dContext,
|
|
|
|
const SkImageInfo& info,
|
|
|
|
SkColor4f color,
|
|
|
|
GrMipmapped mipmapped,
|
|
|
|
GrRenderable renderable,
|
|
|
|
GrSurfaceOrigin origin) {
|
|
|
|
if (info.alphaType() == kOpaque_SkAlphaType) {
|
|
|
|
color = color.makeOpaque();
|
|
|
|
} else if (info.alphaType() == kPremul_SkAlphaType) {
|
|
|
|
auto pmColor = color.premul();
|
|
|
|
color = {pmColor.fR, pmColor.fG, pmColor.fB, pmColor.fA};
|
|
|
|
}
|
|
|
|
auto mbet = ManagedBackendTexture::MakeWithData(dContext,
|
|
|
|
info.width(),
|
|
|
|
info.height(),
|
|
|
|
info.colorType(),
|
|
|
|
color,
|
|
|
|
mipmapped,
|
|
|
|
renderable,
|
|
|
|
GrProtected::kNo);
|
2020-11-05 16:11:20 +00:00
|
|
|
if (!mbet) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-10-13 00:45:06 +00:00
|
|
|
return SkImage::MakeFromTexture(dContext,
|
|
|
|
mbet->texture(),
|
|
|
|
origin,
|
|
|
|
info.colorType(),
|
|
|
|
info.alphaType(),
|
|
|
|
info.refColorSpace(),
|
|
|
|
ManagedBackendTexture::ReleaseProc,
|
|
|
|
mbet->releaseContext());
|
|
|
|
}
|
|
|
|
|
2020-06-26 17:32:09 +00:00
|
|
|
} // namespace sk_gpu_test
|