blob: 7c65774f09244f788fa5f75e2a75e30a346c4c23 [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
Brian Salomondd4087d2020-12-23 20:36:44 -05008#include "tools/gpu/ProxyUtils.h"
9
Robert Phillips34cea002019-11-21 16:02:34 -050010#include "include/core/SkColor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrBackendSurface.h"
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040012#include "include/gpu/GrDirectContext.h"
Adlai Hollera0693042020-10-14 11:23:11 -040013#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrDrawingManager.h"
15#include "src/gpu/GrGpu.h"
Brian Salomondd4087d2020-12-23 20:36:44 -050016#include "src/gpu/GrPixmap.h"
Robert Phillips34cea002019-11-21 16:02:34 -050017#include "src/gpu/GrProgramInfo.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "src/gpu/GrProxyProvider.h"
Robert Phillipse19babf2020-04-06 13:57:30 -040019#include "src/gpu/GrSurfaceContext.h"
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040020#include "src/gpu/SkGr.h"
Robert Phillipsac6156c2020-02-28 16:02:40 -050021#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
Brian Salomon58389b92018-03-07 13:01:25 -050022
23namespace sk_gpu_test {
24
Brian Salomon652124c2020-08-12 14:06:50 -040025GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext* dContext,
26 GrRenderable renderable,
27 GrSurfaceOrigin origin,
Brian Salomondd4087d2020-12-23 20:36:44 -050028 GrPixmap pixmap) {
Adlai Hollerc95b5892020-08-11 12:02:22 -040029 if (dContext->abandoned()) {
Brian Salomon652124c2020-08-12 14:06:50 -040030 return {};
Robert Phillips44333c52020-06-30 13:28:00 -040031 }
32
Adlai Hollerc95b5892020-08-11 12:02:22 -040033 const GrCaps* caps = dContext->priv().caps();
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040034
Brian Salomondd4087d2020-12-23 20:36:44 -050035 const GrBackendFormat format = caps->getDefaultBackendFormat(pixmap.colorType(), renderable);
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040036 if (!format.isValid()) {
Brian Salomon652124c2020-08-12 14:06:50 -040037 return {};
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040038 }
Brian Salomondd4087d2020-12-23 20:36:44 -050039 GrSwizzle swizzle = caps->getReadSwizzle(format, pixmap.colorType());
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040040
Brian Salomon02bd2952018-03-07 15:20:21 -050041 sk_sp<GrTextureProxy> proxy;
Brian Salomondd4087d2020-12-23 20:36:44 -050042 proxy = dContext->priv().proxyProvider()->createProxy(format,
43 pixmap.dimensions(),
44 renderable,
45 /*sample count*/ 1,
46 GrMipmapped::kNo,
47 SkBackingFit::kExact,
48 SkBudgeted::kYes,
Adlai Hollerc95b5892020-08-11 12:02:22 -040049 GrProtected::kNo);
Brian Salomon4eda7102019-10-21 15:04:52 -040050 if (!proxy) {
Brian Salomon652124c2020-08-12 14:06:50 -040051 return {};
Brian Salomon58389b92018-03-07 13:01:25 -050052 }
Greg Daniel3912a4b2020-01-14 09:56:04 -050053 GrSurfaceProxyView view(proxy, origin, swizzle);
Brian Salomondd4087d2020-12-23 20:36:44 -050054 auto sContext = GrSurfaceContext::Make(dContext, std::move(view), pixmap.colorInfo());
Brian Salomon58389b92018-03-07 13:01:25 -050055 if (!sContext) {
Brian Salomon652124c2020-08-12 14:06:50 -040056 return {};
Brian Salomon58389b92018-03-07 13:01:25 -050057 }
Brian Salomondd4087d2020-12-23 20:36:44 -050058 if (!sContext->writePixels(dContext, pixmap, {0, 0})) {
Brian Salomon652124c2020-08-12 14:06:50 -040059 return {};
Brian Salomon58389b92018-03-07 13:01:25 -050060 }
Brian Salomon652124c2020-08-12 14:06:50 -040061 return sContext->readSurfaceView();
Brian Salomon58389b92018-03-07 13:01:25 -050062}
63
Robert Phillips34cea002019-11-21 16:02:34 -050064GrProgramInfo* CreateProgramInfo(const GrCaps* caps,
65 SkArenaAlloc* arena,
Adlai Hollere2296f72020-11-19 13:41:26 -050066 const GrSurfaceProxyView& writeView,
Robert Phillips34cea002019-11-21 16:02:34 -050067 GrAppliedClip&& appliedClip,
68 const GrXferProcessor::DstProxyView& dstProxyView,
69 GrGeometryProcessor* geomProc,
70 SkBlendMode blendMode,
71 GrPrimitiveType primitiveType,
Greg Danield358cbe2020-09-11 09:33:54 -040072 GrXferBarrierFlags renderPassXferBarriers,
Greg Daniel42dbca52020-11-20 10:22:43 -050073 GrLoadOp colorLoadOp,
Robert Phillips34cea002019-11-21 16:02:34 -050074 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),
Greg Daniel42dbca52020-11-20 10:22:43 -050090 primitiveType, renderPassXferBarriers,
91 colorLoadOp, flags, stencilSettings);
Robert Phillips34cea002019-11-21 16:02:34 -050092}
93
94
Brian Salomon58389b92018-03-07 13:01:25 -050095} // namespace sk_gpu_test