diff options
Diffstat (limited to 'tools/gpu')
-rw-r--r-- | tools/gpu/ProxyUtils.cpp | 40 | ||||
-rw-r--r-- | tools/gpu/ProxyUtils.h | 41 |
2 files changed, 81 insertions, 0 deletions
diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp new file mode 100644 index 0000000000..e02bf5fd26 --- /dev/null +++ b/tools/gpu/ProxyUtils.cpp @@ -0,0 +1,40 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "ProxyUtils.h" +#include "GrContextPriv.h" +#include "GrDrawingManager.h" +#include "GrProxyProvider.h" + +namespace sk_gpu_test { + +sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, bool isRT, int width, int height, + GrColorType ct, GrSRGBEncoded srgbEncoded, + GrSurfaceOrigin origin, const void* data, + size_t rowBytes) { + GrSurfaceDesc desc; + desc.fConfig = GrColorTypeToPixelConfig(ct, srgbEncoded); + desc.fWidth = width; + desc.fHeight = height; + desc.fFlags = isRT ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags; + auto proxy = context->contextPriv().proxyProvider()->createProxy( + desc, origin, SkBackingFit::kExact, SkBudgeted::kYes); + if (!proxy) { + return nullptr; + } + auto sContext = context->contextPriv().makeWrappedSurfaceContext(proxy, nullptr); + if (!sContext) { + return nullptr; + } + if (!context->contextPriv().writeSurfacePixels(sContext.get(), 0, 0, width, height, ct, nullptr, + data, rowBytes)) { + return nullptr; + } + return proxy; +} + +} // namespace sk_gpu_test diff --git a/tools/gpu/ProxyUtils.h b/tools/gpu/ProxyUtils.h new file mode 100644 index 0000000000..6dfcd713f8 --- /dev/null +++ b/tools/gpu/ProxyUtils.h @@ -0,0 +1,41 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef ProxyUtils_DEFINED +#define ProxyUtils_DEFINED + +#include "GrTextureProxy.h" +#include "GrTypesPriv.h" + +namespace sk_gpu_test { + +/** Makes a texture proxy containing the passed in color data. */ +sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, bool isRT, int width, int height, + GrColorType, GrSRGBEncoded, GrSurfaceOrigin, + const void* data, size_t rowBytes); + +/** Version that assumes GrSRGBEncoded::kNo. */ +inline sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, bool isRT, int width, + int height, GrColorType ct, + GrSurfaceOrigin origin, const void* data, + size_t rowBytes) { + return MakeTextureProxyFromData(context, isRT, width, height, ct, GrSRGBEncoded::kNo, origin, + data, rowBytes); +} + +/** Version that takes SkColorType rather than GrColorType and assumes GrSRGBEncoded::kNo. */ +inline sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, bool isRT, int width, + int height, SkColorType ct, + GrSurfaceOrigin origin, const void* data, + size_t rowBytes) { + return MakeTextureProxyFromData(context, isRT, width, height, SkColorTypeToGrColorType(ct), + origin, data, rowBytes); +} + +} // namespace sk_gpu_test + +#endif |