Flutter Engine
The Flutter Engine
ProxyUtils.cpp
Go to the documentation of this file.
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
9
21#include "src/gpu/ganesh/SkGr.h"
25
26#if defined(SK_GANESH)
28#endif
29
30namespace sk_gpu_test {
31
33 if (!as_IB(image)->isGaneshBacked() || as_IB(image)->isYUVA()) {
34 return nullptr;
35 }
36 if (!rContext) {
37 // If the image is backed by a recording context we'll use that.
38 GrImageContext* iContext = as_IB(image)->context();
39 SkASSERT(iContext);
40 rContext = iContext->priv().asRecordingContext();
41 if (!rContext) {
42 return nullptr;
43 }
44 }
45 auto [view, ct] = skgpu::ganesh::AsView(rContext, image, skgpu::Mipmapped::kNo);
46 if (!view) {
47 // With the above checks we expect this to succeed unless there is a context mismatch.
48 SkASSERT(!image->isValid(rContext));
49 return nullptr;
50 }
51 GrSurfaceProxy* proxy = view.proxy();
52 SkASSERT(proxy->asTextureProxy());
53 return proxy->asTextureProxy();
54}
55
57 GrRenderable renderable,
58 GrSurfaceOrigin origin,
59 GrCPixmap pixmap) {
60 if (dContext->abandoned()) {
61 return {};
62 }
63
64 const GrCaps* caps = dContext->priv().caps();
65
66 const GrBackendFormat format = caps->getDefaultBackendFormat(pixmap.colorType(), renderable);
67 if (!format.isValid()) {
68 return {};
69 }
70 skgpu::Swizzle swizzle = caps->getReadSwizzle(format, pixmap.colorType());
71
73 proxy = dContext->priv().proxyProvider()->createProxy(format,
74 pixmap.dimensions(),
75 renderable,
76 /*sample count*/ 1,
81 /*label=*/"TextureProxyViewFromData");
82 if (!proxy) {
83 return {};
84 }
85 GrSurfaceProxyView view(proxy, origin, swizzle);
86 auto sContext = dContext->priv().makeSC(std::move(view), pixmap.colorInfo());
87 if (!sContext) {
88 return {};
89 }
90 if (!sContext->writePixels(dContext, pixmap, {0, 0})) {
91 return {};
92 }
93 return sContext->readSurfaceView();
94}
95
96#if defined(SK_GANESH)
97GrProgramInfo* 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,
109 const GrUserStencilSettings* stencilSettings) {
110
111 GrProcessorSet processors = GrProcessorSet(blendMode);
112
113 SkPMColor4f analysisColor = { 0, 0, 0, 1 }; // opaque black
114
115 SkDEBUGCODE(auto analysis =) processors.finalize(analysisColor,
116 GrProcessorAnalysisCoverage::kSingleChannel,
117 &appliedClip, stencilSettings, *caps,
118 GrClampType::kAuto, &analysisColor);
119 SkASSERT(!analysis.requiresDstTexture());
120
121 return GrSimpleMeshDrawOpHelper::CreateProgramInfo(caps, arena, writeView, usesMSAASurface,
122 std::move(appliedClip), dstProxyView,
123 geomProc, std::move(processors),
124 primitiveType, renderPassXferBarriers,
125 colorLoadOp, flags, stencilSettings);
126}
127#endif // defined(SK_GANESH)
128
129} // namespace sk_gpu_test
GrProcessorAnalysisCoverage
GrClampType
Definition: GrTypesPriv.h:228
GrPrimitiveType
Definition: GrTypesPriv.h:43
GrLoadOp
Definition: GrTypesPriv.h:155
GrSurfaceOrigin
Definition: GrTypes.h:147
GrXferBarrierFlags
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkBlendMode
Definition: SkBlendMode.h:38
static SkImage_Base * as_IB(SkImage *image)
Definition: SkImage_Base.h:201
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
GrRecordingContext * asRecordingContext()
const GrCaps * caps() const
Definition: GrCaps.h:57
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition: GrCaps.cpp:400
skgpu::Swizzle getReadSwizzle(const GrBackendFormat &format, GrColorType colorType) const
Definition: GrCaps.cpp:443
bool abandoned() override
GrDirectContextPriv priv()
GrImageContextPriv priv()
const GrColorInfo & colorInfo() const
Definition: GrPixmap.h:18
SkISize dimensions() const
Definition: GrPixmap.h:29
GrColorType colorType() const
Definition: GrPixmap.h:30
sk_sp< GrTextureProxy > createProxy(const GrBackendFormat &, SkISize dimensions, GrRenderable, int renderTargetSampleCnt, skgpu::Mipmapped, SkBackingFit, skgpu::Budgeted, GrProtected, std::string_view label, GrInternalSurfaceFlags=GrInternalSurfaceFlags::kNone, UseAllocator useAllocator=UseAllocator::kYes)
GrProxyProvider * proxyProvider()
std::unique_ptr< skgpu::ganesh::SurfaceContext > makeSC(GrSurfaceProxyView readView, const GrColorInfo &)
virtual GrTextureProxy * asTextureProxy()
virtual GrImageContext * context() const
Definition: SkImage_Base.h:112
virtual bool isValid(GrRecordingContext *context) const =0
FlutterSemanticsFlag flags
uint32_t uint32_t * format
sk_sp< const SkImage > image
Definition: SkRecords.h:269
GrTextureProxy * GetTextureImageProxy(SkImage *image, GrRecordingContext *rContext)
Definition: ProxyUtils.cpp:32
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext *dContext, GrRenderable renderable, GrSurfaceOrigin origin, GrCPixmap pixmap)
Definition: ProxyUtils.cpp:56
std::tuple< GrSurfaceProxyView, GrColorType > AsView(GrRecordingContext *rContext, const SkImage *img, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)
Renderable
Definition: GpuTypes.h:69
Definition: ref_ptr.h:256