The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "AWT" |
| 18 | |
| 19 | #include "jni.h" |
| 20 | #include "JNIHelp.h" |
| 21 | #include "GraphicsJNI.h" |
| 22 | #include <android_runtime/AndroidRuntime.h> |
| 23 | |
| 24 | #include "SkCanvas.h" |
| 25 | #include "SkDevice.h" |
| 26 | #include "SkPicture.h" |
| 27 | #include "SkTemplates.h" |
| 28 | |
| 29 | namespace android |
| 30 | { |
| 31 | |
| 32 | static jclass class_fileDescriptor; |
| 33 | static jfieldID field_fileDescriptor_descriptor; |
| 34 | static jmethodID method_fileDescriptor_init; |
| 35 | |
| 36 | |
| 37 | static jboolean scrollRect(JNIEnv* env, jobject graphics2D, jobject canvas, jobject rect, int dx, int dy) { |
| 38 | if (canvas == NULL) { |
| 39 | jniThrowException(env, "java/lang/NullPointerException", NULL); |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | SkIRect src, *srcPtr = NULL; |
| 44 | if (NULL != rect) { |
| 45 | GraphicsJNI::jrect_to_irect(env, rect, &src); |
| 46 | srcPtr = &src; |
| 47 | } |
| 48 | SkCanvas* c = GraphicsJNI::getNativeCanvas(env, canvas); |
| 49 | const SkBitmap& bitmap = c->getDevice()->accessBitmap(true); |
| 50 | return bitmap.scrollRect(srcPtr, dx, dy, NULL); |
| 51 | } |
| 52 | |
| 53 | static JNINativeMethod method_table[] = { |
| 54 | { "nativeScrollRect", |
| 55 | "(Landroid/graphics/Canvas;Landroid/graphics/Rect;II)Z", |
| 56 | (void*)scrollRect} |
| 57 | }; |
| 58 | |
| 59 | int register_com_android_internal_graphics_NativeUtils(JNIEnv *env) { |
| 60 | return AndroidRuntime::registerNativeMethods( |
| 61 | env, "com/android/internal/graphics/NativeUtils", |
| 62 | method_table, NELEM(method_table)); |
| 63 | } |
| 64 | |
| 65 | } |