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

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

Issue 15035004: SkGpuDevice: Delay locking bitmap pixels until we have a known texture cache miss. (Closed) Base URL: http://skia.googlecode.com/svn/trunk
Patch Set: fix whitespace Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | 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 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 10
11 #include "SkGr.h" 11 #include "SkGr.h"
12 12
13 /* Fill out buffer with the compressed format Ganesh expects from a colortable 13 /* Fill out buffer with the compressed format Ganesh expects from a colortable
14 based bitmap. [palette (colortable) + indices]. 14 based bitmap. [palette (colortable) + indices].
15 15
16 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others 16 At the moment Ganesh only supports 8bit version. If Ganesh allowed we others
17 we could detect that the colortable.count is <= 16, and then repack the 17 we could detect that the colortable.count is <= 16, and then repack the
18 indices as nibbles to save RAM, but it would take more time (i.e. a lot 18 indices as nibbles to save RAM, but it would take more time (i.e. a lot
19 slower than memcpy), so skipping that for now. 19 slower than memcpy), so skipping that for now.
20 20
21 Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big 21 Ganesh wants a full 256 palette entry, even though Skia's ctable is only as big
22 as the colortable.count says it is. 22 as the colortable.count says it is.
23 */ 23 */
24 static void build_compressed_data(void* buffer, const SkBitmap& bitmap) { 24 static void build_compressed_data(void* buffer, const SkBitmap& bitmap) {
25 SkASSERT(SkBitmap::kIndex8_Config == bitmap.config()); 25 SkASSERT(SkBitmap::kIndex8_Config == bitmap.config());
26 26
27 SkAutoLockPixels apl(bitmap); 27 SkAutoLockPixels alp(bitmap);
28 if (!bitmap.readyToDraw()) { 28 if (!bitmap.readyToDraw()) {
29 SkDEBUGFAIL("bitmap not ready to draw!"); 29 SkDEBUGFAIL("bitmap not ready to draw!");
30 return; 30 return;
31 } 31 }
32 32
33 SkColorTable* ctable = bitmap.getColorTable(); 33 SkColorTable* ctable = bitmap.getColorTable();
34 char* dst = (char*)buffer; 34 char* dst = (char*)buffer;
35 35
36 memcpy(dst, ctable->lockColors(), ctable->count() * sizeof(SkPMColor)); 36 memcpy(dst, ctable->lockColors(), ctable->count() * sizeof(SkPMColor));
37 ctable->unlockColors(false); 37 ctable->unlockColors(false);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 return result; 128 return result;
129 } 129 }
130 } else { 130 } else {
131 origBitmap.copyTo(&tmpBitmap, SkBitmap::kARGB_8888_Config); 131 origBitmap.copyTo(&tmpBitmap, SkBitmap::kARGB_8888_Config);
132 // now bitmap points to our temp, which has been promoted to 32bits 132 // now bitmap points to our temp, which has been promoted to 32bits
133 bitmap = &tmpBitmap; 133 bitmap = &tmpBitmap;
134 desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config()); 134 desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config());
135 } 135 }
136 } 136 }
137 137
138 SkAutoLockPixels alp(*bitmap);
139 if (!bitmap->readyToDraw()) {
140 return NULL;
141 }
138 if (cache) { 142 if (cache) {
139 // This texture is likely to be used again so leave it in the cache 143 // This texture is likely to be used again so leave it in the cache
140 GrCacheID cacheID; 144 GrCacheID cacheID;
141 generate_bitmap_cache_id(origBitmap, &cacheID); 145 generate_bitmap_cache_id(origBitmap, &cacheID);
142 return ctx->createTexture(params, desc, cacheID, bitmap->getPixels(), bi tmap->rowBytes()); 146 return ctx->createTexture(params, desc, cacheID, bitmap->getPixels(), bi tmap->rowBytes());
143 } else { 147 } else {
144 // This texture is unlikely to be used again (in its present form) so 148 // This texture is unlikely to be used again (in its present form) so
145 // just use a scratch texture. This will remove the texture from the 149 // just use a scratch texture. This will remove the texture from the
146 // cache so no one else can find it. Additionally, once unlocked, the 150 // cache so no one else can find it. Additionally, once unlocked, the
147 // scratch texture will go to the end of the list for purging so will 151 // scratch texture will go to the end of the list for purging so will
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 return kRGB_565_GrPixelConfig; 218 return kRGB_565_GrPixelConfig;
215 case SkBitmap::kARGB_4444_Config: 219 case SkBitmap::kARGB_4444_Config:
216 return kRGBA_4444_GrPixelConfig; 220 return kRGBA_4444_GrPixelConfig;
217 case SkBitmap::kARGB_8888_Config: 221 case SkBitmap::kARGB_8888_Config:
218 return kSkia8888_GrPixelConfig; 222 return kSkia8888_GrPixelConfig;
219 default: 223 default:
220 // kNo_Config, kA1_Config missing, and kRLE_Index8_Config 224 // kNo_Config, kA1_Config missing, and kRLE_Index8_Config
221 return kUnknown_GrPixelConfig; 225 return kUnknown_GrPixelConfig;
222 } 226 }
223 } 227 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698