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