Bitmap.cpp revision 35ef567140e42f354be4a98cce6a7666ac085c13
1#include "SkBitmap.h" 2#include "SkPixelRef.h" 3#include "SkImageEncoder.h" 4#include "SkColorPriv.h" 5#include "GraphicsJNI.h" 6#include "SkDither.h" 7#include "SkUnPreMultiply.h" 8 9#include <binder/Parcel.h> 10#include "android_os_Parcel.h" 11#include "android_util_Binder.h" 12#include "android_nio_utils.h" 13#include "CreateJavaOutputStreamAdaptor.h" 14 15#include <jni.h> 16 17#include <Caches.h> 18 19#if 0 20 #define TRACE_BITMAP(code) code 21#else 22 #define TRACE_BITMAP(code) 23#endif 24 25/////////////////////////////////////////////////////////////////////////////// 26// Conversions to/from SkColor, for get/setPixels, and the create method, which 27// is basically like setPixels 28 29typedef void (*FromColorProc)(void* dst, const SkColor src[], int width, 30 int x, int y); 31 32static void FromColor_D32(void* dst, const SkColor src[], int width, 33 int, int) { 34 SkPMColor* d = (SkPMColor*)dst; 35 36 for (int i = 0; i < width; i++) { 37 *d++ = SkPreMultiplyColor(*src++); 38 } 39} 40 41static void FromColor_D565(void* dst, const SkColor src[], int width, 42 int x, int y) { 43 uint16_t* d = (uint16_t*)dst; 44 45 DITHER_565_SCAN(y); 46 for (int stop = x + width; x < stop; x++) { 47 SkColor c = *src++; 48 *d++ = SkDitherRGBTo565(SkColorGetR(c), SkColorGetG(c), SkColorGetB(c), 49 DITHER_VALUE(x)); 50 } 51} 52 53static void FromColor_D4444(void* dst, const SkColor src[], int width, 54 int x, int y) { 55 SkPMColor16* d = (SkPMColor16*)dst; 56 57 DITHER_4444_SCAN(y); 58 for (int stop = x + width; x < stop; x++) { 59 SkPMColor c = SkPreMultiplyColor(*src++); 60 *d++ = SkDitherARGB32To4444(c, DITHER_VALUE(x)); 61// *d++ = SkPixel32ToPixel4444(c); 62 } 63} 64 65// can return NULL 66static FromColorProc ChooseFromColorProc(SkBitmap::Config config) { 67 switch (config) { 68 case SkBitmap::kARGB_8888_Config: 69 return FromColor_D32; 70 case SkBitmap::kARGB_4444_Config: 71 return FromColor_D4444; 72 case SkBitmap::kRGB_565_Config: 73 return FromColor_D565; 74 default: 75 break; 76 } 77 return NULL; 78} 79 80bool GraphicsJNI::SetPixels(JNIEnv* env, jintArray srcColors, 81 int srcOffset, int srcStride, 82 int x, int y, int width, int height, 83 const SkBitmap& dstBitmap) { 84 SkAutoLockPixels alp(dstBitmap); 85 void* dst = dstBitmap.getPixels(); 86 FromColorProc proc = ChooseFromColorProc(dstBitmap.config()); 87 88 if (NULL == dst || NULL == proc) { 89 return false; 90 } 91 92 const jint* array = env->GetIntArrayElements(srcColors, NULL); 93 const SkColor* src = (const SkColor*)array + srcOffset; 94 95 // reset to to actual choice from caller 96 dst = dstBitmap.getAddr(x, y); 97 // now copy/convert each scanline 98 for (int y = 0; y < height; y++) { 99 proc(dst, src, width, x, y); 100 src += srcStride; 101 dst = (char*)dst + dstBitmap.rowBytes(); 102 } 103 104 dstBitmap.notifyPixelsChanged(); 105 106 env->ReleaseIntArrayElements(srcColors, const_cast<jint*>(array), 107 JNI_ABORT); 108 return true; 109} 110 111//////////////////// ToColor procs 112 113typedef void (*ToColorProc)(SkColor dst[], const void* src, int width, 114 SkColorTable*); 115 116static void ToColor_S32_Alpha(SkColor dst[], const void* src, int width, 117 SkColorTable*) { 118 SkASSERT(width > 0); 119 const SkPMColor* s = (const SkPMColor*)src; 120 do { 121 *dst++ = SkUnPreMultiply::PMColorToColor(*s++); 122 } while (--width != 0); 123} 124 125static void ToColor_S32_Opaque(SkColor dst[], const void* src, int width, 126 SkColorTable*) { 127 SkASSERT(width > 0); 128 const SkPMColor* s = (const SkPMColor*)src; 129 do { 130 SkPMColor c = *s++; 131 *dst++ = SkColorSetRGB(SkGetPackedR32(c), SkGetPackedG32(c), 132 SkGetPackedB32(c)); 133 } while (--width != 0); 134} 135 136static void ToColor_S4444_Alpha(SkColor dst[], const void* src, int width, 137 SkColorTable*) { 138 SkASSERT(width > 0); 139 const SkPMColor16* s = (const SkPMColor16*)src; 140 do { 141 *dst++ = SkUnPreMultiply::PMColorToColor(SkPixel4444ToPixel32(*s++)); 142 } while (--width != 0); 143} 144 145static void ToColor_S4444_Opaque(SkColor dst[], const void* src, int width, 146 SkColorTable*) { 147 SkASSERT(width > 0); 148 const SkPMColor* s = (const SkPMColor*)src; 149 do { 150 SkPMColor c = SkPixel4444ToPixel32(*s++); 151 *dst++ = SkColorSetRGB(SkGetPackedR32(c), SkGetPackedG32(c), 152 SkGetPackedB32(c)); 153 } while (--width != 0); 154} 155 156static void ToColor_S565(SkColor dst[], const void* src, int width, 157 SkColorTable*) { 158 SkASSERT(width > 0); 159 const uint16_t* s = (const uint16_t*)src; 160 do { 161 uint16_t c = *s++; 162 *dst++ = SkColorSetRGB(SkPacked16ToR32(c), SkPacked16ToG32(c), 163 SkPacked16ToB32(c)); 164 } while (--width != 0); 165} 166 167static void ToColor_SI8_Alpha(SkColor dst[], const void* src, int width, 168 SkColorTable* ctable) { 169 SkASSERT(width > 0); 170 const uint8_t* s = (const uint8_t*)src; 171 const SkPMColor* colors = ctable->lockColors(); 172 do { 173 *dst++ = SkUnPreMultiply::PMColorToColor(colors[*s++]); 174 } while (--width != 0); 175 ctable->unlockColors(false); 176} 177 178static void ToColor_SI8_Opaque(SkColor dst[], const void* src, int width, 179 SkColorTable* ctable) { 180 SkASSERT(width > 0); 181 const uint8_t* s = (const uint8_t*)src; 182 const SkPMColor* colors = ctable->lockColors(); 183 do { 184 SkPMColor c = colors[*s++]; 185 *dst++ = SkColorSetRGB(SkGetPackedR32(c), SkGetPackedG32(c), 186 SkGetPackedB32(c)); 187 } while (--width != 0); 188 ctable->unlockColors(false); 189} 190 191// can return NULL 192static ToColorProc ChooseToColorProc(const SkBitmap& src) { 193 switch (src.config()) { 194 case SkBitmap::kARGB_8888_Config: 195 return src.isOpaque() ? ToColor_S32_Opaque : ToColor_S32_Alpha; 196 case SkBitmap::kARGB_4444_Config: 197 return src.isOpaque() ? ToColor_S4444_Opaque : ToColor_S4444_Alpha; 198 case SkBitmap::kRGB_565_Config: 199 return ToColor_S565; 200 case SkBitmap::kIndex8_Config: 201 if (src.getColorTable() == NULL) { 202 return NULL; 203 } 204 return src.isOpaque() ? ToColor_SI8_Opaque : ToColor_SI8_Alpha; 205 default: 206 break; 207 } 208 return NULL; 209} 210 211/////////////////////////////////////////////////////////////////////////////// 212/////////////////////////////////////////////////////////////////////////////// 213 214static jobject Bitmap_creator(JNIEnv* env, jobject, jintArray jColors, 215 int offset, int stride, int width, int height, 216 SkBitmap::Config config, jboolean isMutable) { 217 if (NULL != jColors) { 218 size_t n = env->GetArrayLength(jColors); 219 if (n < SkAbs32(stride) * (size_t)height) { 220 doThrowAIOOBE(env); 221 return NULL; 222 } 223 } 224 225 SkBitmap bitmap; 226 227 bitmap.setConfig(config, width, height); 228 229 jbyteArray buff = GraphicsJNI::allocateJavaPixelRef(env, &bitmap, NULL); 230 if (NULL == buff) { 231 return NULL; 232 } 233 234 if (jColors != NULL) { 235 GraphicsJNI::SetPixels(env, jColors, offset, stride, 236 0, 0, width, height, bitmap); 237 } 238 239 return GraphicsJNI::createBitmap(env, new SkBitmap(bitmap), buff, isMutable, NULL, NULL); 240} 241 242static jobject Bitmap_copy(JNIEnv* env, jobject, const SkBitmap* src, 243 SkBitmap::Config dstConfig, jboolean isMutable) { 244 SkBitmap result; 245 JavaPixelAllocator allocator(env); 246 247 if (!src->copyTo(&result, dstConfig, &allocator)) { 248 return NULL; 249 } 250 251 return GraphicsJNI::createBitmap(env, new SkBitmap(result), allocator.getStorageObj(), isMutable, NULL, NULL); 252} 253 254static void Bitmap_destructor(JNIEnv* env, jobject, SkBitmap* bitmap) { 255#ifdef USE_OPENGL_RENDERER 256 if (android::uirenderer::Caches::hasInstance()) { 257 android::uirenderer::Caches::getInstance().resourceCache.destructor(bitmap); 258 return; 259 } 260#endif // USE_OPENGL_RENDERER 261 delete bitmap; 262} 263 264static void Bitmap_recycle(JNIEnv* env, jobject, SkBitmap* bitmap) { 265#ifdef USE_OPENGL_RENDERER 266 if (android::uirenderer::Caches::hasInstance()) { 267 android::uirenderer::Caches::getInstance().resourceCache.recycle(bitmap); 268 return; 269 } 270#endif // USE_OPENGL_RENDERER 271 bitmap->setPixels(NULL, NULL); 272} 273 274// These must match the int values in Bitmap.java 275enum JavaEncodeFormat { 276 kJPEG_JavaEncodeFormat = 0, 277 kPNG_JavaEncodeFormat = 1, 278 kWEBP_JavaEncodeFormat = 2 279}; 280 281static bool Bitmap_compress(JNIEnv* env, jobject clazz, SkBitmap* bitmap, 282 int format, int quality, 283 jobject jstream, jbyteArray jstorage) { 284 SkImageEncoder::Type fm; 285 286 switch (format) { 287 case kJPEG_JavaEncodeFormat: 288 fm = SkImageEncoder::kJPEG_Type; 289 break; 290 case kPNG_JavaEncodeFormat: 291 fm = SkImageEncoder::kPNG_Type; 292 break; 293 case kWEBP_JavaEncodeFormat: 294 fm = SkImageEncoder::kWEBP_Type; 295 break; 296 default: 297 return false; 298 } 299 300 bool success = false; 301 if (NULL != bitmap) { 302 SkAutoLockPixels alp(*bitmap); 303 304 if (NULL == bitmap->getPixels()) { 305 return false; 306 } 307 308 SkWStream* strm = CreateJavaOutputStreamAdaptor(env, jstream, jstorage); 309 if (NULL == strm) { 310 return false; 311 } 312 313 SkImageEncoder* encoder = SkImageEncoder::Create(fm); 314 if (NULL != encoder) { 315 success = encoder->encodeStream(strm, *bitmap, quality); 316 delete encoder; 317 } 318 delete strm; 319 } 320 return success; 321} 322 323static void Bitmap_erase(JNIEnv* env, jobject, SkBitmap* bitmap, jint color) { 324 bitmap->eraseColor(color); 325} 326 327static int Bitmap_width(JNIEnv* env, jobject, SkBitmap* bitmap) { 328 return bitmap->width(); 329} 330 331static int Bitmap_height(JNIEnv* env, jobject, SkBitmap* bitmap) { 332 return bitmap->height(); 333} 334 335static int Bitmap_rowBytes(JNIEnv* env, jobject, SkBitmap* bitmap) { 336 return bitmap->rowBytes(); 337} 338 339static int Bitmap_config(JNIEnv* env, jobject, SkBitmap* bitmap) { 340 return bitmap->config(); 341} 342 343static int Bitmap_getGenerationId(JNIEnv* env, jobject, SkBitmap* bitmap) { 344 return bitmap->getGenerationID(); 345} 346 347static jboolean Bitmap_hasAlpha(JNIEnv* env, jobject, SkBitmap* bitmap) { 348 return !bitmap->isOpaque(); 349} 350 351static void Bitmap_setHasAlpha(JNIEnv* env, jobject, SkBitmap* bitmap, 352 jboolean hasAlpha) { 353 bitmap->setIsOpaque(!hasAlpha); 354} 355 356/////////////////////////////////////////////////////////////////////////////// 357 358static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) { 359 if (parcel == NULL) { 360 SkDebugf("-------- unparcel parcel is NULL\n"); 361 return NULL; 362 } 363 364 android::Parcel* p = android::parcelForJavaObject(env, parcel); 365 366 const bool isMutable = p->readInt32() != 0; 367 const SkBitmap::Config config = (SkBitmap::Config)p->readInt32(); 368 const int width = p->readInt32(); 369 const int height = p->readInt32(); 370 const int rowBytes = p->readInt32(); 371 const int density = p->readInt32(); 372 373 if (SkBitmap::kARGB_8888_Config != config && 374 SkBitmap::kRGB_565_Config != config && 375 SkBitmap::kARGB_4444_Config != config && 376 SkBitmap::kIndex8_Config != config && 377 SkBitmap::kA8_Config != config) { 378 SkDebugf("Bitmap_createFromParcel unknown config: %d\n", config); 379 return NULL; 380 } 381 382 SkBitmap* bitmap = new SkBitmap; 383 384 bitmap->setConfig(config, width, height, rowBytes); 385 386 SkColorTable* ctable = NULL; 387 if (config == SkBitmap::kIndex8_Config) { 388 int count = p->readInt32(); 389 if (count > 0) { 390 size_t size = count * sizeof(SkPMColor); 391 const SkPMColor* src = (const SkPMColor*)p->readInplace(size); 392 ctable = new SkColorTable(src, count); 393 } 394 } 395 396 jbyteArray buffer = GraphicsJNI::allocateJavaPixelRef(env, bitmap, ctable); 397 if (NULL == buffer) { 398 SkSafeUnref(ctable); 399 delete bitmap; 400 return NULL; 401 } 402 403 SkSafeUnref(ctable); 404 405 size_t size = bitmap->getSize(); 406 407 android::Parcel::ReadableBlob blob; 408 android::status_t status = p->readBlob(size, &blob); 409 if (status) { 410 doThrowRE(env, "Could not read bitmap from parcel blob."); 411 delete bitmap; 412 return NULL; 413 } 414 415 bitmap->lockPixels(); 416 memcpy(bitmap->getPixels(), blob.data(), size); 417 bitmap->unlockPixels(); 418 419 blob.release(); 420 return GraphicsJNI::createBitmap(env, bitmap, buffer, isMutable, NULL, NULL, density); 421} 422 423static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject, 424 const SkBitmap* bitmap, 425 jboolean isMutable, jint density, 426 jobject parcel) { 427 if (parcel == NULL) { 428 SkDebugf("------- writeToParcel null parcel\n"); 429 return false; 430 } 431 432 android::Parcel* p = android::parcelForJavaObject(env, parcel); 433 434 p->writeInt32(isMutable); 435 p->writeInt32(bitmap->config()); 436 p->writeInt32(bitmap->width()); 437 p->writeInt32(bitmap->height()); 438 p->writeInt32(bitmap->rowBytes()); 439 p->writeInt32(density); 440 441 if (bitmap->getConfig() == SkBitmap::kIndex8_Config) { 442 SkColorTable* ctable = bitmap->getColorTable(); 443 if (ctable != NULL) { 444 int count = ctable->count(); 445 p->writeInt32(count); 446 memcpy(p->writeInplace(count * sizeof(SkPMColor)), 447 ctable->lockColors(), count * sizeof(SkPMColor)); 448 ctable->unlockColors(false); 449 } else { 450 p->writeInt32(0); // indicate no ctable 451 } 452 } 453 454 size_t size = bitmap->getSize(); 455 456 android::Parcel::WritableBlob blob; 457 android::status_t status = p->writeBlob(size, &blob); 458 if (status) { 459 doThrowRE(env, "Could not write bitmap to parcel blob."); 460 return false; 461 } 462 463 bitmap->lockPixels(); 464 const void* pSrc = bitmap->getPixels(); 465 if (pSrc == NULL) { 466 memset(blob.data(), 0, size); 467 } else { 468 memcpy(blob.data(), pSrc, size); 469 } 470 bitmap->unlockPixels(); 471 472 blob.release(); 473 return true; 474} 475 476static jobject Bitmap_extractAlpha(JNIEnv* env, jobject clazz, 477 const SkBitmap* src, const SkPaint* paint, 478 jintArray offsetXY) { 479 SkIPoint offset; 480 SkBitmap* dst = new SkBitmap; 481 JavaPixelAllocator allocator(env); 482 483 src->extractAlpha(dst, paint, &allocator, &offset); 484 // If Skia can't allocate pixels for destination bitmap, it resets 485 // it, that is set its pixels buffer to NULL, and zero width and height. 486 if (dst->getPixels() == NULL && src->getPixels() != NULL) { 487 delete dst; 488 doThrowOOME(env, "failed to allocate pixels for alpha"); 489 return NULL; 490 } 491 if (offsetXY != 0 && env->GetArrayLength(offsetXY) >= 2) { 492 int* array = env->GetIntArrayElements(offsetXY, NULL); 493 array[0] = offset.fX; 494 array[1] = offset.fY; 495 env->ReleaseIntArrayElements(offsetXY, array, 0); 496 } 497 498 return GraphicsJNI::createBitmap(env, dst, allocator.getStorageObj(), true, NULL, NULL); 499} 500 501/////////////////////////////////////////////////////////////////////////////// 502 503static int Bitmap_getPixel(JNIEnv* env, jobject, const SkBitmap* bitmap, 504 int x, int y) { 505 SkAutoLockPixels alp(*bitmap); 506 507 ToColorProc proc = ChooseToColorProc(*bitmap); 508 if (NULL == proc) { 509 return 0; 510 } 511 const void* src = bitmap->getAddr(x, y); 512 if (NULL == src) { 513 return 0; 514 } 515 516 SkColor dst[1]; 517 proc(dst, src, 1, bitmap->getColorTable()); 518 return dst[0]; 519} 520 521static void Bitmap_getPixels(JNIEnv* env, jobject, const SkBitmap* bitmap, 522 jintArray pixelArray, int offset, int stride, 523 int x, int y, int width, int height) { 524 SkAutoLockPixels alp(*bitmap); 525 526 ToColorProc proc = ChooseToColorProc(*bitmap); 527 if (NULL == proc) { 528 return; 529 } 530 const void* src = bitmap->getAddr(x, y); 531 if (NULL == src) { 532 return; 533 } 534 535 SkColorTable* ctable = bitmap->getColorTable(); 536 jint* dst = env->GetIntArrayElements(pixelArray, NULL); 537 SkColor* d = (SkColor*)dst + offset; 538 while (--height >= 0) { 539 proc(d, src, width, ctable); 540 d += stride; 541 src = (void*)((const char*)src + bitmap->rowBytes()); 542 } 543 env->ReleaseIntArrayElements(pixelArray, dst, 0); 544} 545 546/////////////////////////////////////////////////////////////////////////////// 547 548static void Bitmap_setPixel(JNIEnv* env, jobject, const SkBitmap* bitmap, 549 int x, int y, SkColor color) { 550 SkAutoLockPixels alp(*bitmap); 551 if (NULL == bitmap->getPixels()) { 552 return; 553 } 554 555 FromColorProc proc = ChooseFromColorProc(bitmap->config()); 556 if (NULL == proc) { 557 return; 558 } 559 560 proc(bitmap->getAddr(x, y), &color, 1, x, y); 561 bitmap->notifyPixelsChanged(); 562} 563 564static void Bitmap_setPixels(JNIEnv* env, jobject, const SkBitmap* bitmap, 565 jintArray pixelArray, int offset, int stride, 566 int x, int y, int width, int height) { 567 GraphicsJNI::SetPixels(env, pixelArray, offset, stride, 568 x, y, width, height, *bitmap); 569} 570 571static void Bitmap_copyPixelsToBuffer(JNIEnv* env, jobject, 572 const SkBitmap* bitmap, jobject jbuffer) { 573 SkAutoLockPixels alp(*bitmap); 574 const void* src = bitmap->getPixels(); 575 576 if (NULL != src) { 577 android::AutoBufferPointer abp(env, jbuffer, JNI_TRUE); 578 579 // the java side has already checked that buffer is large enough 580 memcpy(abp.pointer(), src, bitmap->getSize()); 581 } 582} 583 584static void Bitmap_copyPixelsFromBuffer(JNIEnv* env, jobject, 585 const SkBitmap* bitmap, jobject jbuffer) { 586 SkAutoLockPixels alp(*bitmap); 587 void* dst = bitmap->getPixels(); 588 589 if (NULL != dst) { 590 android::AutoBufferPointer abp(env, jbuffer, JNI_FALSE); 591 // the java side has already checked that buffer is large enough 592 memcpy(dst, abp.pointer(), bitmap->getSize()); 593 bitmap->notifyPixelsChanged(); 594 } 595} 596 597static bool Bitmap_sameAs(JNIEnv* env, jobject, const SkBitmap* bm0, 598 const SkBitmap* bm1) { 599 if (bm0->width() != bm1->width() || 600 bm0->height() != bm1->height() || 601 bm0->config() != bm1->config()) { 602 return false; 603 } 604 605 SkAutoLockPixels alp0(*bm0); 606 SkAutoLockPixels alp1(*bm1); 607 608 // if we can't load the pixels, return false 609 if (NULL == bm0->getPixels() || NULL == bm1->getPixels()) { 610 return false; 611 } 612 613 if (bm0->config() == SkBitmap::kIndex8_Config) { 614 SkColorTable* ct0 = bm0->getColorTable(); 615 SkColorTable* ct1 = bm1->getColorTable(); 616 if (NULL == ct0 || NULL == ct1) { 617 return false; 618 } 619 if (ct0->count() != ct1->count()) { 620 return false; 621 } 622 623 SkAutoLockColors alc0(ct0); 624 SkAutoLockColors alc1(ct1); 625 const size_t size = ct0->count() * sizeof(SkPMColor); 626 if (memcmp(alc0.colors(), alc1.colors(), size) != 0) { 627 return false; 628 } 629 } 630 631 // now compare each scanline. We can't do the entire buffer at once, 632 // since we don't care about the pixel values that might extend beyond 633 // the width (since the scanline might be larger than the logical width) 634 const int h = bm0->height(); 635 const size_t size = bm0->width() * bm0->bytesPerPixel(); 636 for (int y = 0; y < h; y++) { 637 if (memcmp(bm0->getAddr(0, y), bm1->getAddr(0, y), size) != 0) { 638 return false; 639 } 640 } 641 return true; 642} 643 644static void Bitmap_prepareToDraw(JNIEnv* env, jobject, SkBitmap* bitmap) { 645 bitmap->lockPixels(); 646 bitmap->unlockPixels(); 647} 648 649/////////////////////////////////////////////////////////////////////////////// 650 651#include <android_runtime/AndroidRuntime.h> 652 653static JNINativeMethod gBitmapMethods[] = { 654 { "nativeCreate", "([IIIIIIZ)Landroid/graphics/Bitmap;", 655 (void*)Bitmap_creator }, 656 { "nativeCopy", "(IIZ)Landroid/graphics/Bitmap;", 657 (void*)Bitmap_copy }, 658 { "nativeDestructor", "(I)V", (void*)Bitmap_destructor }, 659 { "nativeRecycle", "(I)V", (void*)Bitmap_recycle }, 660 { "nativeCompress", "(IIILjava/io/OutputStream;[B)Z", 661 (void*)Bitmap_compress }, 662 { "nativeErase", "(II)V", (void*)Bitmap_erase }, 663 { "nativeWidth", "(I)I", (void*)Bitmap_width }, 664 { "nativeHeight", "(I)I", (void*)Bitmap_height }, 665 { "nativeRowBytes", "(I)I", (void*)Bitmap_rowBytes }, 666 { "nativeConfig", "(I)I", (void*)Bitmap_config }, 667 { "nativeHasAlpha", "(I)Z", (void*)Bitmap_hasAlpha }, 668 { "nativeSetHasAlpha", "(IZ)V", (void*)Bitmap_setHasAlpha }, 669 { "nativeCreateFromParcel", 670 "(Landroid/os/Parcel;)Landroid/graphics/Bitmap;", 671 (void*)Bitmap_createFromParcel }, 672 { "nativeWriteToParcel", "(IZILandroid/os/Parcel;)Z", 673 (void*)Bitmap_writeToParcel }, 674 { "nativeExtractAlpha", "(II[I)Landroid/graphics/Bitmap;", 675 (void*)Bitmap_extractAlpha }, 676 { "nativeGenerationId", "(I)I", (void*)Bitmap_getGenerationId }, 677 { "nativeGetPixel", "(III)I", (void*)Bitmap_getPixel }, 678 { "nativeGetPixels", "(I[IIIIIII)V", (void*)Bitmap_getPixels }, 679 { "nativeSetPixel", "(IIII)V", (void*)Bitmap_setPixel }, 680 { "nativeSetPixels", "(I[IIIIIII)V", (void*)Bitmap_setPixels }, 681 { "nativeCopyPixelsToBuffer", "(ILjava/nio/Buffer;)V", 682 (void*)Bitmap_copyPixelsToBuffer }, 683 { "nativeCopyPixelsFromBuffer", "(ILjava/nio/Buffer;)V", 684 (void*)Bitmap_copyPixelsFromBuffer }, 685 { "nativeSameAs", "(II)Z", (void*)Bitmap_sameAs }, 686 { "nativePrepareToDraw", "(I)V", (void*)Bitmap_prepareToDraw }, 687}; 688 689#define kClassPathName "android/graphics/Bitmap" 690 691int register_android_graphics_Bitmap(JNIEnv* env) 692{ 693 return android::AndroidRuntime::registerNativeMethods(env, kClassPathName, 694 gBitmapMethods, SK_ARRAY_COUNT(gBitmapMethods)); 695} 696