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

Side by Side Diff: src/image/SkImage.cpp

Issue 1738513002: start on pre-upload data (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: stuff 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 | « src/gpu/SkGrPriv.h ('k') | src/image/SkImage_Gpu.cpp » ('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 2012 Google Inc. 2 * Copyright 2012 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapCache.h" 9 #include "SkBitmapCache.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // For now, and to maintain parity w/ previous pixelref behavior, we just fo rce the image 82 // For now, and to maintain parity w/ previous pixelref behavior, we just fo rce the image
83 // to produce a cached raster-bitmap form, so that drawing to a raster canva s should be fast. 83 // to produce a cached raster-bitmap form, so that drawing to a raster canva s should be fast.
84 // 84 //
85 SkBitmap bm; 85 SkBitmap bm;
86 if (as_IB(this)->getROPixels(&bm)) { 86 if (as_IB(this)->getROPixels(&bm)) {
87 bm.lockPixels(); 87 bm.lockPixels();
88 bm.unlockPixels(); 88 bm.unlockPixels();
89 } 89 }
90 } 90 }
91 91
92 SkImageTextureData* SkImage::newImageTextureData(
93 const GrContextThreadSafeProxy& proxy,
94 const std::function<void*(size_t, const SkImage*)>& allocate) const {
95 SkPixmap pixmap;
96 if (!this->peekPixels(&pixmap)) {
97 return nullptr;
98 }
99 size_t size = 0;
100 size_t itdSize = SkAlign8(sizeof(SkImageTextureData));
101 size += itdSize;
102 size_t pixelOffset = size;
103 size_t pixelSize = SkAlign8(pixmap.getSafeSize());
104 size += pixelSize;
105 size_t ctOffset = size;
106 int ctCount = 0;
107 size_t ctSize = 0;
108 if (pixmap.ctable()) {
109 ctCount = pixmap.ctable()->count();
110 ctSize = SkAlign8(pixmap.ctable()->count() * 4);
111 size += ctSize;
112 }
113 intptr_t allocation = reinterpret_cast<intptr_t>(allocate(size, this));
114 void* itd = reinterpret_cast<void*>(allocation);
115 void* pixels = reinterpret_cast<void*>(allocation + pixelOffset);
116 SkPMColor* ct = nullptr;
117 if (ctSize) {
118 ct = reinterpret_cast<SkPMColor*>(allocation + ctOffset);
119 }
120
121 memcpy(pixels, pixmap.addr(), pixmap.getSafeSize());
122 if (ctSize) {
123 memcpy(ct, pixmap.ctable()->readColors(), ctSize);
124 }
125
126 const SkImageInfo& info = pixmap.info();
127 size_t rowBytes = pixmap.rowBytes();
128 SkImageTextureData* textureData = new (itd) SkImageTextureData();
129 textureData->fContextUniqueID = proxy.fContextUniqueID;
130 textureData->fImageUniqueID = this->uniqueID();
131 textureData->fPixmapGenerator = [info, pixels, rowBytes, ct, ctCount] (SkPix map* pixmap) {
132 SkAutoTUnref<SkColorTable> colorTable;
133 if (ct) {
134 colorTable.reset(new SkColorTable(ct, ctCount));
135 }
136 pixmap->reset(info, pixels, rowBytes, colorTable.get());
137 };
138 return textureData;
139 }
140
92 //////////////////////////////////////////////////////////////////////////////// /////////////////// 141 //////////////////////////////////////////////////////////////////////////////// ///////////////////
93 142
94 SkShader* SkImage::newShader(SkShader::TileMode tileX, 143 SkShader* SkImage::newShader(SkShader::TileMode tileX,
95 SkShader::TileMode tileY, 144 SkShader::TileMode tileY,
96 const SkMatrix* localMatrix) const { 145 const SkMatrix* localMatrix) const {
97 return SkImageShader::Create(this, tileX, tileY, localMatrix); 146 return SkImageShader::Create(this, tileX, tileY, localMatrix);
98 } 147 }
99 148
100 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { 149 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
101 SkBitmap bm; 150 SkBitmap bm;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 403
355 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 404 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) {
356 return nullptr; 405 return nullptr;
357 } 406 }
358 407
359 SkImage* SkImage::newTextureImage(GrContext*) const { 408 SkImage* SkImage::newTextureImage(GrContext*) const {
360 return nullptr; 409 return nullptr;
361 } 410 }
362 411
363 #endif 412 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGrPriv.h ('k') | src/image/SkImage_Gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698