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 21 matching lines...) Expand all Loading... |
32 stride_ = info.stride; | 32 stride_ = info.stride; |
33 } | 33 } |
34 | 34 |
35 JavaBitmap::~JavaBitmap() { | 35 JavaBitmap::~JavaBitmap() { |
36 int err = AndroidBitmap_unlockPixels(AttachCurrentThread(), bitmap_); | 36 int err = AndroidBitmap_unlockPixels(AttachCurrentThread(), bitmap_); |
37 DCHECK(!err); | 37 DCHECK(!err); |
38 } | 38 } |
39 | 39 |
40 // static | 40 // static |
41 bool JavaBitmap::RegisterJavaBitmap(JNIEnv* env) { | 41 bool JavaBitmap::RegisterJavaBitmap(JNIEnv* env) { |
42 return ui::RegisterNativesImpl(env); | 42 return RegisterNativesImpl(env); |
43 } | 43 } |
44 | 44 |
45 static ScopedJavaLocalRef<jobject> CreateJavaBitmap(const gfx::Size& size) { | 45 static ScopedJavaLocalRef<jobject> CreateJavaBitmap(const gfx::Size& size) { |
46 return ui::Java_BitmapHelper_createBitmap(AttachCurrentThread(), | 46 return Java_BitmapHelper_createBitmap(AttachCurrentThread(), |
47 size.width(), size.height()); | 47 size.width(), size.height()); |
48 } | 48 } |
49 | 49 |
50 ScopedJavaLocalRef<jobject> ConvertToJavaBitmap(const SkBitmap* skbitmap) { | 50 ScopedJavaLocalRef<jobject> ConvertToJavaBitmap(const SkBitmap* skbitmap) { |
51 DCHECK(skbitmap); | 51 DCHECK(skbitmap); |
52 DCHECK_EQ(skbitmap->bytesPerPixel(), 4); | 52 DCHECK_EQ(skbitmap->bytesPerPixel(), 4); |
53 | 53 |
54 ScopedJavaLocalRef<jobject> jbitmap = | 54 ScopedJavaLocalRef<jobject> jbitmap = |
55 CreateJavaBitmap(gfx::Size(skbitmap->width(), skbitmap->height())); | 55 CreateJavaBitmap(gfx::Size(skbitmap->width(), skbitmap->height())); |
56 SkAutoLockPixels src_lock(*skbitmap); | 56 SkAutoLockPixels src_lock(*skbitmap); |
(...skipping 23 matching lines...) Expand all Loading... |
80 | 80 |
81 memcpy(dst_pixels, src_pixels, skbitmap.getSize()); | 81 memcpy(dst_pixels, src_pixels, skbitmap.getSize()); |
82 | 82 |
83 return skbitmap; | 83 return skbitmap; |
84 } | 84 } |
85 | 85 |
86 SkBitmap CreateSkBitmapFromResource(const char* name, gfx::Size size) { | 86 SkBitmap CreateSkBitmapFromResource(const char* name, gfx::Size size) { |
87 DCHECK(!size.IsEmpty()); | 87 DCHECK(!size.IsEmpty()); |
88 JNIEnv* env = AttachCurrentThread(); | 88 JNIEnv* env = AttachCurrentThread(); |
89 ScopedJavaLocalRef<jstring> jname(env, env->NewStringUTF(name)); | 89 ScopedJavaLocalRef<jstring> jname(env, env->NewStringUTF(name)); |
90 ScopedJavaLocalRef<jobject> jobj(ui::Java_BitmapHelper_decodeDrawableResource( | 90 ScopedJavaLocalRef<jobject> jobj(Java_BitmapHelper_decodeDrawableResource( |
91 env, jname.obj(), size.width(), size.height())); | 91 env, jname.obj(), size.width(), size.height())); |
92 if (jobj.is_null()) | 92 if (jobj.is_null()) |
93 return SkBitmap(); | 93 return SkBitmap(); |
94 | 94 |
95 JavaBitmap jbitmap(jobj.obj()); | 95 JavaBitmap jbitmap(jobj.obj()); |
96 SkBitmap bitmap = CreateSkBitmapFromJavaBitmap(jbitmap); | 96 SkBitmap bitmap = CreateSkBitmapFromJavaBitmap(jbitmap); |
97 return skia::ImageOperations::Resize( | 97 return skia::ImageOperations::Resize( |
98 bitmap, skia::ImageOperations::RESIZE_BOX, size.width(), size.height()); | 98 bitmap, skia::ImageOperations::RESIZE_BOX, size.width(), size.height()); |
99 } | 99 } |
100 | 100 |
101 } // namespace gfx | 101 } // namespace gfx |
OLD | NEW |