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