OLD | NEW |
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 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #define GR_ATLAS_WIDTH 256 | 28 #define GR_ATLAS_WIDTH 256 |
29 #define GR_ATLAS_HEIGHT 256 | 29 #define GR_ATLAS_HEIGHT 256 |
30 | 30 |
31 #define GR_PLOT_WIDTH (GR_ATLAS_TEXTURE_WIDTH / GR_ATLAS_WIDTH) | 31 #define GR_PLOT_WIDTH (GR_ATLAS_TEXTURE_WIDTH / GR_ATLAS_WIDTH) |
32 #define GR_PLOT_HEIGHT (GR_ATLAS_TEXTURE_HEIGHT / GR_ATLAS_HEIGHT) | 32 #define GR_PLOT_HEIGHT (GR_ATLAS_TEXTURE_HEIGHT / GR_ATLAS_HEIGHT) |
33 | 33 |
34 #endif | 34 #endif |
35 | 35 |
36 /////////////////////////////////////////////////////////////////////////////// | 36 /////////////////////////////////////////////////////////////////////////////// |
37 | 37 |
38 #define BORDER 1 | |
39 | |
40 #ifdef SK_DEBUG | 38 #ifdef SK_DEBUG |
41 static int gCounter; | 39 static int gCounter; |
42 #endif | 40 #endif |
43 | 41 |
44 // for testing | 42 // for testing |
45 #define FONT_CACHE_STATS 0 | 43 #define FONT_CACHE_STATS 0 |
46 #if FONT_CACHE_STATS | 44 #if FONT_CACHE_STATS |
47 static int g_UploadCount = 0; | 45 static int g_UploadCount = 0; |
48 #endif | 46 #endif |
49 | 47 |
50 GrPlot::GrPlot() : fDrawToken(NULL, 0) | 48 GrPlot::GrPlot() : fDrawToken(NULL, 0) |
51 , fNext(NULL) | 49 , fNext(NULL) |
52 , fTexture(NULL) | 50 , fTexture(NULL) |
53 , fAtlasMgr(NULL) | 51 , fAtlasMgr(NULL) |
54 , fBytesPerPixel(1) | 52 , fBytesPerPixel(1) |
55 { | 53 { |
56 fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH - BORDER, | 54 fRects = GrRectanizer::Factory(GR_ATLAS_WIDTH, |
57 GR_ATLAS_HEIGHT - BORDER); | 55 GR_ATLAS_HEIGHT); |
58 fOffset.set(0, 0); | 56 fOffset.set(0, 0); |
59 } | 57 } |
60 | 58 |
61 GrPlot::~GrPlot() { | 59 GrPlot::~GrPlot() { |
62 delete fRects; | 60 delete fRects; |
63 } | 61 } |
64 | 62 |
65 static inline void adjust_for_offset(GrIPoint16* loc, const GrIPoint16& offset)
{ | 63 static inline void adjust_for_offset(GrIPoint16* loc, const GrIPoint16& offset)
{ |
66 loc->fX += offset.fX * GR_ATLAS_WIDTH; | 64 loc->fX += offset.fX * GR_ATLAS_WIDTH; |
67 loc->fY += offset.fY * GR_ATLAS_HEIGHT; | 65 loc->fY += offset.fY * GR_ATLAS_HEIGHT; |
68 } | 66 } |
69 | 67 |
70 static inline uint8_t* zero_fill(uint8_t* ptr, size_t count) { | 68 static inline uint8_t* zero_fill(uint8_t* ptr, size_t count) { |
71 sk_bzero(ptr, count); | 69 sk_bzero(ptr, count); |
72 return ptr + count; | 70 return ptr + count; |
73 } | 71 } |
74 | 72 |
75 bool GrPlot::addSubImage(int width, int height, const void* image, | 73 bool GrPlot::addSubImage(int width, int height, const void* image, |
76 GrIPoint16* loc) { | 74 GrIPoint16* loc) { |
77 if (!fRects->addRect(width + BORDER, height + BORDER, loc)) { | 75 if (!fRects->addRect(width, height, loc)) { |
78 return false; | 76 return false; |
79 } | 77 } |
80 | 78 |
81 SkAutoSMalloc<1024> storage; | 79 SkAutoSMalloc<1024> storage; |
82 int dstW = width + 2*BORDER; | |
83 int dstH = height + 2*BORDER; | |
84 if (BORDER) { | |
85 const size_t dstRB = dstW * fBytesPerPixel; | |
86 uint8_t* dst = (uint8_t*)storage.reset(dstH * dstRB); | |
87 sk_bzero(dst, dstRB); // zero top row | |
88 dst += dstRB; | |
89 for (int y = 0; y < height; y++) { | |
90 dst = zero_fill(dst, fBytesPerPixel); // zero left edge | |
91 memcpy(dst, image, width * fBytesPerPixel); | |
92 dst += width * fBytesPerPixel; | |
93 dst = zero_fill(dst, fBytesPerPixel); // zero right edge | |
94 image = (const void*)((const char*)image + width * fBytesPerPixel); | |
95 } | |
96 sk_bzero(dst, dstRB); // zero bottom row | |
97 image = storage.get(); | |
98 } | |
99 adjust_for_offset(loc, fOffset); | 80 adjust_for_offset(loc, fOffset); |
100 GrContext* context = fTexture->getContext(); | 81 GrContext* context = fTexture->getContext(); |
101 // We pass the flag that does not force a flush. We assume our caller is | 82 // We pass the flag that does not force a flush. We assume our caller is |
102 // smart and hasn't referenced the part of the texture we're about to update | 83 // smart and hasn't referenced the part of the texture we're about to update |
103 // since the last flush. | 84 // since the last flush. |
104 context->writeTexturePixels(fTexture, | 85 context->writeTexturePixels(fTexture, |
105 loc->fX, loc->fY, dstW, dstH, | 86 loc->fX, loc->fY, width, height, |
106 fTexture->config(), image, 0, | 87 fTexture->config(), image, 0, |
107 GrContext::kDontFlush_PixelOpsFlag); | 88 GrContext::kDontFlush_PixelOpsFlag); |
108 | 89 |
109 // now tell the caller to skip the top/left BORDER | |
110 loc->fX += BORDER; | |
111 loc->fY += BORDER; | |
112 | |
113 #if FONT_CACHE_STATS | 90 #if FONT_CACHE_STATS |
114 ++g_UploadCount; | 91 ++g_UploadCount; |
115 #endif | 92 #endif |
116 | 93 |
117 return true; | 94 return true; |
118 } | 95 } |
119 | 96 |
120 /////////////////////////////////////////////////////////////////////////////// | 97 /////////////////////////////////////////////////////////////////////////////// |
121 | 98 |
122 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config) { | 99 GrAtlasMgr::GrAtlasMgr(GrGpu* gpu, GrPixelConfig config) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 229 |
253 plot->fRects->reset(); | 230 plot->fRects->reset(); |
254 plot->fNext = fFreePlots; | 231 plot->fNext = fFreePlots; |
255 fFreePlots = plot; | 232 fFreePlots = plot; |
256 | 233 |
257 #ifdef SK_DEBUG | 234 #ifdef SK_DEBUG |
258 --gCounter; | 235 --gCounter; |
259 // GrPrintf("~GrPlot %p [%d %d] %d\n", this, plot->fOffset.fX, plot->fOffset.
fY, gCounter); | 236 // GrPrintf("~GrPlot %p [%d %d] %d\n", this, plot->fOffset.fX, plot->fOffset.
fY, gCounter); |
260 #endif | 237 #endif |
261 } | 238 } |
OLD | NEW |