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 11 matching lines...) Expand all Loading... |
22 int err = AndroidBitmap_lockPixels(AttachCurrentThread(), bitmap_, &pixels_); | 22 int err = AndroidBitmap_lockPixels(AttachCurrentThread(), bitmap_, &pixels_); |
23 DCHECK(!err); | 23 DCHECK(!err); |
24 DCHECK(pixels_); | 24 DCHECK(pixels_); |
25 | 25 |
26 AndroidBitmapInfo info; | 26 AndroidBitmapInfo info; |
27 err = AndroidBitmap_getInfo(AttachCurrentThread(), bitmap_, &info); | 27 err = AndroidBitmap_getInfo(AttachCurrentThread(), bitmap_, &info); |
28 DCHECK(!err); | 28 DCHECK(!err); |
29 size_ = gfx::Size(info.width, info.height); | 29 size_ = gfx::Size(info.width, info.height); |
30 format_ = info.format; | 30 format_ = info.format; |
31 stride_ = info.stride; | 31 stride_ = info.stride; |
| 32 byte_count_ = Java_BitmapHelper_getByteCount(AttachCurrentThread(), bitmap_); |
32 } | 33 } |
33 | 34 |
34 JavaBitmap::~JavaBitmap() { | 35 JavaBitmap::~JavaBitmap() { |
35 int err = AndroidBitmap_unlockPixels(AttachCurrentThread(), bitmap_); | 36 int err = AndroidBitmap_unlockPixels(AttachCurrentThread(), bitmap_); |
36 DCHECK(!err); | 37 DCHECK(!err); |
37 } | 38 } |
38 | 39 |
39 // static | 40 // static |
40 bool JavaBitmap::RegisterJavaBitmap(JNIEnv* env) { | 41 bool JavaBitmap::RegisterJavaBitmap(JNIEnv* env) { |
41 return RegisterNativesImpl(env); | 42 return RegisterNativesImpl(env); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 break; | 102 break; |
102 case ANDROID_BITMAP_FORMAT_A_8: | 103 case ANDROID_BITMAP_FORMAT_A_8: |
103 skbitmap.allocPixels(SkImageInfo::MakeA8(src_size.width(), | 104 skbitmap.allocPixels(SkImageInfo::MakeA8(src_size.width(), |
104 src_size.height()), | 105 src_size.height()), |
105 jbitmap.stride()); | 106 jbitmap.stride()); |
106 break; | 107 break; |
107 default: | 108 default: |
108 CHECK(false) << "Invalid Java bitmap format: " << jbitmap.format(); | 109 CHECK(false) << "Invalid Java bitmap format: " << jbitmap.format(); |
109 break; | 110 break; |
110 } | 111 } |
| 112 CHECK_EQ(jbitmap.byte_count(), static_cast<int>(skbitmap.getSize())); |
111 const void* src_pixels = jbitmap.pixels(); | 113 const void* src_pixels = jbitmap.pixels(); |
112 void* dst_pixels = skbitmap.getPixels(); | 114 void* dst_pixels = skbitmap.getPixels(); |
113 memcpy(dst_pixels, src_pixels, skbitmap.getSize()); | 115 memcpy(dst_pixels, src_pixels, skbitmap.getSize()); |
114 | 116 |
115 return skbitmap; | 117 return skbitmap; |
116 } | 118 } |
117 | 119 |
118 SkColorType ConvertToSkiaColorType(jobject bitmap_config) { | 120 SkColorType ConvertToSkiaColorType(jobject bitmap_config) { |
119 int jbitmap_config = Java_BitmapHelper_getBitmapFormatForConfig( | 121 int jbitmap_config = Java_BitmapHelper_getBitmapFormatForConfig( |
120 AttachCurrentThread(), bitmap_config); | 122 AttachCurrentThread(), bitmap_config); |
121 switch (jbitmap_config) { | 123 switch (jbitmap_config) { |
122 case BITMAP_FORMAT_ALPHA_8: | 124 case BITMAP_FORMAT_ALPHA_8: |
123 return kAlpha_8_SkColorType; | 125 return kAlpha_8_SkColorType; |
124 case BITMAP_FORMAT_ARGB_4444: | 126 case BITMAP_FORMAT_ARGB_4444: |
125 return kARGB_4444_SkColorType; | 127 return kARGB_4444_SkColorType; |
126 case BITMAP_FORMAT_ARGB_8888: | 128 case BITMAP_FORMAT_ARGB_8888: |
127 return kN32_SkColorType; | 129 return kN32_SkColorType; |
128 case BITMAP_FORMAT_RGB_565: | 130 case BITMAP_FORMAT_RGB_565: |
129 return kRGB_565_SkColorType; | 131 return kRGB_565_SkColorType; |
130 case BITMAP_FORMAT_NO_CONFIG: | 132 case BITMAP_FORMAT_NO_CONFIG: |
131 default: | 133 default: |
132 return kUnknown_SkColorType; | 134 return kUnknown_SkColorType; |
133 } | 135 } |
134 } | 136 } |
135 | 137 |
136 } // namespace gfx | 138 } // namespace gfx |
OLD | NEW |