| OLD | NEW |
| 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 Loading... |
| 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 | |
| 155 #include "SkConfig8888.h" | 144 #include "SkConfig8888.h" |
| 156 | 145 |
| 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 | |
| 197 bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPi
xels, | 146 bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPi
xels, |
| 198 size_t srcRowBytes, int x, int y) { | 147 size_t srcRowBytes, int x, int y) { |
| 199 // since we don't stop creating un-pixeled devices yet, check for no pixels
here | 148 // since we don't stop creating un-pixeled devices yet, check for no pixels
here |
| 200 if (NULL == fBitmap.getPixels()) { | 149 if (NULL == fBitmap.getPixels()) { |
| 201 return false; | 150 return false; |
| 202 } | 151 } |
| 203 | 152 |
| 204 SkImageInfo dstInfo = fBitmap.info(); | 153 SkImageInfo dstInfo = fBitmap.info(); |
| 205 dstInfo.fWidth = srcInfo.width(); | 154 dstInfo.fWidth = srcInfo.width(); |
| 206 dstInfo.fHeight = srcInfo.height(); | 155 dstInfo.fHeight = srcInfo.height(); |
| 207 | 156 |
| 208 void* dstPixels = fBitmap.getAddr(x, y); | 157 void* dstPixels = fBitmap.getAddr(x, y); |
| 209 size_t dstRowBytes = fBitmap.rowBytes(); | 158 size_t dstRowBytes = fBitmap.rowBytes(); |
| 210 | 159 |
| 211 if (copy_pixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowB
ytes)) { | 160 if (SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPix
els, srcRowBytes)) { |
| 212 fBitmap.notifyPixelsChanged(); | 161 fBitmap.notifyPixelsChanged(); |
| 213 return true; | 162 return true; |
| 214 } | 163 } |
| 215 return false; | 164 return false; |
| 216 } | 165 } |
| 217 | 166 |
| 218 bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s
ize_t dstRowBytes, | 167 bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s
ize_t dstRowBytes, |
| 219 int x, int y) { | 168 int x, int y) { |
| 220 // since we don't stop creating un-pixeled devices yet, check for no pixels
here | 169 return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, x, y); |
| 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); | |
| 242 } | 170 } |
| 243 | 171 |
| 244 /////////////////////////////////////////////////////////////////////////////// | 172 /////////////////////////////////////////////////////////////////////////////// |
| 245 | 173 |
| 246 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 174 void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
| 247 draw.drawPaint(paint); | 175 draw.drawPaint(paint); |
| 248 } | 176 } |
| 249 | 177 |
| 250 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si
ze_t count, | 178 void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, si
ze_t count, |
| 251 const SkPoint pts[], const SkPaint& paint) { | 179 const SkPoint pts[], const SkPaint& paint) { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 paint.getStyle() != SkPaint::kFill_Style || | 382 paint.getStyle() != SkPaint::kFill_Style || |
| 455 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { | 383 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) { |
| 456 // turn off lcd | 384 // turn off lcd |
| 457 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; | 385 flags->fFlags = paint.getFlags() & ~SkPaint::kLCDRenderText_Flag; |
| 458 flags->fHinting = paint.getHinting(); | 386 flags->fHinting = paint.getHinting(); |
| 459 return true; | 387 return true; |
| 460 } | 388 } |
| 461 // we're cool with the paint as is | 389 // we're cool with the paint as is |
| 462 return false; | 390 return false; |
| 463 } | 391 } |
| OLD | NEW |