OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #include "GrBatchAtlas.h" | 8 #include "GrBatchAtlas.h" |
9 #include "GrBatchTarget.h" | 9 #include "GrBatchTarget.h" |
10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 int genID() const { return fGenID; } | 43 int genID() const { return fGenID; } |
44 GrBatchAtlas::AtlasID id() { return fID; } | 44 GrBatchAtlas::AtlasID id() { return fID; } |
45 | 45 |
46 GrTexture* texture() const { return fTexture; } | 46 GrTexture* texture() const { return fTexture; } |
47 | 47 |
48 bool addSubImage(int width, int height, const void* image, SkIPoint16* loc, size_t rowBytes) { | 48 bool addSubImage(int width, int height, const void* image, SkIPoint16* loc, size_t rowBytes) { |
49 if (!fRects->addRect(width, height, loc)) { | 49 if (!fRects->addRect(width, height, loc)) { |
50 return false; | 50 return false; |
51 } | 51 } |
52 | 52 |
53 SkASSERT(fData); | 53 if (!fData) { |
54 fData = reinterpret_cast<unsigned char*>(sk_calloc_throw(fBytesPerPi xel * fWidth * fHeight)); | |
bsalomon
2015/04/24 15:07:41
lgtm, wrap this and delete commented out lines?
| |
55 } | |
54 const unsigned char* imagePtr = (const unsigned char*)image; | 56 const unsigned char* imagePtr = (const unsigned char*)image; |
55 // point ourselves at the right starting spot | 57 // point ourselves at the right starting spot |
56 unsigned char* dataPtr = fData; | 58 unsigned char* dataPtr = fData; |
57 dataPtr += fBytesPerPixel * fWidth * loc->fY; | 59 dataPtr += fBytesPerPixel * fWidth * loc->fY; |
58 dataPtr += fBytesPerPixel * loc->fX; | 60 dataPtr += fBytesPerPixel * loc->fX; |
59 // copy into the data buffer | 61 // copy into the data buffer |
60 for (int i = 0; i < height; ++i) { | 62 for (int i = 0; i < height; ++i) { |
61 memcpy(dataPtr, imagePtr, rowBytes); | 63 memcpy(dataPtr, imagePtr, rowBytes); |
62 dataPtr += fBytesPerPixel * fWidth; | 64 dataPtr += fBytesPerPixel * fWidth; |
63 imagePtr += rowBytes; | 65 imagePtr += rowBytes; |
(...skipping 17 matching lines...) Expand all Loading... | |
81 SkASSERT(batchToken >= fLastUpload); | 83 SkASSERT(batchToken >= fLastUpload); |
82 fLastUpload = batchToken; | 84 fLastUpload = batchToken; |
83 } | 85 } |
84 void setLastUseToken(BatchToken batchToken) { | 86 void setLastUseToken(BatchToken batchToken) { |
85 SkASSERT(batchToken >= fLastUse); | 87 SkASSERT(batchToken >= fLastUse); |
86 fLastUse = batchToken; | 88 fLastUse = batchToken; |
87 } | 89 } |
88 | 90 |
89 void uploadToTexture(GrBatchTarget::TextureUploader uploader) { | 91 void uploadToTexture(GrBatchTarget::TextureUploader uploader) { |
90 // We should only be issuing uploads if we are in fact dirty | 92 // We should only be issuing uploads if we are in fact dirty |
91 SkASSERT(fDirty); | 93 SkASSERT(fDirty && fData && fTexture); |
92 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrBatchPlot::upload ToTexture"); | 94 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "GrBatchPlot::upload ToTexture"); |
93 SkASSERT(fTexture); | |
94 size_t rowBytes = fBytesPerPixel * fRects->width(); | 95 size_t rowBytes = fBytesPerPixel * fRects->width(); |
95 const unsigned char* dataPtr = fData; | 96 const unsigned char* dataPtr = fData; |
96 dataPtr += rowBytes * fDirtyRect.fTop; | 97 dataPtr += rowBytes * fDirtyRect.fTop; |
97 dataPtr += fBytesPerPixel * fDirtyRect.fLeft; | 98 dataPtr += fBytesPerPixel * fDirtyRect.fLeft; |
98 uploader.writeTexturePixels(fTexture, | 99 uploader.writeTexturePixels(fTexture, |
99 fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirtyRect.fTop, | 100 fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirtyRect.fTop, |
100 fDirtyRect.width(), fDirtyRect.height(), | 101 fDirtyRect.width(), fDirtyRect.height(), |
101 fTexture->config(), dataPtr, rowBytes); | 102 fTexture->config(), dataPtr, rowBytes); |
102 fDirtyRect.setEmpty(); | 103 fDirtyRect.setEmpty(); |
103 SkDEBUGCODE(fDirty = false;) | 104 SkDEBUGCODE(fDirty = false;) |
104 } | 105 } |
105 | 106 |
106 void resetRects() { | 107 void resetRects() { |
107 SkASSERT(fRects); | 108 SkASSERT(fRects); |
108 fRects->reset(); | 109 fRects->reset(); |
109 fGenID++; | 110 fGenID++; |
110 fID = create_id(fIndex, fGenID); | 111 fID = create_id(fIndex, fGenID); |
111 | 112 |
112 // zero out the plot | 113 // zero out the plot |
113 SkASSERT(fData); | 114 if (fData) { |
114 memset(fData, 0, fBytesPerPixel * fWidth * fHeight); | 115 sk_bzero(fData, fBytesPerPixel * fWidth * fHeight); |
116 } | |
115 | 117 |
116 fDirtyRect.setEmpty(); | 118 fDirtyRect.setEmpty(); |
117 SkDEBUGCODE(fDirty = false;) | 119 SkDEBUGCODE(fDirty = false;) |
118 } | 120 } |
119 | 121 |
120 int x() const { return fX; } | 122 int x() const { return fX; } |
121 int y() const { return fY; } | 123 int y() const { return fY; } |
122 | 124 |
123 private: | 125 private: |
124 BatchPlot() | 126 BatchPlot() |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 fRects = GrRectanizer::Factory(width, height); | 163 fRects = GrRectanizer::Factory(width, height); |
162 fAtlas = atlas; | 164 fAtlas = atlas; |
163 fOffset.set(offX * width, offY * height); | 165 fOffset.set(offX * width, offY * height); |
164 fBytesPerPixel = bpp; | 166 fBytesPerPixel = bpp; |
165 fData = NULL; | 167 fData = NULL; |
166 fDirtyRect.setEmpty(); | 168 fDirtyRect.setEmpty(); |
167 SkDEBUGCODE(fDirty = false;) | 169 SkDEBUGCODE(fDirty = false;) |
168 fTexture = texture; | 170 fTexture = texture; |
169 | 171 |
170 // allocate backing store | 172 // allocate backing store |
171 fData = SkNEW_ARRAY(unsigned char, fBytesPerPixel * width * height); | 173 //fData = SkNEW_ARRAY(unsigned char, fBytesPerPixel * width * height); |
172 memset(fData, 0, fBytesPerPixel * width * height); | 174 //memset(fData, 0, fBytesPerPixel * width * height); |
173 } | 175 } |
174 | 176 |
175 BatchToken fLastUpload; | 177 BatchToken fLastUpload; |
176 BatchToken fLastUse; | 178 BatchToken fLastUse; |
177 | 179 |
178 uint32_t fIndex; | 180 uint32_t fIndex; |
179 uint32_t fGenID; | 181 uint32_t fGenID; |
180 GrBatchAtlas::AtlasID fID; | 182 GrBatchAtlas::AtlasID fID; |
181 unsigned char* fData; | 183 unsigned char* fData; |
182 int fWidth; | 184 int fWidth; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 } | 368 } |
367 | 369 |
368 void GrBatchAtlas::setLastUseTokenBulk(const BulkUseTokenUpdater& updater, Batch Token batchToken) { | 370 void GrBatchAtlas::setLastUseTokenBulk(const BulkUseTokenUpdater& updater, Batch Token batchToken) { |
369 int count = updater.fPlotsToUpdate.count(); | 371 int count = updater.fPlotsToUpdate.count(); |
370 for (int i = 0; i < count; i++) { | 372 for (int i = 0; i < count; i++) { |
371 BatchPlot* plot = fPlotArray[updater.fPlotsToUpdate[i]]; | 373 BatchPlot* plot = fPlotArray[updater.fPlotsToUpdate[i]]; |
372 this->makeMRU(plot); | 374 this->makeMRU(plot); |
373 plot->setLastUseToken(batchToken); | 375 plot->setLastUseToken(batchToken); |
374 } | 376 } |
375 } | 377 } |
OLD | NEW |