blob: 633467cbd557747df057f54f0c9737e37b02701c [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 Phillipse19babf2020-04-06 13:57:30 -040016#include "src/gpu/GrSurfaceContext.h"
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040017#include "src/gpu/SkGr.h"
Robert Phillipsac6156c2020-02-28 16:02:40 -050018#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "tools/gpu/ProxyUtils.h"
Brian Salomon58389b92018-03-07 13:01:25 -050020
21namespace sk_gpu_test {
22
Brian Salomone7499c72019-06-24 12:12:36 -040023sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context,
24 GrRenderable renderable,
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040025 GrSurfaceOrigin origin,
Brian Salomon4eda7102019-10-21 15:04:52 -040026 const GrImageInfo& imageInfo,
27 const void* data,
28 size_t rowBytes) {
Robert Phillips69893702019-02-22 11:16:30 -050029 if (context->priv().abandoned()) {
Robert Phillips6d363702018-06-25 08:53:09 -040030 return nullptr;
31 }
32
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040033 const GrCaps* caps = context->priv().caps();
34
Brian Salomon4eda7102019-10-21 15:04:52 -040035 const GrBackendFormat format = caps->getDefaultBackendFormat(imageInfo.colorType(), renderable);
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040036 if (!format.isValid()) {
37 return nullptr;
38 }
Greg Daniel47c20e82020-01-21 14:29:57 -050039 GrSwizzle swizzle = caps->getReadSwizzle(format, imageInfo.colorType());
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040040
Brian Salomon02bd2952018-03-07 15:20:21 -050041 sk_sp<GrTextureProxy> proxy;
Brian Salomondf1bd6d2020-03-26 20:37:01 -040042 proxy = context->priv().proxyProvider()->createProxy(format, imageInfo.dimensions(), renderable,
43 1, GrMipMapped::kNo, SkBackingFit::kExact,
44 SkBudgeted::kYes, GrProtected::kNo);
Brian Salomon4eda7102019-10-21 15:04:52 -040045 if (!proxy) {
46 return nullptr;
Brian Salomon58389b92018-03-07 13:01:25 -050047 }
Greg Daniel3912a4b2020-01-14 09:56:04 -050048 GrSurfaceProxyView view(proxy, origin, swizzle);
49 auto sContext = GrSurfaceContext::Make(context, std::move(view), imageInfo.colorType(),
Greg Danielbfa19c42019-12-19 16:41:40 -050050 imageInfo.alphaType(), imageInfo.refColorSpace());
Brian Salomon58389b92018-03-07 13:01:25 -050051 if (!sContext) {
52 return nullptr;
53 }
Brian Salomon4eda7102019-10-21 15:04:52 -040054 if (!sContext->writePixels(imageInfo, data, rowBytes, {0, 0}, context)) {
Brian Salomon58389b92018-03-07 13:01:25 -050055 return nullptr;
56 }
57 return proxy;
58}
59
Robert Phillips34cea002019-11-21 16:02:34 -050060GrProgramInfo* CreateProgramInfo(const GrCaps* caps,
61 SkArenaAlloc* arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -040062 const GrSurfaceProxyView* writeView,
Robert Phillips34cea002019-11-21 16:02:34 -050063 GrAppliedClip&& appliedClip,
64 const GrXferProcessor::DstProxyView& dstProxyView,
65 GrGeometryProcessor* geomProc,
66 SkBlendMode blendMode,
67 GrPrimitiveType primitiveType,
68 GrPipeline::InputFlags flags,
Robert Phillipsac6156c2020-02-28 16:02:40 -050069 const GrUserStencilSettings* stencilSettings) {
Robert Phillips34cea002019-11-21 16:02:34 -050070
71 GrProcessorSet processors = GrProcessorSet(blendMode);
72
73 SkPMColor4f analysisColor = { 0, 0, 0, 1 }; // opaque black
74
75 SkDEBUGCODE(auto analysis =) processors.finalize(analysisColor,
Greg Danielf6d60d32020-01-08 13:39:16 -050076 GrProcessorAnalysisCoverage::kSingleChannel,
Robert Phillipsac6156c2020-02-28 16:02:40 -050077 &appliedClip, stencilSettings, false,
Robert Phillips34cea002019-11-21 16:02:34 -050078 *caps, GrClampType::kAuto, &analysisColor);
79 SkASSERT(!analysis.requiresDstTexture());
80
Brian Salomon8afde5f2020-04-01 16:22:00 -040081 return GrSimpleMeshDrawOpHelper::CreateProgramInfo(caps, arena, writeView,
Robert Phillipsac6156c2020-02-28 16:02:40 -050082 std::move(appliedClip), dstProxyView,
83 geomProc, std::move(processors),
84 primitiveType, flags, stencilSettings);
Robert Phillips34cea002019-11-21 16:02:34 -050085}
86
87
Brian Salomon58389b92018-03-07 13:01:25 -050088} // namespace sk_gpu_test