| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 if (newAlphaType) { | 61 if (newAlphaType) { |
| 62 *newAlphaType = canonicalAlphaType; | 62 *newAlphaType = canonicalAlphaType; |
| 63 } | 63 } |
| 64 return true; | 64 return true; |
| 65 } | 65 } |
| 66 | 66 |
| 67 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) | 67 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) |
| 68 : INHERITED(SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)) | 68 : INHERITED(SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)) |
| 69 , fBitmap(bitmap) { | 69 , fBitmap(bitmap) { |
| 70 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); | 70 SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) { | 73 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) { |
| 74 return Create(info, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
); | 74 return Create(info, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
); |
| 75 } | 75 } |
| 76 | 76 |
| 77 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& sur
faceProps) | 77 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& sur
faceProps) |
| 78 : INHERITED(surfaceProps) | 78 : INHERITED(surfaceProps) |
| 79 , fBitmap(bitmap) { | 79 , fBitmap(bitmap) { |
| 80 SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); | 80 SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, | 83 SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, |
| 84 const SkSurfaceProps& surfaceProps) { | 84 const SkSurfaceProps& surfaceProps) { |
| 85 SkAlphaType newAT = origInfo.alphaType(); | 85 SkAlphaType newAT = origInfo.alphaType(); |
| 86 if (!valid_for_bitmap_device(origInfo, &newAT)) { | 86 if (!valid_for_bitmap_device(origInfo, &newAT)) { |
| 87 return NULL; | 87 return nullptr; |
| 88 } | 88 } |
| 89 | 89 |
| 90 const SkImageInfo info = origInfo.makeAlphaType(newAT); | 90 const SkImageInfo info = origInfo.makeAlphaType(newAT); |
| 91 SkBitmap bitmap; | 91 SkBitmap bitmap; |
| 92 | 92 |
| 93 if (kUnknown_SkColorType == info.colorType()) { | 93 if (kUnknown_SkColorType == info.colorType()) { |
| 94 if (!bitmap.setInfo(info)) { | 94 if (!bitmap.setInfo(info)) { |
| 95 return NULL; | 95 return nullptr; |
| 96 } | 96 } |
| 97 } else { | 97 } else { |
| 98 if (!bitmap.tryAllocPixels(info)) { | 98 if (!bitmap.tryAllocPixels(info)) { |
| 99 return NULL; | 99 return nullptr; |
| 100 } | 100 } |
| 101 if (!bitmap.info().isOpaque()) { | 101 if (!bitmap.info().isOpaque()) { |
| 102 bitmap.eraseColor(SK_ColorTRANSPARENT); | 102 bitmap.eraseColor(SK_ColorTRANSPARENT); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 return new SkBitmapDevice(bitmap, surfaceProps); | 106 return new SkBitmapDevice(bitmap, surfaceProps); |
| 107 } | 107 } |
| 108 | 108 |
| 109 SkImageInfo SkBitmapDevice::imageInfo() const { | 109 SkImageInfo SkBitmapDevice::imageInfo() const { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 135 if (fBitmap.lockPixelsAreWritable() && this->onPeekPixels(pmap)) { | 135 if (fBitmap.lockPixelsAreWritable() && this->onPeekPixels(pmap)) { |
| 136 fBitmap.notifyPixelsChanged(); | 136 fBitmap.notifyPixelsChanged(); |
| 137 return true; | 137 return true; |
| 138 } | 138 } |
| 139 return false; | 139 return false; |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool SkBitmapDevice::onPeekPixels(SkPixmap* pmap) { | 142 bool SkBitmapDevice::onPeekPixels(SkPixmap* pmap) { |
| 143 const SkImageInfo info = fBitmap.info(); | 143 const SkImageInfo info = fBitmap.info(); |
| 144 if (fBitmap.getPixels() && (kUnknown_SkColorType != info.colorType())) { | 144 if (fBitmap.getPixels() && (kUnknown_SkColorType != info.colorType())) { |
| 145 SkColorTable* ctable = NULL; | 145 SkColorTable* ctable = nullptr; |
| 146 pmap->reset(fBitmap.info(), fBitmap.getPixels(), fBitmap.rowBytes(), cta
ble); | 146 pmap->reset(fBitmap.info(), fBitmap.getPixels(), fBitmap.rowBytes(), cta
ble); |
| 147 return true; | 147 return true; |
| 148 } | 148 } |
| 149 return false; | 149 return false; |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPi
xels, | 152 bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPi
xels, |
| 153 size_t srcRowBytes, int x, int y) { | 153 size_t srcRowBytes, int x, int y) { |
| 154 // since we don't stop creating un-pixeled devices yet, check for no pixels
here | 154 // since we don't stop creating un-pixeled devices yet, check for no pixels
here |
| 155 if (NULL == fBitmap.getPixels()) { | 155 if (nullptr == fBitmap.getPixels()) { |
| 156 return false; | 156 return false; |
| 157 } | 157 } |
| 158 | 158 |
| 159 const SkImageInfo dstInfo = fBitmap.info().makeWH(srcInfo.width(), srcInfo.h
eight()); | 159 const SkImageInfo dstInfo = fBitmap.info().makeWH(srcInfo.width(), srcInfo.h
eight()); |
| 160 | 160 |
| 161 void* dstPixels = fBitmap.getAddr(x, y); | 161 void* dstPixels = fBitmap.getAddr(x, y); |
| 162 size_t dstRowBytes = fBitmap.rowBytes(); | 162 size_t dstRowBytes = fBitmap.rowBytes(); |
| 163 | 163 |
| 164 if (SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPix
els, srcRowBytes)) { | 164 if (SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPix
els, srcRowBytes)) { |
| 165 fBitmap.notifyPixelsChanged(); | 165 fBitmap.notifyPixelsChanged(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 draw.drawRect(r, paint); | 204 draw.drawRect(r, paint); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPa
int& paint) { | 207 void SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPa
int& paint) { |
| 208 CHECK_FOR_ANNOTATION(paint); | 208 CHECK_FOR_ANNOTATION(paint); |
| 209 | 209 |
| 210 SkPath path; | 210 SkPath path; |
| 211 path.addOval(oval); | 211 path.addOval(oval); |
| 212 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't | 212 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't |
| 213 // required to override drawOval. | 213 // required to override drawOval. |
| 214 this->drawPath(draw, path, paint, NULL, true); | 214 this->drawPath(draw, path, paint, nullptr, true); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const S
kPaint& paint) { | 217 void SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const S
kPaint& paint) { |
| 218 CHECK_FOR_ANNOTATION(paint); | 218 CHECK_FOR_ANNOTATION(paint); |
| 219 | 219 |
| 220 #ifdef SK_IGNORE_BLURRED_RRECT_OPT | 220 #ifdef SK_IGNORE_BLURRED_RRECT_OPT |
| 221 SkPath path; | 221 SkPath path; |
| 222 | 222 |
| 223 path.addRRect(rrect); | 223 path.addRRect(rrect); |
| 224 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't | 224 // call the VIRTUAL version, so any subclasses who do handle drawPath aren't |
| 225 // required to override drawRRect. | 225 // required to override drawRRect. |
| 226 this->drawPath(draw, path, paint, NULL, true); | 226 this->drawPath(draw, path, paint, nullptr, true); |
| 227 #else | 227 #else |
| 228 draw.drawRRect(rrect, paint); | 228 draw.drawRRect(rrect, paint); |
| 229 #endif | 229 #endif |
| 230 } | 230 } |
| 231 | 231 |
| 232 void SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path, | 232 void SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path, |
| 233 const SkPaint& paint, const SkMatrix* prePathMatri
x, | 233 const SkPaint& paint, const SkMatrix* prePathMatri
x, |
| 234 bool pathIsMutable) { | 234 bool pathIsMutable) { |
| 235 CHECK_FOR_ANNOTATION(paint); | 235 CHECK_FOR_ANNOTATION(paint); |
| 236 draw.drawPath(path, paint, prePathMatrix, pathIsMutable); | 236 draw.drawPath(path, paint, prePathMatrix, pathIsMutable); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, | 239 void SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, |
| 240 const SkMatrix& matrix, const SkPaint& paint) { | 240 const SkMatrix& matrix, const SkPaint& paint) { |
| 241 draw.drawBitmap(bitmap, matrix, NULL, paint); | 241 draw.drawBitmap(bitmap, matrix, nullptr, paint); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, | 244 void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, |
| 245 const SkRect* src, const SkRect& dst, | 245 const SkRect* src, const SkRect& dst, |
| 246 const SkPaint& paint, SkCanvas::SrcRectConst
raint constraint) { | 246 const SkPaint& paint, SkCanvas::SrcRectConst
raint constraint) { |
| 247 SkMatrix matrix; | 247 SkMatrix matrix; |
| 248 SkRect bitmapBounds, tmpSrc, tmpDst; | 248 SkRect bitmapBounds, tmpSrc, tmpDst; |
| 249 SkBitmap tmpBitmap; | 249 SkBitmap tmpBitmap; |
| 250 | 250 |
| 251 bitmapBounds.isetWH(bitmap.width(), bitmap.height()); | 251 bitmapBounds.isetWH(bitmap.width(), bitmap.height()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // it will make a shader and call drawRect, as we do below. | 312 // it will make a shader and call drawRect, as we do below. |
| 313 draw.drawBitmap(*bitmapPtr, matrix, dstPtr, paint); | 313 draw.drawBitmap(*bitmapPtr, matrix, dstPtr, paint); |
| 314 return; | 314 return; |
| 315 } | 315 } |
| 316 | 316 |
| 317 // construct a shader, so we can call drawRect with the dst | 317 // construct a shader, so we can call drawRect with the dst |
| 318 SkShader* s = SkShader::CreateBitmapShader(*bitmapPtr, | 318 SkShader* s = SkShader::CreateBitmapShader(*bitmapPtr, |
| 319 SkShader::kClamp_TileMode, | 319 SkShader::kClamp_TileMode, |
| 320 SkShader::kClamp_TileMode, | 320 SkShader::kClamp_TileMode, |
| 321 &matrix); | 321 &matrix); |
| 322 if (NULL == s) { | 322 if (nullptr == s) { |
| 323 return; | 323 return; |
| 324 } | 324 } |
| 325 | 325 |
| 326 SkPaint paintWithShader(paint); | 326 SkPaint paintWithShader(paint); |
| 327 paintWithShader.setStyle(SkPaint::kFill_Style); | 327 paintWithShader.setStyle(SkPaint::kFill_Style); |
| 328 paintWithShader.setShader(s)->unref(); | 328 paintWithShader.setShader(s)->unref(); |
| 329 | 329 |
| 330 // Call ourself, in case the subclass wanted to share this setup code | 330 // Call ourself, in case the subclass wanted to share this setup code |
| 331 // but handle the drawRect code themselves. | 331 // but handle the drawRect code themselves. |
| 332 this->drawRect(draw, *dstPtr, paintWithShader); | 332 this->drawRect(draw, *dstPtr, paintWithShader); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 paint.getRasterizer() || | 380 paint.getRasterizer() || |
| 381 paint.getPathEffect() || | 381 paint.getPathEffect() || |
| 382 paint.isFakeBoldText() || | 382 paint.isFakeBoldText() || |
| 383 paint.getStyle() != SkPaint::kFill_Style || | 383 paint.getStyle() != SkPaint::kFill_Style || |
| 384 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) | 384 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) |
| 385 { | 385 { |
| 386 return true; | 386 return true; |
| 387 } | 387 } |
| 388 return false; | 388 return false; |
| 389 } | 389 } |
| OLD | NEW |