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-06-24 16:12:36 +00:00
|
|
|
sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context,
|
|
|
|
GrRenderable renderable,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
GrColorType colorType, SkAlphaType alphaType,
|
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();
|
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
const GrBackendFormat format = caps->getDefaultBackendFormat(colorType, renderable);
|
2019-05-13 14:40:06 +00:00
|
|
|
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-06-04 15:03:06 +00:00
|
|
|
auto backendTex = context->createBackendTexture(
|
2019-07-01 19:04:06 +00:00
|
|
|
width, height, format, SkColors::kTransparent, GrMipMapped::kNo, renderable,
|
|
|
|
GrProtected::kNo);
|
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-07-16 11:47:56 +00:00
|
|
|
backendTex, origin, 1, colorType, 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-07-23 14:27:09 +00:00
|
|
|
backendTex, colorType, origin, kAdopt_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kNo, kRW_GrIOType);
|
2018-03-07 20:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!proxy) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2018-03-07 20:20:21 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
GrSurfaceDesc desc;
|
2019-08-14 18:23:53 +00:00
|
|
|
desc.fConfig = GrColorTypeToPixelConfig(colorType);
|
2018-03-07 20:20:21 +00:00
|
|
|
desc.fWidth = width;
|
|
|
|
desc.fHeight = height;
|
2019-07-22 18:23:45 +00:00
|
|
|
proxy = context->priv().proxyProvider()->createProxy(format, desc, renderable, 1, origin,
|
2019-08-30 20:19:42 +00:00
|
|
|
GrMipMapped::kNo, SkBackingFit::kExact,
|
|
|
|
SkBudgeted::kYes, GrProtected::kNo);
|
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-06-24 19:50:07 +00:00
|
|
|
auto sContext = context->priv().makeWrappedSurfaceContext(proxy, colorType, alphaType, nullptr);
|
2018-03-07 18:01:25 +00:00
|
|
|
if (!sContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-07-01 17:05:28 +00:00
|
|
|
if (!sContext->writePixels({colorType, alphaType, nullptr, width, height}, data, rowBytes,
|
|
|
|
{0, 0}, context)) {
|
2018-03-07 18:01:25 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return proxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace sk_gpu_test
|