blob: 0bcdbbded08c7af6ef075b2b5ff8845d5205e2cd [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
Adlai Hollercf0d08e2020-08-11 12:36:10 +000024sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrDirectContext* direct,
Brian Salomone7499c72019-06-24 12:12:36 -040025 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) {
Adlai Hollercf0d08e2020-08-11 12:36:10 +000030 if (direct->abandoned()) {
Robert Phillips44333c52020-06-30 13:28:00 -040031 return nullptr;
32 }
33
Adlai Hollercf0d08e2020-08-11 12:36:10 +000034 const GrCaps* caps = direct->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()) {
38 return nullptr;
39 }
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 Hollercf0d08e2020-08-11 12:36:10 +000043 proxy = direct->priv().proxyProvider()->createProxy(format, imageInfo.dimensions(), renderable,
44 1, GrMipmapped::kNo, SkBackingFit::kExact,
45 SkBudgeted::kYes, GrProtected::kNo);
Brian Salomon4eda7102019-10-21 15:04:52 -040046 if (!proxy) {
47 return nullptr;
Brian Salomon58389b92018-03-07 13:01:25 -050048 }
Greg Daniel3912a4b2020-01-14 09:56:04 -050049 GrSurfaceProxyView view(proxy, origin, swizzle);
Adlai Hollercf0d08e2020-08-11 12:36:10 +000050 auto sContext = GrSurfaceContext::Make(direct, std::move(view), imageInfo.colorType(),
Greg Danielbfa19c42019-12-19 16:41:40 -050051 imageInfo.alphaType(), imageInfo.refColorSpace());
Brian Salomon58389b92018-03-07 13:01:25 -050052 if (!sContext) {
53 return nullptr;
54 }
Adlai Hollercf0d08e2020-08-11 12:36:10 +000055 if (!sContext->writePixels(imageInfo, data, rowBytes, {0, 0}, direct)) {
Brian Salomon58389b92018-03-07 13:01:25 -050056 return nullptr;
57 }
58 return proxy;
59}
60
Robert Phillips34cea002019-11-21 16:02:34 -050061GrProgramInfo* CreateProgramInfo(const GrCaps* caps,
62 SkArenaAlloc* arena,
Brian Salomon8afde5f2020-04-01 16:22:00 -040063 const GrSurfaceProxyView* writeView,
Robert Phillips34cea002019-11-21 16:02:34 -050064 GrAppliedClip&& appliedClip,
65 const GrXferProcessor::DstProxyView& dstProxyView,
66 GrGeometryProcessor* geomProc,
67 SkBlendMode blendMode,
68 GrPrimitiveType primitiveType,
69 GrPipeline::InputFlags flags,
Robert Phillipsac6156c2020-02-28 16:02:40 -050070 const GrUserStencilSettings* stencilSettings) {
Robert Phillips34cea002019-11-21 16:02:34 -050071
72 GrProcessorSet processors = GrProcessorSet(blendMode);
73
74 SkPMColor4f analysisColor = { 0, 0, 0, 1 }; // opaque black
75
76 SkDEBUGCODE(auto analysis =) processors.finalize(analysisColor,
Greg Danielf6d60d32020-01-08 13:39:16 -050077 GrProcessorAnalysisCoverage::kSingleChannel,
Robert Phillipsac6156c2020-02-28 16:02:40 -050078 &appliedClip, stencilSettings, false,
Robert Phillips34cea002019-11-21 16:02:34 -050079 *caps, GrClampType::kAuto, &analysisColor);
80 SkASSERT(!analysis.requiresDstTexture());
81
Brian Salomon8afde5f2020-04-01 16:22:00 -040082 return GrSimpleMeshDrawOpHelper::CreateProgramInfo(caps, arena, writeView,
Robert Phillipsac6156c2020-02-28 16:02:40 -050083 std::move(appliedClip), dstProxyView,
84 geomProc, std::move(processors),
85 primitiveType, flags, stencilSettings);
Robert Phillips34cea002019-11-21 16:02:34 -050086}
87
88
Brian Salomon58389b92018-03-07 13:01:25 -050089} // namespace sk_gpu_test