OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/android/java_bitmap.h" | 5 #include "ui/gfx/android/java_bitmap.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 | 8 |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // TODO(jdduke): Convert to DCHECK's when sufficient data has been capture for | 110 // TODO(jdduke): Convert to DCHECK's when sufficient data has been capture for |
111 // crbug.com/341406. | 111 // crbug.com/341406. |
112 CHECK_EQ(jbitmap.format(), ANDROID_BITMAP_FORMAT_RGBA_8888); | 112 CHECK_EQ(jbitmap.format(), ANDROID_BITMAP_FORMAT_RGBA_8888); |
113 CHECK(!jbitmap.size().IsEmpty()); | 113 CHECK(!jbitmap.size().IsEmpty()); |
114 CHECK_GT(jbitmap.stride(), 0U); | 114 CHECK_GT(jbitmap.stride(), 0U); |
115 CHECK(jbitmap.pixels()); | 115 CHECK(jbitmap.pixels()); |
116 | 116 |
117 gfx::Size src_size = jbitmap.size(); | 117 gfx::Size src_size = jbitmap.size(); |
118 | 118 |
119 SkBitmap skbitmap; | 119 SkBitmap skbitmap; |
120 skbitmap.allocPixels(SkImageInfo::MakeN32Premul(src_size.width(), | 120 if (!skbitmap.allocPixels(SkImageInfo::MakeN32Premul(src_size.width(), |
121 src_size.height()), | 121 src_size.height()), |
122 jbitmap.stride()); | 122 jbitmap.stride())) { |
| 123 LOG(FATAL) << " Failed to allocate bitmap of size " << src_size.width() |
| 124 << "x" << src_size.height() << " stride=" << jbitmap.stride(); |
| 125 } |
123 const void* src_pixels = jbitmap.pixels(); | 126 const void* src_pixels = jbitmap.pixels(); |
124 void* dst_pixels = skbitmap.getPixels(); | 127 void* dst_pixels = skbitmap.getPixels(); |
125 memcpy(dst_pixels, src_pixels, skbitmap.getSize()); | 128 memcpy(dst_pixels, src_pixels, skbitmap.getSize()); |
126 | 129 |
127 return skbitmap; | 130 return skbitmap; |
128 } | 131 } |
129 | 132 |
130 SkColorType ConvertToSkiaColorType(jobject bitmap_config) { | 133 SkColorType ConvertToSkiaColorType(jobject bitmap_config) { |
131 int jbitmap_config = Java_BitmapHelper_getBitmapFormatForConfig( | 134 int jbitmap_config = Java_BitmapHelper_getBitmapFormatForConfig( |
132 AttachCurrentThread(), bitmap_config); | 135 AttachCurrentThread(), bitmap_config); |
133 switch (jbitmap_config) { | 136 switch (jbitmap_config) { |
134 case BITMAP_FORMAT_ALPHA_8: | 137 case BITMAP_FORMAT_ALPHA_8: |
135 return kAlpha_8_SkColorType; | 138 return kAlpha_8_SkColorType; |
136 case BITMAP_FORMAT_ARGB_4444: | 139 case BITMAP_FORMAT_ARGB_4444: |
137 return kARGB_4444_SkColorType; | 140 return kARGB_4444_SkColorType; |
138 case BITMAP_FORMAT_ARGB_8888: | 141 case BITMAP_FORMAT_ARGB_8888: |
139 return kN32_SkColorType; | 142 return kN32_SkColorType; |
140 case BITMAP_FORMAT_RGB_565: | 143 case BITMAP_FORMAT_RGB_565: |
141 return kRGB_565_SkColorType; | 144 return kRGB_565_SkColorType; |
142 case BITMAP_FORMAT_NO_CONFIG: | 145 case BITMAP_FORMAT_NO_CONFIG: |
143 default: | 146 default: |
144 return kUnknown_SkColorType; | 147 return kUnknown_SkColorType; |
145 } | 148 } |
146 } | 149 } |
147 | 150 |
148 } // namespace gfx | 151 } // namespace gfx |
OLD | NEW |