Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: ui/gfx/android/java_bitmap.h

Issue 2417263002: Pass JavaRef to Java methods in ui. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/android/resources/resource_manager_impl.cc ('k') | ui/gfx/android/java_bitmap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef UI_GFX_ANDROID_JAVA_BITMAP_H_ 5 #ifndef UI_GFX_ANDROID_JAVA_BITMAP_H_
6 #define UI_GFX_ANDROID_JAVA_BITMAP_H_ 6 #define UI_GFX_ANDROID_JAVA_BITMAP_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 12 matching lines...) Expand all
23 BITMAP_FORMAT_ARGB_4444, 23 BITMAP_FORMAT_ARGB_4444,
24 BITMAP_FORMAT_ARGB_8888, 24 BITMAP_FORMAT_ARGB_8888,
25 BITMAP_FORMAT_RGB_565, 25 BITMAP_FORMAT_RGB_565,
26 }; 26 };
27 27
28 // This class wraps a JNI AndroidBitmap object to make it easier to use. It 28 // This class wraps a JNI AndroidBitmap object to make it easier to use. It
29 // handles locking and unlocking of the underlying pixels, along with wrapping 29 // handles locking and unlocking of the underlying pixels, along with wrapping
30 // various JNI methods. 30 // various JNI methods.
31 class GFX_EXPORT JavaBitmap { 31 class GFX_EXPORT JavaBitmap {
32 public: 32 public:
33 explicit JavaBitmap(jobject bitmap); 33 explicit JavaBitmap(const base::android::JavaRef<jobject>& bitmap);
34 ~JavaBitmap(); 34 ~JavaBitmap();
35 35
36 inline void* pixels() { return pixels_; } 36 inline void* pixels() { return pixels_; }
37 inline const void* pixels() const { return pixels_; } 37 inline const void* pixels() const { return pixels_; }
38 inline const gfx::Size& size() const { return size_; } 38 inline const gfx::Size& size() const { return size_; }
39 // Formats are in android/bitmap.h; e.g. ANDROID_BITMAP_FORMAT_RGBA_8888 39 // Formats are in android/bitmap.h; e.g. ANDROID_BITMAP_FORMAT_RGBA_8888
40 inline int format() const { return format_; } 40 inline int format() const { return format_; }
41 inline uint32_t stride() const { return stride_; } 41 inline uint32_t stride() const { return stride_; }
42 inline int byte_count() const { return byte_count_; } 42 inline int byte_count() const { return byte_count_; }
43 43
44 private: 44 private:
45 jobject bitmap_; 45 base::android::ScopedJavaGlobalRef<jobject> bitmap_;
Torne 2016/10/14 13:23:29 I'm not sure whether this replacement is actually
aelias_OOO_until_Jul13 2016/10/14 19:30:34 Seems OK. This code was written in 2012 and I thi
Ted C 2016/10/14 20:40:37 agreed...seems like something we can revisit if ne
46 void* pixels_; 46 void* pixels_;
47 gfx::Size size_; 47 gfx::Size size_;
48 int format_; 48 int format_;
49 uint32_t stride_; 49 uint32_t stride_;
50 int byte_count_; 50 int byte_count_;
51 51
52 DISALLOW_COPY_AND_ASSIGN(JavaBitmap); 52 DISALLOW_COPY_AND_ASSIGN(JavaBitmap);
53 }; 53 };
54 54
55 // Allocates a Java-backed bitmap (android.graphics.Bitmap) with the given 55 // Allocates a Java-backed bitmap (android.graphics.Bitmap) with the given
56 // (non-empty!) size and color type. 56 // (non-empty!) size and color type.
57 GFX_EXPORT base::android::ScopedJavaLocalRef<jobject> CreateJavaBitmap( 57 GFX_EXPORT base::android::ScopedJavaLocalRef<jobject> CreateJavaBitmap(
58 int width, 58 int width,
59 int height, 59 int height,
60 SkColorType color_type); 60 SkColorType color_type);
61 61
62 // Converts |skbitmap| to a Java-backed bitmap (android.graphics.Bitmap). 62 // Converts |skbitmap| to a Java-backed bitmap (android.graphics.Bitmap).
63 // Note: |skbitmap| is assumed to be non-null, non-empty and one of RGBA_8888 or 63 // Note: |skbitmap| is assumed to be non-null, non-empty and one of RGBA_8888 or
64 // RGB_565 formats. 64 // RGB_565 formats.
65 GFX_EXPORT base::android::ScopedJavaLocalRef<jobject> ConvertToJavaBitmap( 65 GFX_EXPORT base::android::ScopedJavaLocalRef<jobject> ConvertToJavaBitmap(
66 const SkBitmap* skbitmap); 66 const SkBitmap* skbitmap);
67 67
68 // Converts |bitmap| to an SkBitmap of the same size and format. 68 // Converts |bitmap| to an SkBitmap of the same size and format.
69 // Note: |jbitmap| is assumed to be non-null, non-empty and of format RGBA_8888. 69 // Note: |jbitmap| is assumed to be non-null, non-empty and of format RGBA_8888.
70 GFX_EXPORT SkBitmap CreateSkBitmapFromJavaBitmap(const JavaBitmap& jbitmap); 70 GFX_EXPORT SkBitmap CreateSkBitmapFromJavaBitmap(const JavaBitmap& jbitmap);
71 71
72 // Returns a Skia color type value for the requested input java Bitmap.Config. 72 // Returns a Skia color type value for the requested input java Bitmap.Config.
73 GFX_EXPORT SkColorType ConvertToSkiaColorType(jobject jbitmap_config); 73 GFX_EXPORT SkColorType
74 ConvertToSkiaColorType(const base::android::JavaRef<jobject>& jbitmap_config);
74 75
75 } // namespace gfx 76 } // namespace gfx
76 77
77 #endif // UI_GFX_ANDROID_JAVA_BITMAP_H_ 78 #endif // UI_GFX_ANDROID_JAVA_BITMAP_H_
OLDNEW
« no previous file with comments | « ui/android/resources/resource_manager_impl.cc ('k') | ui/gfx/android/java_bitmap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698