Flutter Engine
The Flutter Engine
BackendTextureImageFactory.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
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
15
16#ifdef SK_GANESH
20#endif
21
22#ifdef SK_GRAPHITE
27#endif
28
29namespace sk_gpu_test {
30#ifdef SK_GANESH
31sk_sp<SkImage> MakeBackendTextureImage(GrDirectContext* dContext,
32 const SkPixmap& pixmap,
33 Renderable renderable,
34 GrSurfaceOrigin origin,
35 Protected isProtected) {
36 auto mbet = ManagedBackendTexture::MakeWithData(dContext,
37 pixmap,
38 origin,
39 renderable,
40 isProtected);
41 if (!mbet) {
42 return nullptr;
43 }
44 return SkImages::BorrowTextureFrom(dContext,
45 mbet->texture(),
46 origin,
47 pixmap.colorType(),
48 pixmap.alphaType(),
49 pixmap.refColorSpace(),
50 ManagedBackendTexture::ReleaseProc,
51 mbet->releaseContext());
52}
53
54sk_sp<SkImage> MakeBackendTextureImage(GrDirectContext* dContext,
55 const SkImageInfo& info,
57 Mipmapped mipmapped,
58 Renderable renderable,
59 GrSurfaceOrigin origin,
60 Protected isProtected) {
61 if (info.alphaType() == kOpaque_SkAlphaType) {
62 color = color.makeOpaque();
63 } else if (info.alphaType() == kPremul_SkAlphaType) {
64 auto pmColor = color.premul();
65 color = {pmColor.fR, pmColor.fG, pmColor.fB, pmColor.fA};
66 }
67 auto mbet = ManagedBackendTexture::MakeWithData(dContext,
68 info.width(),
69 info.height(),
70 info.colorType(),
71 color,
72 mipmapped,
73 renderable,
74 isProtected);
75 if (!mbet) {
76 return nullptr;
77 }
78 return SkImages::BorrowTextureFrom(dContext,
79 mbet->texture(),
80 origin,
81 info.colorType(),
82 info.alphaType(),
83 info.refColorSpace(),
84 ManagedBackendTexture::ReleaseProc,
85 mbet->releaseContext());
86}
87#endif // SK_GANESH
88
89#ifdef SK_GRAPHITE
91sk_sp<SkImage> MakeBackendTextureImage(Recorder* recorder,
92 const SkPixmap& pixmap,
93 skgpu::Mipmapped isMipmapped,
94 Renderable isRenderable,
95 Origin origin,
96 Protected isProtected) {
97 auto mbet = ManagedGraphiteTexture::MakeFromPixmap(recorder,
98 pixmap,
99 isMipmapped,
100 isRenderable,
101 isProtected);
102 if (!mbet) {
103 return nullptr;
104 }
105
106 return SkImages::WrapTexture(recorder,
107 mbet->texture(),
108 pixmap.colorType(),
109 pixmap.alphaType(),
110 pixmap.refColorSpace(),
111 origin,
112 sk_gpu_test::ManagedGraphiteTexture::ImageReleaseProc,
113 mbet->releaseContext());
114}
115
116sk_sp<SkImage> MakeBackendTextureImage(Recorder* recorder,
117 const SkImageInfo& ii,
119 skgpu::Mipmapped isMipmapped,
120 Renderable isRenderable,
121 Origin origin,
122 Protected isProtected) {
123 if (ii.alphaType() == kOpaque_SkAlphaType) {
124 color = color.makeOpaque();
125 }
126
128 bitmap.allocPixels(ii);
129
130 bitmap.eraseColor(color);
131
132 return MakeBackendTextureImage(recorder, bitmap.pixmap(), isMipmapped, isRenderable,
133 origin, isProtected);
134}
135#endif // SK_GRAPHITE
136
137} // namespace sk_gpu_test
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
GrSurfaceOrigin
Definition: GrTypes.h:147
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
SkColorType colorType() const
Definition: SkPixmap.h:173
sk_sp< SkColorSpace > refColorSpace() const
Definition: SkPixmap.cpp:63
SkAlphaType alphaType() const
Definition: SkPixmap.h:175
DlColor color
SK_API sk_sp< SkImage > WrapTexture(skgpu::graphite::Recorder *, const skgpu::graphite::BackendTexture &, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, skgpu::Origin origin, GenerateMipmapsFromBase generateMipmapsFromBase, TextureReleaseProc=nullptr, ReleaseContext=nullptr, std::string_view label={})
SK_API sk_sp< SkImage > BorrowTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
SK_API sk_sp< SkPixelRef > MakeWithData(const SkImageInfo &, size_t rowBytes, sk_sp< SkData > data)
Definition: bitmap.py:1
Origin
Definition: GpuTypes.h:77
Renderable
Definition: GpuTypes.h:69
Mipmapped
Definition: GpuTypes.h:53
Protected
Definition: GpuTypes.h:61
SkAlphaType alphaType() const
Definition: SkImageInfo.h:375
skgpu::graphite::Recorder Recorder