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 23 matching lines...) Expand all Loading... |
34 JavaBitmap::~JavaBitmap() { | 34 JavaBitmap::~JavaBitmap() { |
35 int err = AndroidBitmap_unlockPixels(AttachCurrentThread(), bitmap_); | 35 int err = AndroidBitmap_unlockPixels(AttachCurrentThread(), bitmap_); |
36 DCHECK(!err); | 36 DCHECK(!err); |
37 } | 37 } |
38 | 38 |
39 // static | 39 // static |
40 bool JavaBitmap::RegisterJavaBitmap(JNIEnv* env) { | 40 bool JavaBitmap::RegisterJavaBitmap(JNIEnv* env) { |
41 return RegisterNativesImpl(env); | 41 return RegisterNativesImpl(env); |
42 } | 42 } |
43 | 43 |
44 static ScopedJavaLocalRef<jobject> CreateJavaBitmap(int width, | |
45 int height, | |
46 int bitmap_config) { | |
47 | |
48 return Java_BitmapHelper_createBitmap( | |
49 AttachCurrentThread(), width, height, bitmap_config); | |
50 } | |
51 | |
52 static int SkBitmapConfigToBitmapFormat(SkBitmap::Config bitmap_config) { | 44 static int SkBitmapConfigToBitmapFormat(SkBitmap::Config bitmap_config) { |
53 switch (bitmap_config) { | 45 switch (bitmap_config) { |
54 case SkBitmap::kA8_Config: | 46 case SkBitmap::kA8_Config: |
55 return BITMAP_FORMAT_ALPHA_8; | 47 return BITMAP_FORMAT_ALPHA_8; |
56 case SkBitmap::kARGB_4444_Config: | 48 case SkBitmap::kARGB_4444_Config: |
57 return BITMAP_FORMAT_ARGB_4444; | 49 return BITMAP_FORMAT_ARGB_4444; |
58 case SkBitmap::kARGB_8888_Config: | 50 case SkBitmap::kARGB_8888_Config: |
59 return BITMAP_FORMAT_ARGB_8888; | 51 return BITMAP_FORMAT_ARGB_8888; |
60 case SkBitmap::kRGB_565_Config: | 52 case SkBitmap::kRGB_565_Config: |
61 return BITMAP_FORMAT_RGB_565; | 53 return BITMAP_FORMAT_RGB_565; |
62 case SkBitmap::kNo_Config: | 54 case SkBitmap::kNo_Config: |
63 default: | 55 default: |
64 NOTREACHED(); | 56 NOTREACHED(); |
65 return BITMAP_FORMAT_NO_CONFIG; | 57 return BITMAP_FORMAT_NO_CONFIG; |
66 } | 58 } |
67 } | 59 } |
68 | 60 |
| 61 ScopedJavaLocalRef<jobject> CreateJavaBitmap(int width, |
| 62 int height, |
| 63 SkBitmap::Config bitmap_config) { |
| 64 int java_bitmap_config = SkBitmapConfigToBitmapFormat(bitmap_config); |
| 65 return Java_BitmapHelper_createBitmap( |
| 66 AttachCurrentThread(), width, height, java_bitmap_config); |
| 67 } |
| 68 |
69 ScopedJavaLocalRef<jobject> ConvertToJavaBitmap(const SkBitmap* skbitmap) { | 69 ScopedJavaLocalRef<jobject> ConvertToJavaBitmap(const SkBitmap* skbitmap) { |
70 DCHECK(skbitmap); | 70 DCHECK(skbitmap); |
71 SkBitmap::Config config = skbitmap->getConfig(); | 71 SkBitmap::Config bitmap_config = skbitmap->getConfig(); |
72 DCHECK((config == SkBitmap::kRGB_565_Config) || | 72 DCHECK((bitmap_config == SkBitmap::kRGB_565_Config) || |
73 (config == SkBitmap::kARGB_8888_Config)); | 73 (bitmap_config == SkBitmap::kARGB_8888_Config)); |
74 int java_bitmap_config = SkBitmapConfigToBitmapFormat(config); | |
75 ScopedJavaLocalRef<jobject> jbitmap = CreateJavaBitmap( | 74 ScopedJavaLocalRef<jobject> jbitmap = CreateJavaBitmap( |
76 skbitmap->width(), skbitmap->height(), java_bitmap_config); | 75 skbitmap->width(), skbitmap->height(), bitmap_config); |
77 SkAutoLockPixels src_lock(*skbitmap); | 76 SkAutoLockPixels src_lock(*skbitmap); |
78 JavaBitmap dst_lock(jbitmap.obj()); | 77 JavaBitmap dst_lock(jbitmap.obj()); |
79 void* src_pixels = skbitmap->getPixels(); | 78 void* src_pixels = skbitmap->getPixels(); |
80 void* dst_pixels = dst_lock.pixels(); | 79 void* dst_pixels = dst_lock.pixels(); |
81 memcpy(dst_pixels, src_pixels, skbitmap->getSize()); | 80 memcpy(dst_pixels, src_pixels, skbitmap->getSize()); |
82 | 81 |
83 return jbitmap; | 82 return jbitmap; |
84 } | 83 } |
85 | 84 |
86 SkBitmap CreateSkBitmapFromJavaBitmap(JavaBitmap& jbitmap) { | 85 SkBitmap CreateSkBitmapFromJavaBitmap(JavaBitmap& jbitmap) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 return SkBitmap::kARGB_8888_Config; | 130 return SkBitmap::kARGB_8888_Config; |
132 case BITMAP_FORMAT_RGB_565: | 131 case BITMAP_FORMAT_RGB_565: |
133 return SkBitmap::kRGB_565_Config; | 132 return SkBitmap::kRGB_565_Config; |
134 case BITMAP_FORMAT_NO_CONFIG: | 133 case BITMAP_FORMAT_NO_CONFIG: |
135 default: | 134 default: |
136 return SkBitmap::kNo_Config; | 135 return SkBitmap::kNo_Config; |
137 } | 136 } |
138 } | 137 } |
139 | 138 |
140 } // namespace gfx | 139 } // namespace gfx |
OLD | NEW |