| 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 "SkImage_Base.h" | 8 #include "SkImage_Base.h" |
| 9 #include "SkImagePriv.h" | 9 #include "SkImagePriv.h" |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkData.h" | 12 #include "SkData.h" |
| 13 #include "SkDataPixelRef.h" | 13 #include "SkMallocPixelRef.h" |
| 14 | 14 |
| 15 class SkImage_Raster : public SkImage_Base { | 15 class SkImage_Raster : public SkImage_Base { |
| 16 public: | 16 public: |
| 17 static bool ValidArgs(const Info& info, size_t rowBytes) { | 17 static bool ValidArgs(const Info& info, size_t rowBytes) { |
| 18 const int maxDimension = SK_MaxS32 >> 2; | 18 const int maxDimension = SK_MaxS32 >> 2; |
| 19 const size_t kMaxPixelByteSize = SK_MaxS32; | 19 const size_t kMaxPixelByteSize = SK_MaxS32; |
| 20 | 20 |
| 21 if (info.fWidth < 0 || info.fHeight < 0) { | 21 if (info.fWidth < 0 || info.fHeight < 0) { |
| 22 return false; | 22 return false; |
| 23 } | 23 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 if (NULL == gEmpty) { | 78 if (NULL == gEmpty) { |
| 79 gEmpty = SkNEW(SkImage_Raster); | 79 gEmpty = SkNEW(SkImage_Raster); |
| 80 } | 80 } |
| 81 gEmpty->ref(); | 81 gEmpty->ref(); |
| 82 return gEmpty; | 82 return gEmpty; |
| 83 } | 83 } |
| 84 | 84 |
| 85 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes) | 85 SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes) |
| 86 : INHERITED(info.fWidth, info.fHeight) { | 86 : INHERITED(info.fWidth, info.fHeight) { |
| 87 fBitmap.setConfig(info, rowBytes); | 87 fBitmap.setConfig(info, rowBytes); |
| 88 fBitmap.setPixelRef(SkNEW_ARGS(SkDataPixelRef, (info, data)))->unref(); | 88 SkAutoTUnref<SkPixelRef> ref( |
| 89 SkMallocPixelRef::NewWithData(info, rowBytes, NULL, data, 0)); |
| 90 fBitmap.setPixelRef(ref, 0); |
| 89 fBitmap.setImmutable(); | 91 fBitmap.setImmutable(); |
| 90 } | 92 } |
| 91 | 93 |
| 92 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes
) | 94 SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes
) |
| 93 : INHERITED(info.fWidth, info.fHeight) { | 95 : INHERITED(info.fWidth, info.fHeight) { |
| 94 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); | 96 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); |
| 95 | 97 |
| 96 fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes, info.fAlphaTy
pe); | 98 fBitmap.setConfig(config, info.fWidth, info.fHeight, rowBytes, info.fAlphaTy
pe); |
| 97 fBitmap.setPixelRef(pr); | 99 fBitmap.setPixelRef(pr); |
| 98 } | 100 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 157 } |
| 156 | 158 |
| 157 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, | 159 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, |
| 158 size_t rowBytes) { | 160 size_t rowBytes) { |
| 159 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes)); | 161 return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes)); |
| 160 } | 162 } |
| 161 | 163 |
| 162 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) { | 164 SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) { |
| 163 return ((SkImage_Raster*)image)->getPixelRef(); | 165 return ((SkImage_Raster*)image)->getPixelRef(); |
| 164 } | 166 } |
| OLD | NEW |