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 21 matching lines...) Expand all Loading... |
32 bool fWeOwnThePixels; | 32 bool fWeOwnThePixels; |
33 | 33 |
34 typedef SkSurface_Base INHERITED; | 34 typedef SkSurface_Base INHERITED; |
35 }; | 35 }; |
36 | 36 |
37 /////////////////////////////////////////////////////////////////////////////// | 37 /////////////////////////////////////////////////////////////////////////////// |
38 | 38 |
39 bool SkSurface_Raster::Valid(const SkImage::Info& info, size_t rowBytes) { | 39 bool SkSurface_Raster::Valid(const SkImage::Info& info, size_t rowBytes) { |
40 static const size_t kMaxTotalSize = SK_MaxS32; | 40 static const size_t kMaxTotalSize = SK_MaxS32; |
41 | 41 |
42 bool isOpaque; | 42 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); |
43 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); | |
44 | 43 |
45 int shift = 0; | 44 int shift = 0; |
46 switch (config) { | 45 switch (config) { |
47 case SkBitmap::kA8_Config: | 46 case SkBitmap::kA8_Config: |
48 shift = 0; | 47 shift = 0; |
49 break; | 48 break; |
50 case SkBitmap::kRGB_565_Config: | 49 case SkBitmap::kRGB_565_Config: |
51 shift = 1; | 50 shift = 1; |
52 break; | 51 break; |
53 case SkBitmap::kARGB_8888_Config: | 52 case SkBitmap::kARGB_8888_Config: |
(...skipping 22 matching lines...) Expand all Loading... |
76 uint64_t size = (uint64_t)info.fHeight * rowBytes; | 75 uint64_t size = (uint64_t)info.fHeight * rowBytes; |
77 if (size > kMaxTotalSize) { | 76 if (size > kMaxTotalSize) { |
78 return false; | 77 return false; |
79 } | 78 } |
80 | 79 |
81 return true; | 80 return true; |
82 } | 81 } |
83 | 82 |
84 SkSurface_Raster::SkSurface_Raster(const SkImage::Info& info, void* pixels, size
_t rb) | 83 SkSurface_Raster::SkSurface_Raster(const SkImage::Info& info, void* pixels, size
_t rb) |
85 : INHERITED(info.fWidth, info.fHeight) { | 84 : INHERITED(info.fWidth, info.fHeight) { |
86 bool isOpaque; | 85 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); |
87 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); | 86 fBitmap.setConfig(config, info.fWidth, info.fHeight, rb, info.fAlphaType); |
88 | |
89 fBitmap.setConfig(config, info.fWidth, info.fHeight, rb); | |
90 fBitmap.setPixels(pixels); | 87 fBitmap.setPixels(pixels); |
91 fBitmap.setIsOpaque(isOpaque); | |
92 fWeOwnThePixels = false; // We are "Direct" | 88 fWeOwnThePixels = false; // We are "Direct" |
93 } | 89 } |
94 | 90 |
95 SkSurface_Raster::SkSurface_Raster(const SkImage::Info& info, SkPixelRef* pr, si
ze_t rb) | 91 SkSurface_Raster::SkSurface_Raster(const SkImage::Info& info, SkPixelRef* pr, si
ze_t rb) |
96 : INHERITED(info.fWidth, info.fHeight) { | 92 : INHERITED(info.fWidth, info.fHeight) { |
97 bool isOpaque; | 93 SkBitmap::Config config = SkImageInfoToBitmapConfig(info); |
98 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); | 94 fBitmap.setConfig(config, info.fWidth, info.fHeight, rb, info.fAlphaType); |
99 | |
100 fBitmap.setConfig(config, info.fWidth, info.fHeight, rb); | |
101 fBitmap.setPixelRef(pr); | 95 fBitmap.setPixelRef(pr); |
102 fBitmap.setIsOpaque(isOpaque); | |
103 fWeOwnThePixels = true; | 96 fWeOwnThePixels = true; |
104 | 97 |
105 if (!isOpaque) { | 98 if (!SkAlphaTypeIsOpaque(info.fAlphaType)) { |
106 fBitmap.eraseColor(SK_ColorTRANSPARENT); | 99 fBitmap.eraseColor(SK_ColorTRANSPARENT); |
107 } | 100 } |
108 } | 101 } |
109 | 102 |
110 SkCanvas* SkSurface_Raster::onNewCanvas() { | 103 SkCanvas* SkSurface_Raster::onNewCanvas() { |
111 return SkNEW_ARGS(SkCanvas, (fBitmap)); | 104 return SkNEW_ARGS(SkCanvas, (fBitmap)); |
112 } | 105 } |
113 | 106 |
114 SkSurface* SkSurface_Raster::onNewSurface(const SkImage::Info& info) { | 107 SkSurface* SkSurface_Raster::onNewSurface(const SkImage::Info& info) { |
115 return SkSurface::NewRaster(info); | 108 return SkSurface::NewRaster(info); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 164 |
172 size_t size = (size_t)size64; | 165 size_t size = (size_t)size64; |
173 void* pixels = sk_malloc_throw(size); | 166 void* pixels = sk_malloc_throw(size); |
174 if (NULL == pixels) { | 167 if (NULL == pixels) { |
175 return NULL; | 168 return NULL; |
176 } | 169 } |
177 | 170 |
178 SkAutoTUnref<SkPixelRef> pr(SkNEW_ARGS(SkMallocPixelRef, (pixels, size, NULL
, true))); | 171 SkAutoTUnref<SkPixelRef> pr(SkNEW_ARGS(SkMallocPixelRef, (pixels, size, NULL
, true))); |
179 return SkNEW_ARGS(SkSurface_Raster, (info, pr, rowBytes)); | 172 return SkNEW_ARGS(SkSurface_Raster, (info, pr, rowBytes)); |
180 } | 173 } |
OLD | NEW |