blob: a5a01bf12e1d09e6c6f3ac45e5ef9d23ca6183ec [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"
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040010#include "include/gpu/GrDirectContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrContextPriv.h"
12#include "src/gpu/GrDrawingManager.h"
13#include "src/gpu/GrGpu.h"
Brian Salomonf2ebdd92019-09-30 12:15:30 -040014#include "src/gpu/GrImageInfo.h"
Robert Phillips34cea002019-11-21 16:02:34 -050015#include "src/gpu/GrProgramInfo.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/gpu/GrProxyProvider.h"
Robert Phillipse19babf2020-04-06 13:57:30 -040017#include "src/gpu/GrSurfaceContext.h"
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040018#include "src/gpu/SkGr.h"
Robert Phillipsac6156c2020-02-28 16:02:40 -050019#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "tools/gpu/ProxyUtils.h"
Brian Salomon58389b92018-03-07 13:01:25 -050021
22namespace sk_gpu_test {
23
Brian Salomone7499c72019-06-24 12:12:36 -040024sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context,
25 GrRenderable renderable,
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040026 GrSurfaceOrigin origin,
Brian Salomon4eda7102019-10-21 15:04:52 -040027 const GrImageInfo& imageInfo,
28 const void* data,
29 size_t rowBytes) {
Robert Phillips9eb00022020-06-30 15:30:12 -040030 if (context->abandoned()) {
Robert Phillips6d363702018-06-25 08:53:09 -040031 return nullptr;
32 }
33
Robert Phillipsf8f45d92020-07-01 11:11:18 -040034 auto direct = context->asDirectContext();
Robert Phillips44333c52020-06-30 13:28:00 -040035 if (!direct) {
36 return nullptr;
37 }
38
39 const GrCaps* caps = direct->priv().caps();
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040040
Brian Salomon4eda7102019-10-21 15:04:52 -040041 const GrBackendFormat format = caps->getDefaultBackendFormat(imageInfo.colorType(), renderable);
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040042 if (!format.isValid()) {
43 return nullptr;
44 }
Greg Daniel47c20e82020-01-21 14:29:57 -050045 GrSwizzle swizzle = caps->getReadSwizzle(format, imageInfo.colorType());
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040046
Brian Salomon02bd2952018-03-07 15:20:21 -050047 sk_sp<GrTextureProxy> proxy;
Robert Phillips44333c52020-06-30 13:28:00 -040048 proxy = direct->priv().proxyProvider()->createProxy(format, imageInfo.dimensions(), renderable,
49 1, GrMipMapped::kNo, SkBackingFit::kExact,
50 SkBudgeted::kYes, GrProtected::kNo);
Brian Salomon4eda7102019-10-21 15:04:52 -040051 if (!proxy) {
52 return nullptr;
Brian Salomon58389b92018-03-07 13:01:25 -050053 }
Greg Daniel3912a4b2020-01-14 09:56:04 -050054 GrSurfaceProxyView view(proxy, origin, swizzle);
Robert Phillips44333c52020-06-30 13:28:00 -040055 auto sContext = GrSurfaceContext::Make(direct, std::move(view), imageInfo.colorType(),
Greg Danielbfa19c42019-12-19 16:41:40 -050056 imageInfo.alphaType(), imageInfo.refColorSpace());
Brian Salomon58389b92018-03-07 13:01:25 -050057 if (!sContext) {
58 return nullptr;
59 }
Robert Phillips44333c52020-06-30 13:28:00 -040060 if (!sContext->writePixels(imageInfo, data, rowBytes, {0, 0}, direct)) {
Brian Salomon58389b92018-03-07 13:01:25 -050061 return nullptr;
62 }
63 return proxy;
64}
65
Robert Phillips34cea002019-11-21 16:02:34 -050066GrProgramInfo* CreateProgramInfo(const GrCaps* caps,
67 SkArenaAlloc* arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -040068 const GrSurfaceProxyView* writeView,
Robert Phillips34cea002019-11-21 16:02:34 -050069 GrAppliedClip&& appliedClip,
70 const GrXferProcessor::DstProxyView& dstProxyView,
71 GrGeometryProcessor* geomProc,
72 SkBlendMode blendMode,
73 GrPrimitiveType primitiveType,
74 GrPipeline::InputFlags flags,
Robert Phillipsac6156c2020-02-28 16:02:40 -050075 const GrUserStencilSettings* stencilSettings) {
Robert Phillips34cea002019-11-21 16:02:34 -050076
77 GrProcessorSet processors = GrProcessorSet(blendMode);
78
79 SkPMColor4f analysisColor = { 0, 0, 0, 1 }; // opaque black
80
81 SkDEBUGCODE(auto analysis =) processors.finalize(analysisColor,
Greg Danielf6d60d32020-01-08 13:39:16 -050082 GrProcessorAnalysisCoverage::kSingleChannel,
Robert Phillipsac6156c2020-02-28 16:02:40 -050083 &appliedClip, stencilSettings, false,
Robert Phillips34cea002019-11-21 16:02:34 -050084 *caps, GrClampType::kAuto, &analysisColor);
85 SkASSERT(!analysis.requiresDstTexture());
86
Brian Salomon8afde5f2020-04-01 16:22:00 -040087 return GrSimpleMeshDrawOpHelper::CreateProgramInfo(caps, arena, writeView,
Robert Phillipsac6156c2020-02-28 16:02:40 -050088 std::move(appliedClip), dstProxyView,
89 geomProc, std::move(processors),
90 primitiveType, flags, stencilSettings);
Robert Phillips34cea002019-11-21 16:02:34 -050091}
92
93
Brian Salomon58389b92018-03-07 13:01:25 -050094} // namespace sk_gpu_test