blob: 182aa24e6d572e793f423f813c429014539d5440 [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"
Adlai Hollera0693042020-10-14 11:23:11 -040011#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#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 Salomon652124c2020-08-12 14:06:50 -040024GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext* dContext,
25 GrRenderable renderable,
26 GrSurfaceOrigin origin,
27 const GrImageInfo& imageInfo,
28 const void* data,
29 size_t rowBytes) {
Adlai Hollerc95b5892020-08-11 12:02:22 -040030 if (dContext->abandoned()) {
Brian Salomon652124c2020-08-12 14:06:50 -040031 return {};
Robert Phillips44333c52020-06-30 13:28:00 -040032 }
33
Adlai Hollerc95b5892020-08-11 12:02:22 -040034 const GrCaps* caps = dContext->priv().caps();
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040035
Brian Salomon4eda7102019-10-21 15:04:52 -040036 const GrBackendFormat format = caps->getDefaultBackendFormat(imageInfo.colorType(), renderable);
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040037 if (!format.isValid()) {
Brian Salomon652124c2020-08-12 14:06:50 -040038 return {};
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040039 }
Greg Daniel47c20e82020-01-21 14:29:57 -050040 GrSwizzle swizzle = caps->getReadSwizzle(format, imageInfo.colorType());
Robert Phillips9dbcdcc2019-05-13 10:40:06 -040041
Brian Salomon02bd2952018-03-07 15:20:21 -050042 sk_sp<GrTextureProxy> proxy;
Adlai Hollerc95b5892020-08-11 12:02:22 -040043 proxy = dContext->priv().proxyProvider()->createProxy(format, imageInfo.dimensions(),
44 renderable, 1, GrMipmapped::kNo,
45 SkBackingFit::kExact, SkBudgeted::kYes,
46 GrProtected::kNo);
Brian Salomon4eda7102019-10-21 15:04:52 -040047 if (!proxy) {
Brian Salomon652124c2020-08-12 14:06:50 -040048 return {};
Brian Salomon58389b92018-03-07 13:01:25 -050049 }
Greg Daniel3912a4b2020-01-14 09:56:04 -050050 GrSurfaceProxyView view(proxy, origin, swizzle);
Adlai Hollerc95b5892020-08-11 12:02:22 -040051 auto sContext = GrSurfaceContext::Make(dContext, std::move(view), imageInfo.colorType(),
Greg Danielbfa19c42019-12-19 16:41:40 -050052 imageInfo.alphaType(), imageInfo.refColorSpace());
Brian Salomon58389b92018-03-07 13:01:25 -050053 if (!sContext) {
Brian Salomon652124c2020-08-12 14:06:50 -040054 return {};
Brian Salomon58389b92018-03-07 13:01:25 -050055 }
Adlai Hollerc95b5892020-08-11 12:02:22 -040056 if (!sContext->writePixels(dContext, imageInfo, data, rowBytes, {0, 0})) {
Brian Salomon652124c2020-08-12 14:06:50 -040057 return {};
Brian Salomon58389b92018-03-07 13:01:25 -050058 }
Brian Salomon652124c2020-08-12 14:06:50 -040059 return sContext->readSurfaceView();
Brian Salomon58389b92018-03-07 13:01:25 -050060}
61
Robert Phillips34cea002019-11-21 16:02:34 -050062GrProgramInfo* CreateProgramInfo(const GrCaps* caps,
63 SkArenaAlloc* arena,
Adlai Hollere2296f72020-11-19 13:41:26 -050064 const GrSurfaceProxyView& writeView,
Robert Phillips34cea002019-11-21 16:02:34 -050065 GrAppliedClip&& appliedClip,
66 const GrXferProcessor::DstProxyView& dstProxyView,
67 GrGeometryProcessor* geomProc,
68 SkBlendMode blendMode,
69 GrPrimitiveType primitiveType,
Greg Danield358cbe2020-09-11 09:33:54 -040070 GrXferBarrierFlags renderPassXferBarriers,
Greg Daniel42dbca52020-11-20 10:22:43 -050071 GrLoadOp colorLoadOp,
Robert Phillips34cea002019-11-21 16:02:34 -050072 GrPipeline::InputFlags flags,
Robert Phillipsac6156c2020-02-28 16:02:40 -050073 const GrUserStencilSettings* stencilSettings) {
Robert Phillips34cea002019-11-21 16:02:34 -050074
75 GrProcessorSet processors = GrProcessorSet(blendMode);
76
77 SkPMColor4f analysisColor = { 0, 0, 0, 1 }; // opaque black
78
79 SkDEBUGCODE(auto analysis =) processors.finalize(analysisColor,
Greg Danielf6d60d32020-01-08 13:39:16 -050080 GrProcessorAnalysisCoverage::kSingleChannel,
Robert Phillipsac6156c2020-02-28 16:02:40 -050081 &appliedClip, stencilSettings, false,
Robert Phillips34cea002019-11-21 16:02:34 -050082 *caps, GrClampType::kAuto, &analysisColor);
83 SkASSERT(!analysis.requiresDstTexture());
84
Brian Salomon8afde5f2020-04-01 16:22:00 -040085 return GrSimpleMeshDrawOpHelper::CreateProgramInfo(caps, arena, writeView,
Robert Phillipsac6156c2020-02-28 16:02:40 -050086 std::move(appliedClip), dstProxyView,
87 geomProc, std::move(processors),
Greg Daniel42dbca52020-11-20 10:22:43 -050088 primitiveType, renderPassXferBarriers,
89 colorLoadOp, flags, stencilSettings);
Robert Phillips34cea002019-11-21 16:02:34 -050090}
91
92
Brian Salomon58389b92018-03-07 13:01:25 -050093} // namespace sk_gpu_test