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" |
11 #include "jni/BitmapHelper_jni.h" | 11 #include "jni/BitmapHelper_jni.h" |
12 #include "skia/ext/image_operations.h" | 12 #include "skia/ext/image_operations.h" |
13 #include "third_party/skia/include/core/SkBitmap.h" | |
14 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
15 | 14 |
16 using base::android::AttachCurrentThread; | 15 using base::android::AttachCurrentThread; |
17 | 16 |
18 namespace gfx { | 17 namespace gfx { |
19 | 18 |
19 static const char kALPHA_8[] = "ALPHA_8"; | |
20 static const char kARGB_4444[] = "kARGB_4444"; | |
21 static const char kARGB_8888[] = "ARGB_8888"; | |
22 static const char kRGB_565[] = "RGB_565"; | |
23 static const char kBitmapConfigClassPath[] = "android/graphics/Bitmap$Config"; | |
24 static base::subtle::AtomicWord g_BitmapConfig_method = 0; | |
25 | |
20 JavaBitmap::JavaBitmap(jobject bitmap) | 26 JavaBitmap::JavaBitmap(jobject bitmap) |
21 : bitmap_(bitmap), | 27 : bitmap_(bitmap), |
22 pixels_(NULL) { | 28 pixels_(NULL) { |
23 int err = AndroidBitmap_lockPixels(AttachCurrentThread(), bitmap_, &pixels_); | 29 int err = AndroidBitmap_lockPixels(AttachCurrentThread(), bitmap_, &pixels_); |
24 DCHECK(!err); | 30 DCHECK(!err); |
25 DCHECK(pixels_); | 31 DCHECK(pixels_); |
26 | 32 |
27 AndroidBitmapInfo info; | 33 AndroidBitmapInfo info; |
28 err = AndroidBitmap_getInfo(AttachCurrentThread(), bitmap_, &info); | 34 err = AndroidBitmap_getInfo(AttachCurrentThread(), bitmap_, &info); |
29 DCHECK(!err); | 35 DCHECK(!err); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 env, jname.obj(), size.width(), size.height())); | 101 env, jname.obj(), size.width(), size.height())); |
96 if (jobj.is_null()) | 102 if (jobj.is_null()) |
97 return SkBitmap(); | 103 return SkBitmap(); |
98 | 104 |
99 JavaBitmap jbitmap(jobj.obj()); | 105 JavaBitmap jbitmap(jobj.obj()); |
100 SkBitmap bitmap = CreateSkBitmapFromJavaBitmap(jbitmap); | 106 SkBitmap bitmap = CreateSkBitmapFromJavaBitmap(jbitmap); |
101 return skia::ImageOperations::Resize( | 107 return skia::ImageOperations::Resize( |
102 bitmap, skia::ImageOperations::RESIZE_BOX, size.width(), size.height()); | 108 bitmap, skia::ImageOperations::RESIZE_BOX, size.width(), size.height()); |
103 } | 109 } |
104 | 110 |
111 SkBitmap::Config ToSkiaBitmapConfig(JNIEnv* env, | |
112 jobject bitmap_config) | |
113 { | |
114 static jclass g_BitmapConfig_clazz = reinterpret_cast<jclass> | |
115 (env->NewGlobalRef(base::android::GetClass(env, | |
116 kBitmapConfigClassPath).obj())); | |
117 DCHECK(g_BitmapConfig_clazz); | |
118 jmethodID method_id = base::android::MethodID::LazyGet< | |
119 base::android::MethodID::TYPE_INSTANCE>(env, | |
120 g_BitmapConfig_clazz, | |
121 "name", | |
122 "()Ljava/lang/String;", | |
123 &g_BitmapConfig_method); | |
124 | |
125 jstring value = (jstring)env->CallObjectMethod(bitmap_config, method_id); | |
126 const std::string config_value = base::android::ConvertJavaStringToUTF8(env, | |
vivekg
2014/02/11 17:59:02
const std::string&
sivag
2014/02/13 16:31:52
Done.
| |
127 value); | |
128 base::android::CheckException(env); | |
129 | |
130 if (config_value.compare(kARGB_8888) == 0) { | |
131 return SkBitmap::kARGB_8888_Config; | |
132 } else if (config_value.compare(kRGB_565) == 0) { | |
133 return SkBitmap::kRGB_565_Config; | |
134 } else if (config_value.compare(kALPHA_8) == 0) { | |
135 return SkBitmap::kA8_Config; | |
136 } else if (config_value.compare(kARGB_4444) == 0) { | |
137 return SkBitmap::kARGB_4444_Config; | |
138 } | |
139 | |
140 return SkBitmap::kNo_Config; | |
141 } | |
142 | |
105 } // namespace gfx | 143 } // namespace gfx |
OLD | NEW |