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

Side by Side Diff: src/core/SkBitmapDevice.cpp

Issue 382543005: Revert of Add SkBitmap::readPixels() and reimplement copyTo and SkCanvas::readPixels (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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/core/SkBitmap.cpp ('k') | src/core/SkConfig8888.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 2013 Google Inc. 2 * Copyright 2013 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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkConfig8888.h" 9 #include "SkConfig8888.h"
10 #include "SkDraw.h" 10 #include "SkDraw.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 134
135 void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) { 135 void* SkBitmapDevice::onAccessPixels(SkImageInfo* info, size_t* rowBytes) {
136 if (fBitmap.getPixels()) { 136 if (fBitmap.getPixels()) {
137 *info = fBitmap.info(); 137 *info = fBitmap.info();
138 *rowBytes = fBitmap.rowBytes(); 138 *rowBytes = fBitmap.rowBytes();
139 return fBitmap.getPixels(); 139 return fBitmap.getPixels();
140 } 140 }
141 return NULL; 141 return NULL;
142 } 142 }
143 143
144 static void rect_memcpy(void* dst, size_t dstRB, const void* src, size_t srcRB, size_t bytesPerRow,
145 int rowCount) {
146 SkASSERT(bytesPerRow <= srcRB);
147 SkASSERT(bytesPerRow <= dstRB);
148 for (int i = 0; i < rowCount; ++i) {
149 memcpy(dst, src, bytesPerRow);
150 dst = (char*)dst + dstRB;
151 src = (const char*)src + srcRB;
152 }
153 }
154
144 #include "SkConfig8888.h" 155 #include "SkConfig8888.h"
145 156
157 static bool copy_pixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstR owBytes,
158 const SkImageInfo& srcInfo, const void* srcPixels, size_ t srcRowBytes) {
159 if (srcInfo.dimensions() != dstInfo.dimensions()) {
160 return false;
161 }
162 if (4 == srcInfo.bytesPerPixel() && 4 == dstInfo.bytesPerPixel()) {
163 SkDstPixelInfo dstPI;
164 dstPI.fColorType = dstInfo.colorType();
165 dstPI.fAlphaType = dstInfo.alphaType();
166 dstPI.fPixels = dstPixels;
167 dstPI.fRowBytes = dstRowBytes;
168
169 SkSrcPixelInfo srcPI;
170 srcPI.fColorType = srcInfo.colorType();
171 srcPI.fAlphaType = srcInfo.alphaType();
172 srcPI.fPixels = srcPixels;
173 srcPI.fRowBytes = srcRowBytes;
174
175 return srcPI.convertPixelsTo(&dstPI, srcInfo.width(), srcInfo.height());
176 }
177 if (srcInfo.colorType() == dstInfo.colorType()) {
178 switch (srcInfo.colorType()) {
179 case kRGB_565_SkColorType:
180 case kAlpha_8_SkColorType:
181 break;
182 case kARGB_4444_SkColorType:
183 if (srcInfo.alphaType() != dstInfo.alphaType()) {
184 return false;
185 }
186 break;
187 default:
188 return false;
189 }
190 rect_memcpy(dstPixels, dstRowBytes, srcPixels, srcRowBytes,
191 srcInfo.width() * srcInfo.bytesPerPixel(), srcInfo.height()) ;
192 }
193 // TODO: add support for more conversions as needed
194 return false;
195 }
196
146 bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPi xels, 197 bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPi xels,
147 size_t srcRowBytes, int x, int y) { 198 size_t srcRowBytes, int x, int y) {
148 // since we don't stop creating un-pixeled devices yet, check for no pixels here 199 // since we don't stop creating un-pixeled devices yet, check for no pixels here
149 if (NULL == fBitmap.getPixels()) { 200 if (NULL == fBitmap.getPixels()) {
150 return false; 201 return false;
151 } 202 }
152 203
153 SkImageInfo dstInfo = fBitmap.info(); 204 SkImageInfo dstInfo = fBitmap.info();
154 dstInfo.fWidth = srcInfo.width(); 205 dstInfo.fWidth = srcInfo.width();
155 dstInfo.fHeight = srcInfo.height(); 206 dstInfo.fHeight = srcInfo.height();
156 207
157 void* dstPixels = fBitmap.getAddr(x, y); 208 void* dstPixels = fBitmap.getAddr(x, y);
158 size_t dstRowBytes = fBitmap.rowBytes(); 209 size_t dstRowBytes = fBitmap.rowBytes();
159 210
160 if (SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPix els, srcRowBytes)) { 211 if (copy_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowB ytes)) {
161 fBitmap.notifyPixelsChanged(); 212 fBitmap.notifyPixelsChanged();
162 return true; 213 return true;
163 } 214 }
164 return false; 215 return false;
165 } 216 }
166 217
167 bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s ize_t dstRowBytes, 218 bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s ize_t dstRowBytes,
168 int x, int y) { 219 int x, int y) {
169 return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, x, y); 220 // since we don't stop creating un-pixeled devices yet, check for no pixels here
221 if (NULL == fBitmap.getPixels()) {
222 return false;
223 }
224
225 SkImageInfo srcInfo = fBitmap.info();
226
227 // perhaps can relax these in the future
228 if (4 != dstInfo.bytesPerPixel()) {
229 return false;
230 }
231 if (4 != srcInfo.bytesPerPixel()) {
232 return false;
233 }
234
235 srcInfo.fWidth = dstInfo.width();
236 srcInfo.fHeight = dstInfo.height();
237
238 const void* srcPixels = fBitmap.getAddr(x, y);
239 const size_t srcRowBytes = fBitmap.rowBytes();
240
241 return copy_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcR owBytes);
170 } 242 }
171 243
172 /////////////////////////////////////////////////////////////////////////////// 244 ///////////////////////////////////////////////////////////////////////////////
173 245
174 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { 246 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
175 draw.drawPaint(paint); 247 draw.drawPaint(paint);
176 } 248 }
177 249
178 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si ze_t count, 250 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si ze_t count,
179 const SkPoint pts[], const SkPaint& paint) { 251 const SkPoint pts[], const SkPaint& paint) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 paint.getStyle() != SkPaint::kFill_Style || 454 paint.getStyle() != SkPaint::kFill_Style ||
383 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { 455 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) {
384 // turn off lcd 456 // turn off lcd
385 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; 457 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag;
386 flags->fHinting = paint.getHinting(); 458 flags->fHinting = paint.getHinting();
387 return true; 459 return true;
388 } 460 }
389 // we're cool with the paint as is 461 // we're cool with the paint as is
390 return false; 462 return false;
391 } 463 }
OLDNEW
« no previous file with comments | « src/core/SkBitmap.cpp ('k') | src/core/SkConfig8888.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698