blob: c5be111ce64a75a905f7d1be2ebdfcea72666f7d [file] [log] [blame]
Brian Salomon58389b92018-03-07 13:01:25 -05001/*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Robert Phillips34cea002019-11-21 16:02:34 -05008#include "include/core/SkColor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "include/gpu/GrBackendSurface.h"
10#include "src/gpu/GrContextPriv.h"
11#include "src/gpu/GrDrawingManager.h"
12#include "src/gpu/GrGpu.h"
Brian Salomonf2ebdd92019-09-30 12:15:30 -040013#include "src/gpu/GrImageInfo.h"
Robert Phillips34cea002019-11-21 16:02:34 -050014#include "src/gpu/GrProgramInfo.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/gpu/GrProxyProvider.h"
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040016#include "src/gpu/SkGr.h"
Robert Phillipsac6156c2020-02-28 16:02:40 -050017#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "tools/gpu/ProxyUtils.h"
Brian Salomon58389b92018-03-07 13:01:25 -050019
20namespace sk_gpu_test {
21
Brian Salomone7499c72019-06-24 12:12:36 -040022sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context,
23 GrRenderable renderable,
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040024 GrSurfaceOrigin origin,
Brian Salomon4eda7102019-10-21 15:04:52 -040025 const GrImageInfo& imageInfo,
26 const void* data,
27 size_t rowBytes) {
Robert Phillips69893702019-02-22 11:16:30 -050028 if (context->priv().abandoned()) {
Robert Phillips6d363702018-06-25 08:53:09 -040029 return nullptr;
30 }
31
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040032 const GrCaps* caps = context->priv().caps();
33
Brian Salomon4eda7102019-10-21 15:04:52 -040034 const GrBackendFormat format = caps->getDefaultBackendFormat(imageInfo.colorType(), renderable);
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040035 if (!format.isValid()) {
36 return nullptr;
37 }
Greg Daniel47c20e82020-01-21 14:29:57 -050038 GrSwizzle swizzle = caps->getReadSwizzle(format, imageInfo.colorType());
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040039
Brian Salomon02bd2952018-03-07 15:20:21 -050040 sk_sp<GrTextureProxy> proxy;
Brian Salomondf1bd6d2020-03-26 20:37:01 -040041 proxy = context->priv().proxyProvider()->createProxy(format, imageInfo.dimensions(), renderable,
42 1, GrMipMapped::kNo, SkBackingFit::kExact,
43 SkBudgeted::kYes, GrProtected::kNo);
Brian Salomon4eda7102019-10-21 15:04:52 -040044 if (!proxy) {
45 return nullptr;
Brian Salomon58389b92018-03-07 13:01:25 -050046 }
Greg Daniel3912a4b2020-01-14 09:56:04 -050047 GrSurfaceProxyView view(proxy, origin, swizzle);
48 auto sContext = GrSurfaceContext::Make(context, std::move(view), imageInfo.colorType(),
Greg Danielbfa19c42019-12-19 16:41:40 -050049 imageInfo.alphaType(), imageInfo.refColorSpace());
Brian Salomon58389b92018-03-07 13:01:25 -050050 if (!sContext) {
51 return nullptr;
52 }
Brian Salomon4eda7102019-10-21 15:04:52 -040053 if (!sContext->writePixels(imageInfo, data, rowBytes, {0, 0}, context)) {
Brian Salomon58389b92018-03-07 13:01:25 -050054 return nullptr;
55 }
56 return proxy;
57}
58
Robert Phillips34cea002019-11-21 16:02:34 -050059GrProgramInfo* CreateProgramInfo(const GrCaps* caps,
60 SkArenaAlloc* arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -040061 const GrSurfaceProxyView* writeView,
Robert Phillips34cea002019-11-21 16:02:34 -050062 GrAppliedClip&& appliedClip,
63 const GrXferProcessor::DstProxyView& dstProxyView,
64 GrGeometryProcessor* geomProc,
65 SkBlendMode blendMode,
66 GrPrimitiveType primitiveType,
67 GrPipeline::InputFlags flags,
Robert Phillipsac6156c2020-02-28 16:02:40 -050068 const GrUserStencilSettings* stencilSettings) {
Robert Phillips34cea002019-11-21 16:02:34 -050069
70 GrProcessorSet processors = GrProcessorSet(blendMode);
71
72 SkPMColor4f analysisColor = { 0, 0, 0, 1 }; // opaque black
73
74 SkDEBUGCODE(auto analysis =) processors.finalize(analysisColor,
Greg Danielf6d60d32020-01-08 13:39:16 -050075 GrProcessorAnalysisCoverage::kSingleChannel,
Robert Phillipsac6156c2020-02-28 16:02:40 -050076 &appliedClip, stencilSettings, false,
Robert Phillips34cea002019-11-21 16:02:34 -050077 *caps, GrClampType::kAuto, &analysisColor);
78 SkASSERT(!analysis.requiresDstTexture());
79
Brian Salomon8afde5f2020-04-01 16:22:00 -040080 return GrSimpleMeshDrawOpHelper::CreateProgramInfo(caps, arena, writeView,
Robert Phillipsac6156c2020-02-28 16:02:40 -050081 std::move(appliedClip), dstProxyView,
82 geomProc, std::move(processors),
83 primitiveType, flags, stencilSettings);
Robert Phillips34cea002019-11-21 16:02:34 -050084}
85
86
Brian Salomon58389b92018-03-07 13:01:25 -050087} // namespace sk_gpu_test