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