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

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

Issue 184453002: Android::Pass Bitmap.Config instead of bool to CreateJavaBitmap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added NOTREACHED check. Created 6 years, 9 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/java/src/org/chromium/ui/gfx/BitmapHelper.java ('k') | no next file » | 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 #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
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, int height, 44 static ScopedJavaLocalRef<jobject> CreateJavaBitmap(int width,
45 bool is565_config) { 45 int height,
46 return Java_BitmapHelper_createBitmap(AttachCurrentThread(), 46 int bitmap_config) {
47 width, height, is565_config); 47
48 return Java_BitmapHelper_createBitmap(
49 AttachCurrentThread(), width, height, bitmap_config);
50 }
51
52 static int SkBitmapConfigToBitmapFormat(SkBitmap::Config bitmap_config) {
53 switch (bitmap_config) {
54 case SkBitmap::kA8_Config:
55 return BITMAP_FORMAT_ALPHA_8;
56 case SkBitmap::kARGB_4444_Config:
57 return BITMAP_FORMAT_ARGB_4444;
58 case SkBitmap::kARGB_8888_Config:
59 return BITMAP_FORMAT_ARGB_8888;
60 case SkBitmap::kRGB_565_Config:
61 return BITMAP_FORMAT_RGB_565;
62 case SkBitmap::kNo_Config:
63 default:
64 NOTREACHED();
65 return BITMAP_FORMAT_NO_CONFIG;
66 }
48 } 67 }
49 68
50 ScopedJavaLocalRef<jobject> ConvertToJavaBitmap(const SkBitmap* skbitmap) { 69 ScopedJavaLocalRef<jobject> ConvertToJavaBitmap(const SkBitmap* skbitmap) {
51 DCHECK(skbitmap); 70 DCHECK(skbitmap);
52 SkBitmap::Config config = skbitmap->getConfig(); 71 SkBitmap::Config config = skbitmap->getConfig();
53 DCHECK((config == SkBitmap::kRGB_565_Config) || 72 DCHECK((config == SkBitmap::kRGB_565_Config) ||
54 (config == SkBitmap::kARGB_8888_Config)); 73 (config == SkBitmap::kARGB_8888_Config));
55 // If the Config is not RGB565 it is default i.e ARGB8888 74 int java_bitmap_config = SkBitmapConfigToBitmapFormat(config);
56 ScopedJavaLocalRef<jobject> jbitmap = 75 ScopedJavaLocalRef<jobject> jbitmap = CreateJavaBitmap(
57 CreateJavaBitmap(skbitmap->width(), skbitmap->height(), 76 skbitmap->width(), skbitmap->height(), java_bitmap_config);
58 (config == SkBitmap::kRGB_565_Config));
59 SkAutoLockPixels src_lock(*skbitmap); 77 SkAutoLockPixels src_lock(*skbitmap);
60 JavaBitmap dst_lock(jbitmap.obj()); 78 JavaBitmap dst_lock(jbitmap.obj());
61 void* src_pixels = skbitmap->getPixels(); 79 void* src_pixels = skbitmap->getPixels();
62 void* dst_pixels = dst_lock.pixels(); 80 void* dst_pixels = dst_lock.pixels();
63 memcpy(dst_pixels, src_pixels, skbitmap->getSize()); 81 memcpy(dst_pixels, src_pixels, skbitmap->getSize());
64 82
65 return jbitmap; 83 return jbitmap;
66 } 84 }
67 85
68 SkBitmap CreateSkBitmapFromJavaBitmap(JavaBitmap& jbitmap) { 86 SkBitmap CreateSkBitmapFromJavaBitmap(JavaBitmap& jbitmap) {
(...skipping 26 matching lines...) Expand all
95 if (jobj.is_null()) 113 if (jobj.is_null())
96 return SkBitmap(); 114 return SkBitmap();
97 115
98 JavaBitmap jbitmap(jobj.obj()); 116 JavaBitmap jbitmap(jobj.obj());
99 SkBitmap bitmap = CreateSkBitmapFromJavaBitmap(jbitmap); 117 SkBitmap bitmap = CreateSkBitmapFromJavaBitmap(jbitmap);
100 return skia::ImageOperations::Resize( 118 return skia::ImageOperations::Resize(
101 bitmap, skia::ImageOperations::RESIZE_BOX, size.width(), size.height()); 119 bitmap, skia::ImageOperations::RESIZE_BOX, size.width(), size.height());
102 } 120 }
103 121
104 SkBitmap::Config ConvertToSkiaConfig(jobject bitmap_config) { 122 SkBitmap::Config ConvertToSkiaConfig(jobject bitmap_config) {
105 int jbitmap_config = 123 int jbitmap_config = Java_BitmapHelper_getBitmapFormatForConfig(
106 Java_BitmapHelper_bitmapConfig(AttachCurrentThread(), bitmap_config); 124 AttachCurrentThread(), bitmap_config);
107 switch (jbitmap_config) { 125 switch (jbitmap_config) {
108 case BITMAP_FORMAT_ALPHA_8: 126 case BITMAP_FORMAT_ALPHA_8:
109 return SkBitmap::kA8_Config; 127 return SkBitmap::kA8_Config;
110 case BITMAP_FORMAT_ARGB_4444: 128 case BITMAP_FORMAT_ARGB_4444:
111 return SkBitmap::kARGB_4444_Config; 129 return SkBitmap::kARGB_4444_Config;
112 case BITMAP_FORMAT_ARGB_8888: 130 case BITMAP_FORMAT_ARGB_8888:
113 return SkBitmap::kARGB_8888_Config; 131 return SkBitmap::kARGB_8888_Config;
114 case BITMAP_FORMAT_RGB_565: 132 case BITMAP_FORMAT_RGB_565:
115 return SkBitmap::kRGB_565_Config; 133 return SkBitmap::kRGB_565_Config;
116 case BITMAP_FORMAT_NO_CONFIG: 134 case BITMAP_FORMAT_NO_CONFIG:
117 default: 135 default:
118 return SkBitmap::kNo_Config; 136 return SkBitmap::kNo_Config;
119 } 137 }
120 } 138 }
121 139
122 } // namespace gfx 140 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/android/java/src/org/chromium/ui/gfx/BitmapHelper.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698