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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 148 } |
149 | 149 |
150 return SkNEW_ARGS(SkSurface_Raster, (info, pixels, rowBytes)); | 150 return SkNEW_ARGS(SkSurface_Raster, (info, pixels, rowBytes)); |
151 } | 151 } |
152 | 152 |
153 SkSurface* SkSurface::NewRaster(const SkImageInfo& info) { | 153 SkSurface* SkSurface::NewRaster(const SkImageInfo& info) { |
154 if (!SkSurface_Raster::Valid(info)) { | 154 if (!SkSurface_Raster::Valid(info)) { |
155 return NULL; | 155 return NULL; |
156 } | 156 } |
157 | 157 |
158 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); | 158 static const size_t kMaxTotalSize = SK_MaxS32; |
159 if (NULL == pr.get()) { | 159 size_t rowBytes = SkImageMinRowBytes(info); |
| 160 uint64_t size64 = (uint64_t)info.fHeight * rowBytes; |
| 161 if (size64 > kMaxTotalSize) { |
160 return NULL; | 162 return NULL; |
161 } | 163 } |
162 return SkNEW_ARGS(SkSurface_Raster, (info, pr, info.minRowBytes())); | 164 |
| 165 size_t size = (size_t)size64; |
| 166 void* pixels = sk_malloc_throw(size); |
| 167 if (NULL == pixels) { |
| 168 return NULL; |
| 169 } |
| 170 |
| 171 SkAutoTUnref<SkPixelRef> pr(SkNEW_ARGS(SkMallocPixelRef, (pixels, size, NULL
, true))); |
| 172 return SkNEW_ARGS(SkSurface_Raster, (info, pr, rowBytes)); |
163 } | 173 } |
OLD | NEW |