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

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

Issue 25015003: gfx: Create a separate gfx component out of ui. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/android/gfx_jni_registrar.cc ('k') | ui/gfx/gfx.gyp » ('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 #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
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
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
OLDNEW
« no previous file with comments | « ui/gfx/android/gfx_jni_registrar.cc ('k') | ui/gfx/gfx.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698