OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "SkGr.h" | 9 #include "SkGr.h" |
| 10 #include "SkGrPriv.h" |
10 | 11 |
11 #include "GrCaps.h" | 12 #include "GrCaps.h" |
12 #include "GrContext.h" | 13 #include "GrContext.h" |
13 #include "GrGpuResourcePriv.h" | 14 #include "GrGpuResourcePriv.h" |
14 #include "GrImageIDTextureAdjuster.h" | 15 #include "GrImageIDTextureAdjuster.h" |
15 #include "GrTextureParamsAdjuster.h" | 16 #include "GrTextureParamsAdjuster.h" |
16 #include "GrTypes.h" | 17 #include "GrTypes.h" |
17 #include "GrXferProcessor.h" | 18 #include "GrXferProcessor.h" |
18 #include "GrYUVProvider.h" | 19 #include "GrYUVProvider.h" |
19 | 20 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 * based bitmap. [palette (colortable) + indices]. | 115 * based bitmap. [palette (colortable) + indices]. |
115 * | 116 * |
116 * At the moment Ganesh only supports 8bit version. If Ganesh allowed we others | 117 * At the moment Ganesh only supports 8bit version. If Ganesh allowed we others |
117 * we could detect that the colortable.count is <= 16, and then repack the | 118 * we could detect that the colortable.count is <= 16, and then repack the |
118 * indices as nibbles to save RAM, but it would take more time (i.e. a lot | 119 * indices as nibbles to save RAM, but it would take more time (i.e. a lot |
119 * slower than memcpy), so skipping that for now. | 120 * slower than memcpy), so skipping that for now. |
120 * | 121 * |
121 * Ganesh wants a full 256 palette entry, even though Skia's ctable is only as b
ig | 122 * Ganesh wants a full 256 palette entry, even though Skia's ctable is only as b
ig |
122 * as the colortable.count says it is. | 123 * as the colortable.count says it is. |
123 */ | 124 */ |
124 static void build_index8_data(void* buffer, const SkBitmap& bitmap) { | 125 static void build_index8_data(void* buffer, const SkPixmap& pixmap) { |
125 SkASSERT(kIndex_8_SkColorType == bitmap.colorType()); | 126 SkASSERT(kIndex_8_SkColorType == pixmap.colorType()); |
126 | 127 |
127 SkAutoLockPixels alp(bitmap); | 128 const SkColorTable* ctable = pixmap.ctable(); |
128 if (!bitmap.readyToDraw()) { | |
129 SkDEBUGFAIL("bitmap not ready to draw!"); | |
130 return; | |
131 } | |
132 | |
133 SkColorTable* ctable = bitmap.getColorTable(); | |
134 char* dst = (char*)buffer; | 129 char* dst = (char*)buffer; |
135 | 130 |
136 const int count = ctable->count(); | 131 const int count = ctable->count(); |
137 | 132 |
138 SkDstPixelInfo dstPI; | 133 SkDstPixelInfo dstPI; |
139 dstPI.fColorType = kRGBA_8888_SkColorType; | 134 dstPI.fColorType = kRGBA_8888_SkColorType; |
140 dstPI.fAlphaType = kPremul_SkAlphaType; | 135 dstPI.fAlphaType = kPremul_SkAlphaType; |
141 dstPI.fPixels = buffer; | 136 dstPI.fPixels = buffer; |
142 dstPI.fRowBytes = count * sizeof(SkPMColor); | 137 dstPI.fRowBytes = count * sizeof(SkPMColor); |
143 | 138 |
144 SkSrcPixelInfo srcPI; | 139 SkSrcPixelInfo srcPI; |
145 srcPI.fColorType = kN32_SkColorType; | 140 srcPI.fColorType = kN32_SkColorType; |
146 srcPI.fAlphaType = kPremul_SkAlphaType; | 141 srcPI.fAlphaType = kPremul_SkAlphaType; |
147 srcPI.fPixels = ctable->readColors(); | 142 srcPI.fPixels = ctable->readColors(); |
148 srcPI.fRowBytes = count * sizeof(SkPMColor); | 143 srcPI.fRowBytes = count * sizeof(SkPMColor); |
149 | 144 |
150 srcPI.convertPixelsTo(&dstPI, count, 1); | 145 srcPI.convertPixelsTo(&dstPI, count, 1); |
151 | 146 |
152 // always skip a full 256 number of entries, even if we memcpy'd fewer | 147 // always skip a full 256 number of entries, even if we memcpy'd fewer |
153 dst += 256 * sizeof(GrColor); | 148 dst += 256 * sizeof(GrColor); |
154 | 149 |
155 if ((unsigned)bitmap.width() == bitmap.rowBytes()) { | 150 if ((unsigned)pixmap.width() == pixmap.rowBytes()) { |
156 memcpy(dst, bitmap.getPixels(), bitmap.getSize()); | 151 memcpy(dst, pixmap.addr(), pixmap.getSafeSize()); |
157 } else { | 152 } else { |
158 // need to trim off the extra bytes per row | 153 // need to trim off the extra bytes per row |
159 size_t width = bitmap.width(); | 154 size_t width = pixmap.width(); |
160 size_t rowBytes = bitmap.rowBytes(); | 155 size_t rowBytes = pixmap.rowBytes(); |
161 const char* src = (const char*)bitmap.getPixels(); | 156 const uint8_t* src = pixmap.addr8(); |
162 for (int y = 0; y < bitmap.height(); y++) { | 157 for (int y = 0; y < pixmap.height(); y++) { |
163 memcpy(dst, src, width); | 158 memcpy(dst, src, width); |
164 src += rowBytes; | 159 src += rowBytes; |
165 dst += width; | 160 dst += width; |
166 } | 161 } |
167 } | 162 } |
168 } | 163 } |
169 | 164 |
170 /** | 165 /** |
171 * Once we have made SkImages handle all lazy/deferred/generated content, the Y
UV apis will | 166 * Once we have made SkImages handle all lazy/deferred/generated content, the Y
UV apis will |
172 * be gone from SkPixelRef, and we can remove this subclass entirely. | 167 * be gone from SkPixelRef, and we can remove this subclass entirely. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 const void* startOfTexData; | 206 const void* startOfTexData; |
212 desc.fConfig = GrIsCompressedTextureDataSupported(ctx, data, bm.width(), bm.
height(), | 207 desc.fConfig = GrIsCompressedTextureDataSupported(ctx, data, bm.width(), bm.
height(), |
213 &startOfTexData); | 208 &startOfTexData); |
214 if (kUnknown_GrPixelConfig == desc.fConfig) { | 209 if (kUnknown_GrPixelConfig == desc.fConfig) { |
215 return nullptr; | 210 return nullptr; |
216 } | 211 } |
217 | 212 |
218 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, startOf
TexData, 0); | 213 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, startOf
TexData, 0); |
219 } | 214 } |
220 | 215 |
221 GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bmp) { | 216 GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bitmap) { |
222 SkASSERT(!bmp.getTexture()); | 217 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info()); |
| 218 if (GrTexture *texture = load_etc1_texture(ctx, bitmap, desc)) { |
| 219 return texture; |
| 220 } |
223 | 221 |
| 222 if (GrTexture* texture = create_texture_from_yuv(ctx, bitmap, desc)) { |
| 223 return texture; |
| 224 } |
| 225 |
| 226 SkAutoLockPixels alp(bitmap); |
| 227 if (!bitmap.readyToDraw()) { |
| 228 return nullptr; |
| 229 } |
| 230 SkPixmap pixmap; |
| 231 if (!bitmap.peekPixels(&pixmap)) { |
| 232 return nullptr; |
| 233 } |
| 234 return GrUploadPixmapToTexture(ctx, pixmap); |
| 235 } |
| 236 |
| 237 GrTexture* GrUploadPixmapToTexture(GrContext* ctx, const SkPixmap& pixmap) { |
| 238 const SkPixmap* pmap = &pixmap; |
| 239 SkPixmap tmpPixmap; |
224 SkBitmap tmpBitmap; | 240 SkBitmap tmpBitmap; |
225 const SkBitmap* bitmap = &bmp; | |
226 | 241 |
227 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap->info()); | 242 GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(pixmap.info()); |
228 const GrCaps* caps = ctx->caps(); | 243 const GrCaps* caps = ctx->caps(); |
229 | 244 |
230 if (kIndex_8_SkColorType == bitmap->colorType()) { | 245 if (kIndex_8_SkColorType == pixmap.colorType()) { |
231 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) { | 246 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) { |
232 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig
, | 247 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig
, |
233 bitmap->width(), bitma
p->height()); | 248 pixmap.width(), pixmap
.height()); |
234 SkAutoMalloc storage(imageSize); | 249 SkAutoMalloc storage(imageSize); |
235 build_index8_data(storage.get(), bmp); | 250 build_index8_data(storage.get(), pixmap); |
236 | 251 |
237 // our compressed data will be trimmed, so pass width() for its | 252 // our compressed data will be trimmed, so pass width() for its |
238 // "rowBytes", since they are the same now. | 253 // "rowBytes", since they are the same now. |
239 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes,
storage.get(), | 254 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes,
storage.get(), |
240 bitmap->width()); | 255 pixmap.width()); |
241 } else { | 256 } else { |
242 bmp.copyTo(&tmpBitmap, kN32_SkColorType); | 257 SkImageInfo info = SkImageInfo::MakeN32Premul(pixmap.width(), pixmap
.height()); |
243 // now bitmap points to our temp, which has been promoted to 32bits | 258 tmpBitmap.allocPixels(info); |
244 bitmap = &tmpBitmap; | 259 if (!pixmap.readPixels(info, tmpBitmap.getPixels(), tmpBitmap.rowByt
es())) { |
245 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); | 260 return nullptr; |
246 } | 261 } |
247 } else if (!bitmap->readyToDraw()) { | 262 if (!tmpBitmap.peekPixels(&tmpPixmap)) { |
248 // If the bitmap had compressed data and was then uncompressed, it'll st
ill return | 263 return nullptr; |
249 // compressed data on 'refEncodedData' and upload it. Probably not good,
since if | 264 } |
250 // the bitmap has available pixels, then they might not be what the deco
mpressed | 265 pmap = &tmpPixmap; |
251 // data is. | 266 // must rebuild desc, since we've forced the info to be N32 |
252 | 267 desc = GrImageInfoToSurfaceDesc(pmap->info()); |
253 // Really?? We aren't doing this with YUV. | |
254 | |
255 GrTexture *texture = load_etc1_texture(ctx, *bitmap, desc); | |
256 if (texture) { | |
257 return texture; | |
258 } | 268 } |
259 } | 269 } |
260 | 270 |
261 GrTexture *texture = create_texture_from_yuv(ctx, *bitmap, desc); | 271 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, pmap->a
ddr(), |
262 if (texture) { | 272 pmap->rowBytes()); |
263 return texture; | |
264 } | |
265 | |
266 SkAutoLockPixels alp(*bitmap); | |
267 if (!bitmap->readyToDraw()) { | |
268 return nullptr; | |
269 } | |
270 | |
271 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, bitmap-
>getPixels(), | |
272 bitmap->rowBytes()); | |
273 } | 273 } |
274 | 274 |
275 | 275 |
276 //////////////////////////////////////////////////////////////////////////////// | 276 //////////////////////////////////////////////////////////////////////////////// |
277 | 277 |
278 void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix
elRef) { | 278 void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix
elRef) { |
279 class Invalidator : public SkPixelRef::GenIDChangeListener { | 279 class Invalidator : public SkPixelRef::GenIDChangeListener { |
280 public: | 280 public: |
281 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} | 281 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} |
282 private: | 282 private: |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 SkErrorInternals::SetError( kInvalidPaint_SkError, | 696 SkErrorInternals::SetError( kInvalidPaint_SkError, |
697 "Sorry, I don't understand the filtering
" | 697 "Sorry, I don't understand the filtering
" |
698 "mode you asked for. Falling back to " | 698 "mode you asked for. Falling back to " |
699 "MIPMaps."); | 699 "MIPMaps."); |
700 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 700 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
701 break; | 701 break; |
702 | 702 |
703 } | 703 } |
704 return textureFilterMode; | 704 return textureFilterMode; |
705 } | 705 } |
OLD | NEW |