97 {
98 const Caps* caps = recorder->
priv().
caps();
99 SkASSERT(caps->isTexturable(textureProxy->textureInfo()));
101 textureProxy->textureInfo()));
102
103 unsigned int mipLevelCount = levels.
size();
104
106
107
108
109#ifdef SK_DEBUG
110 unsigned int numExpectedLevels = 1;
113 textureProxy->dimensions().height()) + 1;
114 }
115 SkASSERT(mipLevelCount == 1 || mipLevelCount == numExpectedLevels);
116#endif
117
120 }
121
122 if (mipLevelCount == 1 && !levels[0].fPixels) {
124 }
125
126 for (
unsigned int i = 0;
i < mipLevelCount; ++
i) {
127
128 if (!levels[
i].fPixels) {
130 }
131 }
132
134 bool isRGB888Format;
135 std::tie(supportedColorType, isRGB888Format) =
136 caps->supportedWritePixelsColorType(dstColorInfo.
colorType(),
137 textureProxy->textureInfo(),
141 }
142
145
147 caps,
148 mipLevelCount,
149 bpp,
152 &levelOffsetsAndRowBytes);
154
157 if (!writer) {
158 SKGPU_LOG_W(
"Failed to get write-mapped buffer for texture upload of size %zu",
159 combinedBufferSize);
161 }
162
163 UploadInstance upload{bufferInfo.fBuffer, bpp, std::move(textureProxy), std::move(condContext)};
164
165
166 int32_t currentWidth = dstRect.
width();
167 int32_t currentHeight = dstRect.
height();
168 bool needsConversion = (srcColorInfo != dstColorInfo);
169 for (unsigned int currentMipLevel = 0; currentMipLevel < mipLevelCount; currentMipLevel++) {
170 const size_t trimRowBytes = currentWidth * bpp;
171 const size_t srcRowBytes = levels[currentMipLevel].fRowBytes;
172 const auto [mipOffset, dstRowBytes] = levelOffsetsAndRowBytes[currentMipLevel];
173
174
175 const char*
src = (
const char*)levels[currentMipLevel].fPixels;
176
177 if (isRGB888Format) {
180 SkISize dims = {currentWidth, currentHeight};
183
184 const void* rgbConvertSrc =
src;
185 size_t rgbSrcRowBytes = srcRowBytes;
187 if (needsConversion) {
188 temp.
alloc(dstImageInfo);
192 srcImageInfo,
194 srcRowBytes));
195 rgbConvertSrc = temp.
addr();
197 }
198 writer.writeRGBFromRGBx(mipOffset,
199 rgbConvertSrc,
200 rgbSrcRowBytes,
201 dstRowBytes,
202 currentWidth,
203 currentHeight);
204 } else if (needsConversion) {
205 SkISize dims = {currentWidth, currentHeight};
208
209 writer.convertAndWrite(
210 mipOffset, srcImageInfo,
src, srcRowBytes, dstImageInfo, dstRowBytes);
211 } else {
212 writer.write(mipOffset,
src, srcRowBytes, dstRowBytes, trimRowBytes, currentHeight);
213 }
214
215
216
217 upload.fCopyData.push_back({
218 bufferInfo.fOffset + mipOffset,
219 dstRowBytes,
221 currentMipLevel
222 });
223
224 currentWidth =
std::max(1, currentWidth / 2);
225 currentHeight =
std::max(1, currentHeight / 2);
226 }
227
229 mipLevelCount > 1 ? "MipMap " : "",
231
233}
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
#define SKGPU_LOG_W(fmt,...)
@ kRGB_888x_SkColorType
pixel with 8 bits each for red, green, blue; in 32-bit word
@ kUnknown_SkColorType
uninitialized
bool SkConvertPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRB, const SkImageInfo &srcInfo, const void *srcPixels, size_t srcRB)
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
#define ATRACE_ANDROID_FRAMEWORK(fmt,...)
static sk_sp< SkImage > upload(const sk_sp< SkSurface > &surf, SkColor color)
void alloc(const SkImageInfo &)
SkColorType colorType() const
static int ComputeLevelCount(int baseWidth, int baseHeight)
void * writable_addr() const
const void * addr() const
constexpr size_t size() const
const Caps * caps() const
UploadBufferManager * uploadBufferManager()
std::tuple< TextureUploadWriter, BindBufferInfo > getTextureUploadWriter(size_t requiredBytes, size_t requiredAlignment)
static UploadInstance Invalid()
UploadInstance(UploadInstance &&)
static float max(float r, float g, float b)
std::pair< size_t, size_t > compute_combined_buffer_size(const Caps *caps, int mipLevelCount, size_t bytesPerBlock, const SkISize &baseDimensions, SkTextureCompressionType compressionType, TArray< std::pair< size_t, size_t > > *levelOffsetsAndRowBytes)
constexpr int32_t top() const
constexpr SkISize size() const
constexpr int32_t height() const
constexpr int32_t width() const
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
constexpr int32_t left() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)