Home | History | Annotate | Download | only in graphics
      1 /* libs/android_runtime/android/graphics/Rasterizer.cpp
      2 **
      3 ** Copyright 2006, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 // This file was generated from the C++ include file: SkRasterizer.h
     19 // Any changes made to this file will be discarded by the build.
     20 // To change this file, either edit the include, or device/tools/gluemaker/main.cpp,
     21 // or one of the auxilary file specifications in device/tools/gluemaker.
     22 
     23 #include "jni.h"
     24 #include "GraphicsJNI.h"
     25 #include "Paint.h"
     26 #include "SkLayerRasterizer.h"
     27 #include <android_runtime/AndroidRuntime.h>
     28 
     29 // Rasterizer.java holds a pointer (jlong) to this guy
     30 class NativeRasterizer {
     31 public:
     32     NativeRasterizer() {}
     33     virtual ~NativeRasterizer() {}
     34 
     35     // Can return NULL, or a ref to the skia rasterizer.
     36     virtual SkRasterizer* refRasterizer() { return NULL; }
     37 };
     38 
     39 class NativeLayerRasterizer : public NativeRasterizer {
     40 public:
     41     SkLayerRasterizer::Builder fBuilder;
     42 
     43     virtual SkRasterizer* refRasterizer() {
     44         return fBuilder.snapshotRasterizer();
     45     }
     46 };
     47 
     48 SkRasterizer* GraphicsJNI::refNativeRasterizer(jlong rasterizerHandle) {
     49     NativeRasterizer* nr = reinterpret_cast<NativeRasterizer*>(rasterizerHandle);
     50     return nr ? nr->refRasterizer() : NULL;
     51 }
     52 
     53 ///////////////////////////////////////////////////////////////////////////////
     54 
     55 namespace android {
     56 
     57 class SkRasterizerGlue {
     58 public:
     59     static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) {
     60         delete reinterpret_cast<NativeRasterizer *>(objHandle);
     61     }
     62 
     63 };
     64 
     65 static JNINativeMethod gRasterizerMethods[] = {
     66     {"finalizer", "(J)V", (void*) SkRasterizerGlue::finalizer}
     67 };
     68 
     69 int register_android_graphics_Rasterizer(JNIEnv* env) {
     70     int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Rasterizer", gRasterizerMethods,
     71         sizeof(gRasterizerMethods) / sizeof(gRasterizerMethods[0]));
     72     return result;
     73 }
     74 
     75 class SkLayerRasterizerGlue {
     76 public:
     77     static jlong create(JNIEnv* env, jobject) {
     78         return reinterpret_cast<jlong>(new NativeLayerRasterizer);
     79     }
     80 
     81     static void addLayer(JNIEnv* env, jobject, jlong layerHandle, jlong paintHandle, jfloat dx, jfloat dy) {
     82         NativeLayerRasterizer* nr = reinterpret_cast<NativeLayerRasterizer *>(layerHandle);
     83         const Paint* paint = reinterpret_cast<Paint *>(paintHandle);
     84         SkASSERT(nr);
     85         SkASSERT(paint);
     86         nr->fBuilder.addLayer(*paint, dx, dy);
     87     }
     88 };
     89 
     90 static JNINativeMethod gLayerRasterizerMethods[] = {
     91     { "nativeConstructor",  "()J",      (void*)SkLayerRasterizerGlue::create    },
     92     { "nativeAddLayer",     "(JJFF)V",  (void*)SkLayerRasterizerGlue::addLayer  }
     93 };
     94 
     95 int register_android_graphics_LayerRasterizer(JNIEnv* env)
     96 {
     97     return android::AndroidRuntime::registerNativeMethods(env,
     98                                                        "android/graphics/LayerRasterizer",
     99                                                        gLayerRasterizerMethods,
    100                                                        SK_ARRAY_COUNT(gLayerRasterizerMethods));
    101 }
    102 
    103 }
    104 
    105