OLD | NEW |
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 "SkSurface_Base.h" | 8 #include "SkSurface_Base.h" |
9 #include "SkImagePriv.h" | 9 #include "SkImagePriv.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 const SkSurfaceProps* props) { | 201 const SkSurfaceProps* props) { |
202 return MakeRasterDirectReleaseProc(info, pixels, rowBytes, nullptr, nullptr,
props); | 202 return MakeRasterDirectReleaseProc(info, pixels, rowBytes, nullptr, nullptr,
props); |
203 } | 203 } |
204 | 204 |
205 sk_sp<SkSurface> SkSurface::MakeRaster(const SkImageInfo& info, size_t rowBytes, | 205 sk_sp<SkSurface> SkSurface::MakeRaster(const SkImageInfo& info, size_t rowBytes, |
206 const SkSurfaceProps* props) { | 206 const SkSurfaceProps* props) { |
207 if (!SkSurface_Raster::Valid(info)) { | 207 if (!SkSurface_Raster::Valid(info)) { |
208 return nullptr; | 208 return nullptr; |
209 } | 209 } |
210 | 210 |
211 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, rowBytes, null
ptr)); | 211 // If the requested alpha type is opaque, then leave the pixels uninitialize
d. |
| 212 // Alpha formats can be safely initialiezd to zero. |
| 213 SkAutoTUnref<SkPixelRef> pr(info.isOpaque() |
| 214 ? SkMallocPixelRef::NewAllocate(info, rowBytes,
nullptr) |
| 215 : SkMallocPixelRef::NewZeroed(info, rowBytes, nu
llptr)); |
212 if (nullptr == pr.get()) { | 216 if (nullptr == pr.get()) { |
213 return nullptr; | 217 return nullptr; |
214 } | 218 } |
215 if (rowBytes) { | 219 if (rowBytes) { |
216 SkASSERT(pr->rowBytes() == rowBytes); | 220 SkASSERT(pr->rowBytes() == rowBytes); |
217 } | 221 } |
218 return sk_make_sp<SkSurface_Raster>(pr, props); | 222 return sk_make_sp<SkSurface_Raster>(pr, props); |
219 } | 223 } |
OLD | NEW |