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

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

Issue 159463004: Packing/unpacking of width and height in gfx::Size is redundant while using CreateJavaBitmap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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 | « no previous file | 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 24 matching lines...) Expand all
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 RegisterNativesImpl(env); 42 return RegisterNativesImpl(env);
43 } 43 }
44 44
45 static ScopedJavaLocalRef<jobject> CreateJavaBitmap(const gfx::Size& size, 45 static ScopedJavaLocalRef<jobject> CreateJavaBitmap(int width, int height,
46 bool is565_config) { 46 bool is565_config) {
47 return Java_BitmapHelper_createBitmap(AttachCurrentThread(), 47 return Java_BitmapHelper_createBitmap(AttachCurrentThread(),
48 size.width(), size.height(), is565_config); 48 width, height, is565_config);
49 } 49 }
50 50
51 ScopedJavaLocalRef<jobject> ConvertToJavaBitmap(const SkBitmap* skbitmap) { 51 ScopedJavaLocalRef<jobject> ConvertToJavaBitmap(const SkBitmap* skbitmap) {
52 DCHECK(skbitmap); 52 DCHECK(skbitmap);
53 SkBitmap::Config config = skbitmap->getConfig(); 53 SkBitmap::Config config = skbitmap->getConfig();
54 DCHECK((config == SkBitmap::kRGB_565_Config) || 54 DCHECK((config == SkBitmap::kRGB_565_Config) ||
55 (config == SkBitmap::kARGB_8888_Config)); 55 (config == SkBitmap::kARGB_8888_Config));
56 // If the Config is not RGB565 it is default i.e ARGB8888 56 // If the Config is not RGB565 it is default i.e ARGB8888
57 ScopedJavaLocalRef<jobject> jbitmap = 57 ScopedJavaLocalRef<jobject> jbitmap =
58 CreateJavaBitmap(gfx::Size(skbitmap->width(), skbitmap->height()), 58 CreateJavaBitmap(skbitmap->width(), skbitmap->height(),
59 (config == SkBitmap::kRGB_565_Config)); 59 (config == SkBitmap::kRGB_565_Config));
60 SkAutoLockPixels src_lock(*skbitmap); 60 SkAutoLockPixels src_lock(*skbitmap);
61 JavaBitmap dst_lock(jbitmap.obj()); 61 JavaBitmap dst_lock(jbitmap.obj());
62 void* src_pixels = skbitmap->getPixels(); 62 void* src_pixels = skbitmap->getPixels();
63 void* dst_pixels = dst_lock.pixels(); 63 void* dst_pixels = dst_lock.pixels();
64 memcpy(dst_pixels, src_pixels, skbitmap->getSize()); 64 memcpy(dst_pixels, src_pixels, skbitmap->getSize());
65 65
66 return jbitmap; 66 return jbitmap;
67 } 67 }
68 68
(...skipping 27 matching lines...) Expand all
96 if (jobj.is_null()) 96 if (jobj.is_null())
97 return SkBitmap(); 97 return SkBitmap();
98 98
99 JavaBitmap jbitmap(jobj.obj()); 99 JavaBitmap jbitmap(jobj.obj());
100 SkBitmap bitmap = CreateSkBitmapFromJavaBitmap(jbitmap); 100 SkBitmap bitmap = CreateSkBitmapFromJavaBitmap(jbitmap);
101 return skia::ImageOperations::Resize( 101 return skia::ImageOperations::Resize(
102 bitmap, skia::ImageOperations::RESIZE_BOX, size.width(), size.height()); 102 bitmap, skia::ImageOperations::RESIZE_BOX, size.width(), size.height());
103 } 103 }
104 104
105 } // namespace gfx 105 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698