Home | History | Annotate | Download | only in graphics
      1 /*
      2  * Copyright (C) 2015 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 #ifndef BITMAP_H_
     17 #define BITMAP_H_
     18 
     19 #include <jni.h>
     20 #include <android/bitmap.h>
     21 #include <SkBitmap.h>
     22 #include <SkImageInfo.h>
     23 
     24 namespace android {
     25 
     26 class Bitmap;
     27 
     28 namespace bitmap {
     29 
     30 enum BitmapCreateFlags {
     31     kBitmapCreateFlag_None = 0x0,
     32     kBitmapCreateFlag_Mutable = 0x1,
     33     kBitmapCreateFlag_Premultiplied = 0x2,
     34 };
     35 
     36 jobject createBitmap(JNIEnv* env, Bitmap* bitmap,
     37             int bitmapCreateFlags, jbyteArray ninePatchChunk = NULL,
     38             jobject ninePatchInsets = NULL, int density = -1);
     39 
     40 
     41 void toSkBitmap(jlong bitmapHandle, SkBitmap* outBitmap);
     42 
     43 Bitmap& toBitmap(JNIEnv* env, jobject bitmap);
     44 Bitmap& toBitmap(JNIEnv* env, jlong bitmapHandle);
     45 
     46 // NDK access
     47 void imageInfo(JNIEnv* env, jobject bitmap, AndroidBitmapInfo* info);
     48 // Returns a pointer to the pixels or nullptr if the bitmap is not valid
     49 void* lockPixels(JNIEnv* env, jobject bitmap);
     50 // Returns true if unlocked, false if the bitmap is no longer valid (destroyed)
     51 bool unlockPixels(JNIEnv* env, jobject bitmap);
     52 
     53 /** Reinitialize a bitmap. bitmap must already have its SkAlphaType set in
     54     sync with isPremultiplied
     55 */
     56 void reinitBitmap(JNIEnv* env, jobject javaBitmap, const SkImageInfo& info,
     57         bool isPremultiplied);
     58 
     59 int getBitmapAllocationByteCount(JNIEnv* env, jobject javaBitmap);
     60 
     61 } // namespace bitmap
     62 
     63 } // namespace android
     64 
     65 #endif /* BITMAP_H_ */
     66