Flutter Engine
The Flutter Engine
Classes | Functions
compressed_textures.cpp File Reference
#include "include/core/SkTypes.h"
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkData.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPath.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTextureCompressionType.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "src/core/SkCompressedDataUtils.h"
#include "src/core/SkMipmap.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrDataUtils.h"
#include "src/gpu/ganesh/GrImageContextPriv.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "src/gpu/ganesh/image/SkImage_GaneshBase.h"
#include "src/image/SkImage_Base.h"
#include "third_party/etc1/etc1.h"
#include "tools/gpu/ProxyUtils.h"

Go to the source code of this file.

Classes

struct  CompressedImageObjects
 
class  CompressedTexturesGM
 

Functions

static SkPoint gen_pt (float angle, const SkVector &scale)
 
static SkPath make_gear (SkISize dimensions, int numTeeth)
 
SkBitmap render_level (SkISize dimensions, SkColor color, SkColorType colorType, bool opaque)
 
static CompressedImageObjects make_compressed_image (SkCanvas *canvas, const SkISize dimensions, SkColorType colorType, bool opaque, SkTextureCompressionType compression)
 

Function Documentation

◆ gen_pt()

static SkPoint gen_pt ( float  angle,
const SkVector scale 
)
static

Definition at line 48 of file compressed_textures.cpp.

48 {
49 SkScalar s = SkScalarSin(angle);
50 SkScalar c = SkScalarCos(angle);
51
52 return { scale.fX * c, scale.fY * s };
53}
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarCos(radians)
Definition: SkScalar.h:46
float SkScalar
Definition: extension.cpp:12
struct MyStruct s
const Scalar scale

◆ make_compressed_image()

static CompressedImageObjects make_compressed_image ( SkCanvas canvas,
const SkISize  dimensions,
SkColorType  colorType,
bool  opaque,
SkTextureCompressionType  compression 
)
static

Definition at line 122 of file compressed_textures.cpp.

126 {
127 size_t totalSize = SkCompressedDataSize(compression, dimensions, nullptr, true);
128
130 char* pixels = (char*) tmp->writable_data();
131
132 int numMipLevels = SkMipmap::ComputeLevelCount(dimensions.width(), dimensions.height()) + 1;
133
134 size_t offset = 0;
135
136 // Use a different color for each mipmap level so we can visually evaluate the draws
137 static const SkColor kColors[] = {
145 };
146
147 SkISize levelDims = dimensions;
148 for (int i = 0; i < numMipLevels; ++i) {
149 size_t levelSize = SkCompressedDataSize(compression, levelDims, nullptr, false);
150
151 SkBitmap bm = render_level(levelDims, kColors[i%7], colorType, opaque);
154 SkASSERT(opaque);
155
156 if (etc1_encode_image((unsigned char*)bm.getAddr16(0, 0),
157 bm.width(), bm.height(), 2, bm.rowBytes(),
158 (unsigned char*) &pixels[offset])) {
159 return {nullptr, nullptr};
160 }
161 } else {
162 GrTwoColorBC1Compress(bm.pixmap(), kColors[i%7], &pixels[offset]);
163 }
164
165 offset += levelSize;
166 levelDims = {std::max(1, levelDims.width()/2), std::max(1, levelDims.height()/2)};
167 }
168
170#if defined(SK_GRAPHITE)
171 skgpu::graphite::Recorder* recorder = canvas->recorder();
172 if (recorder) {
174 sk_gpu_test::ManagedGraphiteTexture::MakeFromCompressedData(recorder,
175 dimensions,
176 compression,
177 tmp,
179 if (texture) {
180 image = SkImages::WrapTexture(recorder,
181 texture->texture(),
184 /*colorSpace=*/nullptr);
185 if (image) {
186 return {image, texture};
187 }
188 }
189 }
190#endif
191 auto dContext = GrAsDirectContext(canvas->recordingContext());
192 if (dContext) {
194 std::move(tmp),
195 dimensions.width(),
196 dimensions.height(),
197 compression,
199 } else {
201 std::move(tmp), dimensions.width(), dimensions.height(), compression);
202 }
203 return {image, nullptr};
204}
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition: SkColorType.h:22
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
size_t SkCompressedDataSize(SkTextureCompressionType type, SkISize dimensions, TArray< size_t > *individualMipOffsets, bool mipmapped)
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
int width() const
Definition: SkBitmap.h:149
const SkPixmap & pixmap() const
Definition: SkBitmap.h:133
size_t rowBytes() const
Definition: SkBitmap.h:238
SkColorType colorType() const
Definition: SkBitmap.h:160
int height() const
Definition: SkBitmap.h:158
uint16_t * getAddr16(int x, int y) const
Definition: SkBitmap.h:1265
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
virtual skgpu::graphite::Recorder * recorder() const
Definition: SkCanvas.cpp:1641
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
void * writable_data()
Definition: SkData.h:52
static int ComputeLevelCount(int baseWidth, int baseHeight)
Definition: SkMipmap.cpp:134
SkBitmap render_level(SkISize dimensions, SkColor color, SkColorType colorType, bool opaque)
int etc1_encode_image(const etc1_byte *pIn, etc1_uint32 width, etc1_uint32 height, etc1_uint32 pixelSize, etc1_uint32 stride, etc1_byte *pOut)
Definition: etc1.cpp:517
static float max(float r, float g, float b)
Definition: hsl.cpp:49
FlTexture * texture
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 > TextureFromCompressedTextureData(GrDirectContext *direct, sk_sp< SkData > data, int width, int height, SkTextureCompressionType type, skgpu::Mipmapped mipmapped=skgpu::Mipmapped::kNo, GrProtected isProtected=GrProtected::kNo)
SK_API sk_sp< SkImage > RasterFromCompressedTextureData(sk_sp< SkData > data, int width, int height, SkTextureCompressionType type)
sk_sp< const SkImage > image
Definition: SkRecords.h:269
const DlColor kColors[]
static constexpr SkColorType CompressionTypeToSkColorType(SkTextureCompressionType compression)
Definition: GpuTypesPriv.h:30
SeparatedVector2 offset
Definition: SkSize.h:16
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37

