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