Coverage Report

Created: 2024-05-20 07:14

/src/skia/tools/gpu/ProxyUtils.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
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
8
#include "tools/gpu/ProxyUtils.h"
9
10
#include "include/core/SkColor.h"
11
#include "include/gpu/GrBackendSurface.h"
12
#include "include/gpu/GrDirectContext.h"
13
#include "include/private/gpu/ganesh/GrImageContext.h"
14
#include "src/gpu/ganesh/GrDirectContextPriv.h"
15
#include "src/gpu/ganesh/GrDrawingManager.h"
16
#include "src/gpu/ganesh/GrGpu.h"
17
#include "src/gpu/ganesh/GrImageContextPriv.h"
18
#include "src/gpu/ganesh/GrPixmap.h"
19
#include "src/gpu/ganesh/GrProgramInfo.h"
20
#include "src/gpu/ganesh/GrProxyProvider.h"
21
#include "src/gpu/ganesh/SkGr.h"
22
#include "src/gpu/ganesh/SurfaceContext.h"
23
#include "src/gpu/ganesh/image/GrImageUtils.h"
24
#include "src/image/SkImage_Base.h"
25
26
#if defined(SK_GANESH)
27
#include "src/gpu/ganesh/ops/GrSimpleMeshDrawOpHelper.h"
28
#endif
29
30
namespace sk_gpu_test {
31
32
0
GrTextureProxy* GetTextureImageProxy(SkImage* image, GrRecordingContext* rContext) {
33
0
    if (!as_IB(image)->isGaneshBacked() || as_IB(image)->isYUVA()) {
34
0
        return nullptr;
35
0
    }
36
0
    if (!rContext) {
37
        // If the image is backed by a recording context we'll use that.
38
0
        GrImageContext* iContext = as_IB(image)->context();
39
0
        SkASSERT(iContext);
40
0
        rContext = iContext->priv().asRecordingContext();
41
0
        if (!rContext) {
42
0
            return nullptr;
43
0
        }
44
0
    }
45
0
    auto [view, ct] = skgpu::ganesh::AsView(rContext, image, skgpu::Mipmapped::kNo);
46
0
    if (!view) {
47
        // With the above checks we expect this to succeed unless there is a context mismatch.
48
0
        SkASSERT(!image->isValid(rContext));
49
0
        return nullptr;
50
0
    }
51
0
    GrSurfaceProxy* proxy = view.proxy();
52
0
    SkASSERT(proxy->asTextureProxy());
53
0
    return proxy->asTextureProxy();
54
0
}
Unexecuted instantiation: sk_gpu_test::GetTextureImageProxy(SkImage*, GrRecordingContext*)
Unexecuted instantiation: sk_gpu_test::GetTextureImageProxy(SkImage*, GrRecordingContext*)
55
56
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext* dContext,
57
                                                GrRenderable renderable,
58
                                                GrSurfaceOrigin origin,
59
0
                                                GrCPixmap pixmap) {
60
0
    if (dContext->abandoned()) {
61
0
        return {};
62
0
    }
63
64
0
    const GrCaps* caps = dContext->priv().caps();
65
66
0
    const GrBackendFormat format = caps->getDefaultBackendFormat(pixmap.colorType(), renderable);
67
0
    if (!format.isValid()) {
68
0
        return {};
69
0
    }
70
0
    skgpu::Swizzle swizzle = caps->getReadSwizzle(format, pixmap.colorType());
71
72
0
    sk_sp<GrTextureProxy> proxy;
73
0
    proxy = dContext->priv().proxyProvider()->createProxy(format,
74
0
                                                          pixmap.dimensions(),
75
0
                                                          renderable,
76
0
                                                          /*sample count*/ 1,
77
0
                                                          skgpu::Mipmapped::kNo,
78
0
                                                          SkBackingFit::kExact,
79
0
                                                          skgpu::Budgeted::kYes,
80
0
                                                          GrProtected::kNo,
81
0
                                                          /*label=*/"TextureProxyViewFromData");
82
0
    if (!proxy) {
83
0
        return {};
84
0
    }
85
0
    GrSurfaceProxyView view(proxy, origin, swizzle);
86
0
    auto sContext = dContext->priv().makeSC(std::move(view), pixmap.colorInfo());
87
0
    if (!sContext) {
88
0
        return {};
89
0
    }
90
0
    if (!sContext->writePixels(dContext, pixmap, {0, 0})) {
91
0
        return {};
92
0
    }
93
0
    return sContext->readSurfaceView();
94
0
}
95
96
#if defined(SK_GANESH)
97
GrProgramInfo* CreateProgramInfo(const GrCaps* caps,
98
                                 SkArenaAlloc* arena,
99
                                 const GrSurfaceProxyView& writeView,
100
                                 bool usesMSAASurface,
101
                                 GrAppliedClip&& appliedClip,
102
                                 const GrDstProxyView& dstProxyView,
103
                                 GrGeometryProcessor* geomProc,
104
                                 SkBlendMode blendMode,
105
                                 GrPrimitiveType primitiveType,
106
                                 GrXferBarrierFlags renderPassXferBarriers,
107
                                 GrLoadOp colorLoadOp,
108
                                 GrPipeline::InputFlags flags,
109
0
                                 const GrUserStencilSettings* stencilSettings) {
110
111
0
    GrProcessorSet processors = GrProcessorSet(blendMode);
112
113
0
    SkPMColor4f analysisColor = { 0, 0, 0, 1 }; // opaque black
114
115
0
    SkDEBUGCODE(auto analysis =) processors.finalize(analysisColor,
116
0
                                                     GrProcessorAnalysisCoverage::kSingleChannel,
117
0
                                                     &appliedClip, stencilSettings, *caps,
118
0
                                                     GrClampType::kAuto, &analysisColor);
119
0
    SkASSERT(!analysis.requiresDstTexture());
120
121
0
    return GrSimpleMeshDrawOpHelper::CreateProgramInfo(caps, arena, writeView, usesMSAASurface,
122
0
                                                       std::move(appliedClip), dstProxyView,
123
0
                                                       geomProc, std::move(processors),
124
0
                                                       primitiveType, renderPassXferBarriers,
125
0
                                                       colorLoadOp, flags, stencilSettings);
126
0
}
Unexecuted instantiation: sk_gpu_test::CreateProgramInfo(GrCaps const*, SkArenaAlloc*, GrSurfaceProxyView const&, bool, GrAppliedClip&&, GrDstProxyView const&, GrGeometryProcessor*, SkBlendMode, GrPrimitiveType, GrXferBarrierFlags, GrLoadOp, GrPipeline::InputFlags, GrUserStencilSettings const*)
Unexecuted instantiation: sk_gpu_test::CreateProgramInfo(GrCaps const*, SkArenaAlloc*, GrSurfaceProxyView const&, bool, GrAppliedClip&&, GrDstProxyView const&, GrGeometryProcessor*, SkBlendMode, GrPrimitiveType, GrXferBarrierFlags, GrLoadOp, GrPipeline::InputFlags, GrUserStencilSettings const*)
127
#endif // defined(SK_GANESH)
128
129
}  // namespace sk_gpu_test