Chromium Code Reviews| 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[] = "ARGB_4444"; | |
| 21 static const char kARGB_8888[] = "ARGB_8888"; | |
| 22 static const char kRGB_565[] = "RGB_565"; | |
| 23 | |
| 20 JavaBitmap::JavaBitmap(jobject bitmap) | 24 JavaBitmap::JavaBitmap(jobject bitmap) |
| 21 : bitmap_(bitmap), | 25 : bitmap_(bitmap), |
| 22 pixels_(NULL) { | 26 pixels_(NULL) { |
| 23 int err = AndroidBitmap_lockPixels(AttachCurrentThread(), bitmap_, &pixels_); | 27 int err = AndroidBitmap_lockPixels(AttachCurrentThread(), bitmap_, &pixels_); |
| 24 DCHECK(!err); | 28 DCHECK(!err); |
| 25 DCHECK(pixels_); | 29 DCHECK(pixels_); |
| 26 | 30 |
| 27 AndroidBitmapInfo info; | 31 AndroidBitmapInfo info; |
| 28 err = AndroidBitmap_getInfo(AttachCurrentThread(), bitmap_, &info); | 32 err = AndroidBitmap_getInfo(AttachCurrentThread(), bitmap_, &info); |
| 29 DCHECK(!err); | 33 DCHECK(!err); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 env, jname.obj(), size.width(), size.height())); | 99 env, jname.obj(), size.width(), size.height())); |
| 96 if (jobj.is_null()) | 100 if (jobj.is_null()) |
| 97 return SkBitmap(); | 101 return SkBitmap(); |
| 98 | 102 |
| 99 JavaBitmap jbitmap(jobj.obj()); | 103 JavaBitmap jbitmap(jobj.obj()); |
| 100 SkBitmap bitmap = CreateSkBitmapFromJavaBitmap(jbitmap); | 104 SkBitmap bitmap = CreateSkBitmapFromJavaBitmap(jbitmap); |
| 101 return skia::ImageOperations::Resize( | 105 return skia::ImageOperations::Resize( |
| 102 bitmap, skia::ImageOperations::RESIZE_BOX, size.width(), size.height()); | 106 bitmap, skia::ImageOperations::RESIZE_BOX, size.width(), size.height()); |
| 103 } | 107 } |
| 104 | 108 |
| 109 ScopedJavaLocalRef<jstring> ConvertBitmapConfigToString(jobject bitmap_config) { | |
| 110 | |
|
no sievers
2014/02/13 21:34:24
You can just call the function directly instead of
sivag
2014/02/14 12:24:25
Done.
| |
| 111 return Java_BitmapHelper_bitmapConfigToString(AttachCurrentThread(), | |
| 112 bitmap_config); | |
| 113 } | |
| 114 | |
| 115 SkBitmap::Config ConvertToSkiaConfig(jobject bitmap_config) | |
| 116 { | |
| 117 | |
| 118 ScopedJavaLocalRef<jstring> value = ConvertBitmapConfigToString( | |
| 119 bitmap_config); | |
| 120 const std::string& config_value = base::android::ConvertJavaStringToUTF8( | |
| 121 AttachCurrentThread(), value.obj()); | |
| 122 | |
| 123 if (config_value.compare(kARGB_8888) == 0) { | |
| 124 return SkBitmap::kARGB_8888_Config; | |
| 125 } else if (config_value.compare(kRGB_565) == 0) { | |
| 126 return SkBitmap::kRGB_565_Config; | |
| 127 } else if (config_value.compare(kALPHA_8) == 0) { | |
| 128 return SkBitmap::kA8_Config; | |
| 129 } else if (config_value.compare(kARGB_4444) == 0) { | |
| 130 return SkBitmap::kARGB_4444_Config; | |
| 131 } | |
| 132 | |
| 133 return SkBitmap::kNo_Config; | |
| 134 } | |
| 135 | |
| 105 } // namespace gfx | 136 } // namespace gfx |
| OLD | NEW |