| 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" |
| 11 #include "SkMallocPixelRef.h" |
| 11 #include "SkMatrix.h" | 12 #include "SkMatrix.h" |
| 12 #include "SkPaint.h" | 13 #include "SkPaint.h" |
| 13 #include "SkPath.h" | 14 #include "SkPath.h" |
| 14 #include "SkPixelRef.h" | 15 #include "SkPixelRef.h" |
| 15 #include "SkPixmap.h" | 16 #include "SkPixmap.h" |
| 16 #include "SkShader.h" | 17 #include "SkShader.h" |
| 17 #include "SkSurface.h" | 18 #include "SkSurface.h" |
| 18 #include "SkXfermode.h" | 19 #include "SkXfermode.h" |
| 19 | 20 |
| 20 class SkColorTable; | 21 class SkColorTable; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 return nullptr; | 88 return nullptr; |
| 88 } | 89 } |
| 89 | 90 |
| 90 const SkImageInfo info = origInfo.makeAlphaType(newAT); | 91 const SkImageInfo info = origInfo.makeAlphaType(newAT); |
| 91 SkBitmap bitmap; | 92 SkBitmap bitmap; |
| 92 | 93 |
| 93 if (kUnknown_SkColorType == info.colorType()) { | 94 if (kUnknown_SkColorType == info.colorType()) { |
| 94 if (!bitmap.setInfo(info)) { | 95 if (!bitmap.setInfo(info)) { |
| 95 return nullptr; | 96 return nullptr; |
| 96 } | 97 } |
| 97 } else { | 98 } else if (bitmap.info().isOpaque()) { |
| 99 // If this bitmap is opaque, we don't have any sensible default color, |
| 100 // so we just return uninitialized pixels. |
| 98 if (!bitmap.tryAllocPixels(info)) { | 101 if (!bitmap.tryAllocPixels(info)) { |
| 99 return nullptr; | 102 return nullptr; |
| 100 } | 103 } |
| 101 if (!bitmap.info().isOpaque()) { | 104 } else { |
| 102 bitmap.eraseColor(SK_ColorTRANSPARENT); | 105 // This bitmap has transparency, so we'll zero the pixels (to transparen
t). |
| 106 // We use a ZeroedPRFactory as a faster alloc-then-eraseColor(SK_ColorTR
ANSPARENT). |
| 107 SkMallocPixelRef::ZeroedPRFactory factory; |
| 108 if (!bitmap.tryAllocPixels(info, &factory, nullptr/*color table*/)) { |
| 109 return nullptr; |
| 103 } | 110 } |
| 104 } | 111 } |
| 105 | 112 |
| 106 return new SkBitmapDevice(bitmap, surfaceProps); | 113 return new SkBitmapDevice(bitmap, surfaceProps); |
| 107 } | 114 } |
| 108 | 115 |
| 109 SkImageInfo SkBitmapDevice::imageInfo() const { | 116 SkImageInfo SkBitmapDevice::imageInfo() const { |
| 110 return fBitmap.info(); | 117 return fBitmap.info(); |
| 111 } | 118 } |
| 112 | 119 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 paint.getRasterizer() || | 387 paint.getRasterizer() || |
| 381 paint.getPathEffect() || | 388 paint.getPathEffect() || |
| 382 paint.isFakeBoldText() || | 389 paint.isFakeBoldText() || |
| 383 paint.getStyle() != SkPaint::kFill_Style || | 390 paint.getStyle() != SkPaint::kFill_Style || |
| 384 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) | 391 !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) |
| 385 { | 392 { |
| 386 return true; | 393 return true; |
| 387 } | 394 } |
| 388 return false; | 395 return false; |
| 389 } | 396 } |
| OLD | NEW |