2018-03-07 18:01:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrDrawingManager.h"
|
|
|
|
#include "src/gpu/GrGpu.h"
|
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
2019-05-13 14:40:06 +00:00
|
|
|
#include "src/gpu/SkGr.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
2018-03-07 18:01:25 +00:00
|
|
|
|
|
|
|
namespace sk_gpu_test {
|
|
|
|
|
2019-05-13 14:40:06 +00:00
|
|
|
sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, GrRenderable renderable,
|
2019-02-22 16:16:30 +00:00
|
|
|
int width, int height,
|
2018-09-25 13:31:10 +00:00
|
|
|
GrColorType colorType, GrSRGBEncoded srgbEncoded,
|
2019-05-13 14:40:06 +00:00
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
const void* data, size_t rowBytes) {
|
2019-02-22 16:16:30 +00:00
|
|
|
if (context->priv().abandoned()) {
|
2018-06-25 12:53:09 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-05-13 14:40:06 +00:00
|
|
|
const GrCaps* caps = context->priv().caps();
|
|
|
|
|
|
|
|
const GrBackendFormat format = caps->getBackendFormatFromGrColorType(colorType, srgbEncoded);
|
|
|
|
if (!format.isValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-03-07 20:20:21 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy;
|
|
|
|
if (kBottomLeft_GrSurfaceOrigin == origin) {
|
|
|
|
// We (soon will) only support using kBottomLeft with wrapped textures.
|
2019-02-04 18:26:26 +00:00
|
|
|
auto backendTex = context->priv().getGpu()->createTestingOnlyBackendTexture(
|
2019-05-13 14:40:06 +00:00
|
|
|
width, height, format, GrMipMapped::kNo, renderable);
|
2018-03-07 20:20:21 +00:00
|
|
|
if (!backendTex.isValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-05-13 14:40:06 +00:00
|
|
|
|
2018-03-07 20:20:21 +00:00
|
|
|
// Adopt ownership so our caller doesn't have to worry about deleting the backend texture.
|
2019-05-13 14:40:06 +00:00
|
|
|
if (GrRenderable::kYes == renderable) {
|
2019-02-04 18:26:26 +00:00
|
|
|
proxy = context->priv().proxyProvider()->wrapRenderableBackendTexture(
|
2019-02-05 15:08:43 +00:00
|
|
|
backendTex, origin, 1, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, nullptr,
|
|
|
|
nullptr);
|
2018-03-07 20:20:21 +00:00
|
|
|
} else {
|
2019-02-04 18:26:26 +00:00
|
|
|
proxy = context->priv().proxyProvider()->wrapBackendTexture(
|
2019-01-24 21:03:07 +00:00
|
|
|
backendTex, origin, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType);
|
2018-03-07 20:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!proxy) {
|
2019-02-04 18:26:26 +00:00
|
|
|
context->priv().getGpu()->deleteTestingOnlyBackendTexture(backendTex);
|
2018-03-07 20:20:21 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2018-09-25 13:31:10 +00:00
|
|
|
GrPixelConfig config = GrColorTypeToPixelConfig(colorType, srgbEncoded);
|
2019-02-04 18:26:26 +00:00
|
|
|
if (!context->priv().caps()->isConfigTexturable(config)) {
|
2018-09-25 13:31:10 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-03-07 20:20:21 +00:00
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fConfig = config;
|
|
|
|
desc.fWidth = width;
|
|
|
|
desc.fHeight = height;
|
2019-05-13 14:40:06 +00:00
|
|
|
desc.fFlags = GrRenderable::kYes == renderable ? kRenderTarget_GrSurfaceFlag
|
|
|
|
: kNone_GrSurfaceFlags;
|
2019-02-04 18:26:26 +00:00
|
|
|
proxy = context->priv().proxyProvider()->createProxy(
|
2018-11-16 20:43:41 +00:00
|
|
|
format, desc, origin, SkBackingFit::kExact, SkBudgeted::kYes);
|
2018-03-07 20:20:21 +00:00
|
|
|
if (!proxy) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-03-07 18:01:25 +00:00
|
|
|
}
|
2019-05-13 14:40:06 +00:00
|
|
|
|
2019-02-04 18:26:26 +00:00
|
|
|
auto sContext = context->priv().makeWrappedSurfaceContext(proxy, nullptr);
|
2018-03-07 18:01:25 +00:00
|
|
|
if (!sContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-02-04 18:26:26 +00:00
|
|
|
if (!context->priv().writeSurfacePixels(sContext.get(), 0, 0, width, height, colorType,
|
|
|
|
nullptr, data, rowBytes)) {
|
2018-03-07 18:01:25 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return proxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace sk_gpu_test
|