◆ make_gear()

static SkPath make_gear ( SkISize  dimensions,
int  numTeeth 
)
static

Definition at line 56 of file compressed_textures.cpp.

56 {
57 SkVector outerRad{ dimensions.fWidth / 2.0f, dimensions.fHeight / 2.0f };
58 SkVector innerRad{ dimensions.fWidth / 2.5f, dimensions.fHeight / 2.5f };
59 const float kAnglePerTooth = 2.0f * SK_ScalarPI / (3 * numTeeth);
60
61 float angle = 0.0f;
62
63 SkPath tmp;
65
66 tmp.moveTo(gen_pt(angle, outerRad));
67
68 for (int i = 0; i < numTeeth; ++i, angle += 3*kAnglePerTooth) {
69 tmp.lineTo(gen_pt(angle+kAnglePerTooth, outerRad));
70 tmp.lineTo(gen_pt(angle+(1.5f*kAnglePerTooth), innerRad));
71 tmp.lineTo(gen_pt(angle+(2.5f*kAnglePerTooth), innerRad));
72 tmp.lineTo(gen_pt(angle+(3.0f*kAnglePerTooth), outerRad));
73 }
74
75 tmp.close();
76
77 float fInnerRad = 0.1f * std::min(dimensions.fWidth, dimensions.fHeight);
78 if (fInnerRad > 0.5f) {
79 tmp.addCircle(0.0f, 0.0f, fInnerRad, SkPathDirection::kCCW);
80 }
81
82 return tmp;
83}
#define SK_ScalarPI
Definition: SkScalar.h:21
Definition: SkPath.h:59
SkPath & addCircle(SkScalar x, SkScalar y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:1213
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
void setFillType(SkPathFillType ft)
Definition: SkPath.h:235
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728
SkPath & close()
Definition: SkPath.cpp:823
static SkPoint gen_pt(float angle, const SkVector &scale)
static float min(float r, float g, float b)
Definition: hsl.cpp:48
int32_t fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17

◆ render_level()

SkBitmap render_level ( SkISize  dimensions,
SkColor  color,
SkColorType  colorType,
bool  opaque 
)

Definition at line 86 of file compressed_textures.cpp.

86 {
87 SkPath path = make_gear(dimensions, 9);
88
89 SkImageInfo ii = SkImageInfo::Make(dimensions.width(), dimensions.height(),
92 SkBitmap bm;
93 bm.allocPixels(ii);
94
96
97 SkCanvas c(bm);
98
100 paint.setColor(color | 0xFF000000);
101 paint.setAntiAlias(false);
102
103 c.translate(dimensions.width() / 2.0f, dimensions.height() / 2.0f);
104 c.drawPath(path, paint);
105
106 return bm;
107}
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
const Paint & paint
Definition: color_source.cc:38
static SkPath make_gear(SkISize dimensions, int numTeeth)
DlColor color
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)