Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: src/gpu/SkGr.cpp

Issue 1776913003: Add SkImage::NewTextureFromPixmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: try again Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkImage.h ('k') | src/gpu/SkGrPriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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.
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;
258 } 266 }
259 } 267 }
260 268
261 GrTexture *texture = create_texture_from_yuv(ctx, *bitmap, desc); 269 return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, pmap->a ddr(),
262 if (texture) { 270 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 } 271 }
274 272
275 273
276 //////////////////////////////////////////////////////////////////////////////// 274 ////////////////////////////////////////////////////////////////////////////////
277 275
278 void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix elRef) { 276 void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix elRef) {
279 class Invalidator : public SkPixelRef::GenIDChangeListener { 277 class Invalidator : public SkPixelRef::GenIDChangeListener {
280 public: 278 public:
281 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {} 279 explicit Invalidator(const GrUniqueKey& key) : fMsg(key) {}
282 private: 280 private:
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 SkErrorInternals::SetError( kInvalidPaint_SkError, 694 SkErrorInternals::SetError( kInvalidPaint_SkError,
697 "Sorry, I don't understand the filtering " 695 "Sorry, I don't understand the filtering "
698 "mode you asked for. Falling back to " 696 "mode you asked for. Falling back to "
699 "MIPMaps."); 697 "MIPMaps.");
700 textureFilterMode = GrTextureParams::kMipMap_FilterMode; 698 textureFilterMode = GrTextureParams::kMipMap_FilterMode;
701 break; 699 break;
702 700
703 } 701 }
704 return textureFilterMode; 702 return textureFilterMode;
705 } 703 }
OLDNEW
« no previous file with comments | « include/core/SkImage.h ('k') | src/gpu/SkGrPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698