Merge "Rename hwui/PixelRef to hwui/Bitmap Test: refactoring cl. bug:32216791"

This commit is contained in:
Sergei Vasilinetc
2016-10-20 19:35:29 +00:00
committed by Android (Google) Code Review
12 changed files with 144 additions and 145 deletions

View File

@@ -17,7 +17,7 @@
#include "android_nio_utils.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include <hwui/Paint.h>
#include <hwui/PixelRef.h>
#include <hwui/Bitmap.h>
#include <renderthread/RenderProxy.h>
#include "core_jni_helpers.h"
@@ -37,25 +37,25 @@ static jmethodID gBitmap_getAllocationByteCountMethodID;
namespace android {
class Bitmap {
class BitmapWrapper {
public:
Bitmap(PixelRef* pixelRef)
: mPixelRef(pixelRef) { }
BitmapWrapper(Bitmap* bitmap)
: mBitmap(bitmap) { }
void freePixels() {
mInfo = mPixelRef->info();
mHasHardwareMipMap = mPixelRef->hasHardwareMipMap();
mAllocationSize = mPixelRef->getAllocationByteCount();
mRowBytes = mPixelRef->rowBytes();
mGenerationId = mPixelRef->getGenerationID();
mPixelRef.reset();
mInfo = mBitmap->info();
mHasHardwareMipMap = mBitmap->hasHardwareMipMap();
mAllocationSize = mBitmap->getAllocationByteCount();
mRowBytes = mBitmap->rowBytes();
mGenerationId = mBitmap->getGenerationID();
mBitmap.reset();
}
bool valid() {
return !!mPixelRef;
return !!mBitmap;
}
PixelRef* pixelRef() { return mPixelRef.get(); }
Bitmap* bitmap() { return mBitmap.get(); }
void assertValid() {
LOG_ALWAYS_FATAL_IF(!valid(), "Error, cannot access an invalid/free'd bitmap here!");
@@ -63,58 +63,58 @@ public:
void getSkBitmap(SkBitmap* outBitmap) {
assertValid();
mPixelRef->getSkBitmap(outBitmap);
mBitmap->getSkBitmap(outBitmap);
}
bool hasHardwareMipMap() {
if (mPixelRef) {
return mPixelRef->hasHardwareMipMap();
if (mBitmap) {
return mBitmap->hasHardwareMipMap();
}
return mHasHardwareMipMap;
}
void setHasHardwareMipMap(bool hasMipMap) {
assertValid();
mPixelRef->setHasHardwareMipMap(hasMipMap);
mBitmap->setHasHardwareMipMap(hasMipMap);
}
void setAlphaType(SkAlphaType alphaType) {
assertValid();
mPixelRef->setAlphaType(alphaType);
mBitmap->setAlphaType(alphaType);
}
const SkImageInfo& info() {
if (mPixelRef) {
return mPixelRef->info();
if (mBitmap) {
return mBitmap->info();
}
return mInfo;
}
size_t getAllocationByteCount() const {
if (mPixelRef) {
return mPixelRef->getAllocationByteCount();
if (mBitmap) {
return mBitmap->getAllocationByteCount();
}
return mAllocationSize;
}
size_t rowBytes() const {
if (mPixelRef) {
return mPixelRef->rowBytes();
if (mBitmap) {
return mBitmap->rowBytes();
}
return mRowBytes;
}
uint32_t getGenerationID() const {
if (mPixelRef) {
return mPixelRef->getGenerationID();
if (mBitmap) {
return mBitmap->getGenerationID();
}
return mGenerationId;
}
~Bitmap() { }
~BitmapWrapper() { }
private:
sk_sp<PixelRef> mPixelRef;
sk_sp<Bitmap> mBitmap;
SkImageInfo mInfo;
bool mHasHardwareMipMap;
size_t mAllocationSize;
@@ -127,22 +127,22 @@ private:
class LocalScopedBitmap {
public:
explicit LocalScopedBitmap(jlong bitmapHandle)
: mBitmap(reinterpret_cast<Bitmap*>(bitmapHandle)) {}
: mBitmapWrapper(reinterpret_cast<BitmapWrapper*>(bitmapHandle)) {}
Bitmap* operator->() {
return mBitmap;
BitmapWrapper* operator->() {
return mBitmapWrapper;
}
void* pixels() {
return mBitmap->pixelRef()->pixels();
return mBitmapWrapper->bitmap()->pixels();
}
bool valid() {
return mBitmap && mBitmap->valid();
return mBitmapWrapper && mBitmapWrapper->valid();
}
private:
Bitmap* mBitmap;
BitmapWrapper* mBitmapWrapper;
};
namespace bitmap {
@@ -175,18 +175,18 @@ int getBitmapAllocationByteCount(JNIEnv* env, jobject javaBitmap)
return env->CallIntMethod(javaBitmap, gBitmap_getAllocationByteCountMethodID);
}
jobject createBitmap(JNIEnv* env, PixelRef* pixelRef,
jobject createBitmap(JNIEnv* env, Bitmap* bitmap,
int bitmapCreateFlags, jbyteArray ninePatchChunk, jobject ninePatchInsets,
int density) {
bool isMutable = bitmapCreateFlags & kBitmapCreateFlag_Mutable;
bool isPremultiplied = bitmapCreateFlags & kBitmapCreateFlag_Premultiplied;
// The caller needs to have already set the alpha type properly, so the
// native SkBitmap stays in sync with the Java Bitmap.
assert_premultiplied(pixelRef->info(), isPremultiplied);
Bitmap* bitmap = new Bitmap(pixelRef);
assert_premultiplied(bitmap->info(), isPremultiplied);
BitmapWrapper* bitmapWrapper = new BitmapWrapper(bitmap);
jobject obj = env->NewObject(gBitmap_class, gBitmap_constructorMethodID,
reinterpret_cast<jlong>(bitmap), pixelRef->width(), pixelRef->height(), density, isMutable,
isPremultiplied, ninePatchChunk, ninePatchInsets);
reinterpret_cast<jlong>(bitmapWrapper), bitmap->width(), bitmap->height(), density,
isMutable, isPremultiplied, ninePatchChunk, ninePatchInsets);
if (env->ExceptionCheck() != 0) {
ALOGE("*** Uncaught exception returned from Java call!\n");
@@ -200,14 +200,14 @@ void toSkBitmap(jlong bitmapHandle, SkBitmap* outBitmap) {
bitmap->getSkBitmap(outBitmap);
}
PixelRef* toPixelRef(JNIEnv* env, jobject bitmap) {
Bitmap* toBitmap(JNIEnv* env, jobject bitmap) {
SkASSERT(env);
SkASSERT(bitmap);
SkASSERT(env->IsInstanceOf(bitmap, gBitmap_class));
jlong bitmapHandle = env->GetLongField(bitmap, gBitmap_nativePtr);
LocalScopedBitmap localBitmap(bitmapHandle);
localBitmap->assertValid();
return localBitmap->pixelRef();
return localBitmap->bitmap();
}
} // namespace bitmap
@@ -548,7 +548,7 @@ static jobject Bitmap_creator(JNIEnv* env, jobject, jintArray jColors,
bitmap.setInfo(SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType,
GraphicsJNI::defaultColorSpace()));
sk_sp<PixelRef> nativeBitmap = PixelRef::allocateHeapPixelRef(&bitmap, NULL);
sk_sp<Bitmap> nativeBitmap = Bitmap::allocateHeapBitmap(&bitmap, NULL);
if (!nativeBitmap) {
return NULL;
}
@@ -564,7 +564,7 @@ static jobject Bitmap_creator(JNIEnv* env, jobject, jintArray jColors,
static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle,
jint dstConfigHandle, jboolean isMutable) {
SkBitmap src;
reinterpret_cast<Bitmap*>(srcHandle)->getSkBitmap(&src);
reinterpret_cast<BitmapWrapper*>(srcHandle)->getSkBitmap(&src);
SkColorType dstCT = GraphicsJNI::legacyBitmapConfigToColorType(dstConfigHandle);
SkBitmap result;
HeapAllocator allocator;
@@ -572,41 +572,41 @@ static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle,
if (!src.copyTo(&result, dstCT, &allocator)) {
return NULL;
}
auto pixelRef = allocator.getStorageObjAndReset();
return createBitmap(env, pixelRef, getPremulBitmapCreateFlags(isMutable));
auto bitmap = allocator.getStorageObjAndReset();
return createBitmap(env, bitmap, getPremulBitmapCreateFlags(isMutable));
}
static PixelRef* Bitmap_copyAshmemImpl(JNIEnv* env, SkBitmap& src, SkColorType& dstCT) {
static Bitmap* Bitmap_copyAshmemImpl(JNIEnv* env, SkBitmap& src, SkColorType& dstCT) {
SkBitmap result;
AshmemPixelAllocator allocator(env);
if (!src.copyTo(&result, dstCT, &allocator)) {
return NULL;
}
auto pixelRef = allocator.getStorageObjAndReset();
pixelRef->setImmutable();
return pixelRef;
auto bitmap = allocator.getStorageObjAndReset();
bitmap->setImmutable();
return bitmap;
}
static jobject Bitmap_copyAshmem(JNIEnv* env, jobject, jlong srcHandle) {
SkBitmap src;
reinterpret_cast<Bitmap*>(srcHandle)->getSkBitmap(&src);
reinterpret_cast<BitmapWrapper*>(srcHandle)->getSkBitmap(&src);
SkColorType dstCT = src.colorType();
auto pixelRef = Bitmap_copyAshmemImpl(env, src, dstCT);
jobject ret = createBitmap(env, pixelRef, getPremulBitmapCreateFlags(false));
auto bitmap = Bitmap_copyAshmemImpl(env, src, dstCT);
jobject ret = createBitmap(env, bitmap, getPremulBitmapCreateFlags(false));
return ret;
}
static jobject Bitmap_copyAshmemConfig(JNIEnv* env, jobject, jlong srcHandle, jint dstConfigHandle) {
SkBitmap src;
reinterpret_cast<Bitmap*>(srcHandle)->getSkBitmap(&src);
reinterpret_cast<BitmapWrapper*>(srcHandle)->getSkBitmap(&src);
SkColorType dstCT = GraphicsJNI::legacyBitmapConfigToColorType(dstConfigHandle);
auto pixelRef = Bitmap_copyAshmemImpl(env, src, dstCT);
jobject ret = createBitmap(env, pixelRef, getPremulBitmapCreateFlags(false));
auto bitmap = Bitmap_copyAshmemImpl(env, src, dstCT);
jobject ret = createBitmap(env, bitmap, getPremulBitmapCreateFlags(false));
return ret;
}
static void Bitmap_destruct(Bitmap* bitmap) {
static void Bitmap_destruct(BitmapWrapper* bitmap) {
delete bitmap;
}
@@ -646,7 +646,7 @@ static void Bitmap_reconfigure(JNIEnv* env, jobject clazz, jlong bitmapHandle,
// Otherwise respect the premultiplied request.
alphaType = requestPremul ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
}
bitmap->pixelRef()->reconfigure(SkImageInfo::Make(width, height, colorType, alphaType,
bitmap->bitmap()->reconfigure(SkImageInfo::Make(width, height, colorType, alphaType,
sk_sp<SkColorSpace>(bitmap->info().colorSpace())));
}
@@ -831,7 +831,7 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
}
// Map the bitmap in place from the ashmem region if possible otherwise copy.
sk_sp<PixelRef> nativeBitmap;
sk_sp<Bitmap> nativeBitmap;
if (blob.fd() >= 0 && (blob.isMutable() || !isMutable) && (size >= ASHMEM_BITMAP_MIN_SIZE)) {
#if DEBUG_PARCEL
ALOGD("Bitmap.createFromParcel: mapped contents of %s bitmap from %s blob "
@@ -852,7 +852,7 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
}
// Map the pixels in place and take ownership of the ashmem region.
nativeBitmap = sk_sp<PixelRef>(GraphicsJNI::mapAshmemPixelRef(env, bitmap.get(),
nativeBitmap = sk_sp<Bitmap>(GraphicsJNI::mapAshmemBitmap(env, bitmap.get(),
ctable, dupFd, const_cast<void*>(blob.data()), size, !isMutable));
SkSafeUnref(ctable);
if (!nativeBitmap) {
@@ -879,7 +879,7 @@ static jobject Bitmap_createFromParcel(JNIEnv* env, jobject, jobject parcel) {
#endif
// Copy the pixels into a new buffer.
nativeBitmap = PixelRef::allocateHeapPixelRef(bitmap.get(), ctable);
nativeBitmap = Bitmap::allocateHeapBitmap(bitmap.get(), ctable);
SkSafeUnref(ctable);
if (!nativeBitmap) {
blob.release();
@@ -910,8 +910,8 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject,
android::Parcel* p = android::parcelForJavaObject(env, parcel);
SkBitmap bitmap;
auto androidBitmap = reinterpret_cast<Bitmap*>(bitmapHandle);
androidBitmap->getSkBitmap(&bitmap);
auto bitmapWrapper = reinterpret_cast<BitmapWrapper*>(bitmapHandle);
bitmapWrapper->getSkBitmap(&bitmap);
sk_sp<SkColorSpace> sRGB = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
bool isSRGB = bitmap.colorSpace() == sRGB.get();
@@ -941,7 +941,7 @@ static jboolean Bitmap_writeToParcel(JNIEnv* env, jobject,
// Transfer the underlying ashmem region if we have one and it's immutable.
android::status_t status;
int fd = androidBitmap->pixelRef()->getAshmemFd();
int fd = bitmapWrapper->bitmap()->getAshmemFd();
if (fd >= 0 && !isMutable && p->allowFds()) {
#if DEBUG_PARCEL
ALOGD("Bitmap.writeToParcel: transferring immutable bitmap's ashmem fd as "
@@ -991,7 +991,7 @@ static jobject Bitmap_extractAlpha(JNIEnv* env, jobject clazz,
jlong srcHandle, jlong paintHandle,
jintArray offsetXY) {
SkBitmap src;
reinterpret_cast<Bitmap*>(srcHandle)->getSkBitmap(&src);
reinterpret_cast<BitmapWrapper*>(srcHandle)->getSkBitmap(&src);
const android::Paint* paint = reinterpret_cast<android::Paint*>(paintHandle);
SkIPoint offset;
SkBitmap dst;
@@ -1020,7 +1020,7 @@ static jobject Bitmap_extractAlpha(JNIEnv* env, jobject clazz,
static jint Bitmap_getPixel(JNIEnv* env, jobject, jlong bitmapHandle,
jint x, jint y) {
SkBitmap bitmap;
reinterpret_cast<Bitmap*>(bitmapHandle)->getSkBitmap(&bitmap);
reinterpret_cast<BitmapWrapper*>(bitmapHandle)->getSkBitmap(&bitmap);
SkAutoLockPixels alp(bitmap);
ToColorProc proc = ChooseToColorProc(bitmap);
@@ -1041,7 +1041,7 @@ static void Bitmap_getPixels(JNIEnv* env, jobject, jlong bitmapHandle,
jintArray pixelArray, jint offset, jint stride,
jint x, jint y, jint width, jint height) {
SkBitmap bitmap;
reinterpret_cast<Bitmap*>(bitmapHandle)->getSkBitmap(&bitmap);
reinterpret_cast<BitmapWrapper*>(bitmapHandle)->getSkBitmap(&bitmap);
SkAutoLockPixels alp(bitmap);
ToColorProc proc = ChooseToColorProc(bitmap);
@@ -1069,7 +1069,7 @@ static void Bitmap_getPixels(JNIEnv* env, jobject, jlong bitmapHandle,
static void Bitmap_setPixel(JNIEnv* env, jobject, jlong bitmapHandle,
jint x, jint y, jint colorHandle) {
SkBitmap bitmap;
reinterpret_cast<Bitmap*>(bitmapHandle)->getSkBitmap(&bitmap);
reinterpret_cast<BitmapWrapper*>(bitmapHandle)->getSkBitmap(&bitmap);
SkColor color = static_cast<SkColor>(colorHandle);
SkAutoLockPixels alp(bitmap);
if (NULL == bitmap.getPixels()) {
@@ -1089,7 +1089,7 @@ static void Bitmap_setPixels(JNIEnv* env, jobject, jlong bitmapHandle,
jintArray pixelArray, jint offset, jint stride,
jint x, jint y, jint width, jint height) {
SkBitmap bitmap;
reinterpret_cast<Bitmap*>(bitmapHandle)->getSkBitmap(&bitmap);
reinterpret_cast<BitmapWrapper*>(bitmapHandle)->getSkBitmap(&bitmap);
GraphicsJNI::SetPixels(env, pixelArray, offset, stride,
x, y, width, height, bitmap);
}
@@ -1097,7 +1097,7 @@ static void Bitmap_setPixels(JNIEnv* env, jobject, jlong bitmapHandle,
static void Bitmap_copyPixelsToBuffer(JNIEnv* env, jobject,
jlong bitmapHandle, jobject jbuffer) {
SkBitmap bitmap;
reinterpret_cast<Bitmap*>(bitmapHandle)->getSkBitmap(&bitmap);
reinterpret_cast<BitmapWrapper*>(bitmapHandle)->getSkBitmap(&bitmap);
SkAutoLockPixels alp(bitmap);
const void* src = bitmap.getPixels();
@@ -1112,7 +1112,7 @@ static void Bitmap_copyPixelsToBuffer(JNIEnv* env, jobject,
static void Bitmap_copyPixelsFromBuffer(JNIEnv* env, jobject,
jlong bitmapHandle, jobject jbuffer) {
SkBitmap bitmap;
reinterpret_cast<Bitmap*>(bitmapHandle)->getSkBitmap(&bitmap);
reinterpret_cast<BitmapWrapper*>(bitmapHandle)->getSkBitmap(&bitmap);
SkAutoLockPixels alp(bitmap);
void* dst = bitmap.getPixels();
@@ -1128,8 +1128,8 @@ static jboolean Bitmap_sameAs(JNIEnv* env, jobject, jlong bm0Handle,
jlong bm1Handle) {
SkBitmap bm0;
SkBitmap bm1;
reinterpret_cast<Bitmap*>(bm0Handle)->getSkBitmap(&bm0);
reinterpret_cast<Bitmap*>(bm1Handle)->getSkBitmap(&bm1);
reinterpret_cast<BitmapWrapper*>(bm0Handle)->getSkBitmap(&bm0);
reinterpret_cast<BitmapWrapper*>(bm1Handle)->getSkBitmap(&bm1);
if (bm0.width() != bm1.width() ||
bm0.height() != bm1.height() ||
bm0.colorType() != bm1.colorType() ||
@@ -1189,7 +1189,7 @@ static jboolean Bitmap_sameAs(JNIEnv* env, jobject, jlong bm0Handle,
static jlong Bitmap_refPixelRef(JNIEnv* env, jobject, jlong bitmapHandle) {
LocalScopedBitmap bitmap(bitmapHandle);
SkPixelRef* pixelRef = bitmap->pixelRef();
SkPixelRef* pixelRef = bitmap->bitmap();
SkSafeRef(pixelRef);
return reinterpret_cast<jlong>(pixelRef);
}

View File

@@ -24,7 +24,7 @@
namespace android {
class PixelRef;
class Bitmap;
namespace bitmap {
@@ -34,14 +34,14 @@ enum BitmapCreateFlags {
kBitmapCreateFlag_Premultiplied = 0x2,
};
jobject createBitmap(JNIEnv* env, PixelRef* bitmap,
jobject createBitmap(JNIEnv* env, Bitmap* bitmap,
int bitmapCreateFlags, jbyteArray ninePatchChunk = NULL,
jobject ninePatchInsets = NULL, int density = -1);
void toSkBitmap(jlong bitmapHandle, SkBitmap* outBitmap);
PixelRef* toPixelRef(JNIEnv* env, jobject bitmap);
Bitmap* toBitmap(JNIEnv* env, jobject bitmap);
/** Reinitialize a bitmap. bitmap must already have its SkAlphaType set in
sync with isPremultiplied

View File

@@ -162,7 +162,7 @@ private:
class RecyclingPixelAllocator : public SkBitmap::Allocator {
public:
RecyclingPixelAllocator(android::PixelRef* bitmap, unsigned int size)
RecyclingPixelAllocator(android::Bitmap* bitmap, unsigned int size)
: mBitmap(bitmap), mSize(size) {
}
@@ -200,7 +200,7 @@ public:
}
private:
android::PixelRef* const mBitmap;
android::Bitmap* const mBitmap;
const unsigned int mSize;
};
@@ -327,10 +327,10 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
scaledHeight = static_cast<int>(scaledHeight * scale + 0.5f);
}
android::PixelRef* reuseBitmap = nullptr;
android::Bitmap* reuseBitmap = nullptr;
unsigned int existingBufferSize = 0;
if (javaBitmap != NULL) {
reuseBitmap = bitmap::toPixelRef(env, javaBitmap);
reuseBitmap = bitmap::toBitmap(env, javaBitmap);
if (reuseBitmap->isImmutable()) {
ALOGW("Unable to reuse an immutable bitmap as an image decoder target.");
javaBitmap = NULL;

View File

@@ -148,10 +148,10 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in
}
// Recycle a bitmap if possible.
android::PixelRef* recycledBitmap = nullptr;
android::Bitmap* recycledBitmap = nullptr;
size_t recycledBytes = 0;
if (javaBitmap) {
recycledBitmap = bitmap::toPixelRef(env, javaBitmap);
recycledBitmap = bitmap::toBitmap(env, javaBitmap);
if (recycledBitmap->isImmutable()) {
ALOGW("Warning: Reusing an immutable bitmap as an image decoder target.");
}

View File

@@ -337,11 +337,11 @@ SkColorType GraphicsJNI::legacyBitmapConfigToColorType(jint legacyConfig) {
}
void GraphicsJNI::getSkBitmap(JNIEnv* env, jobject bitmap, SkBitmap* outBitmap) {
android::bitmap::toPixelRef(env, bitmap)->getSkBitmap(outBitmap);
android::bitmap::toBitmap(env, bitmap)->getSkBitmap(outBitmap);
}
SkPixelRef* GraphicsJNI::refSkPixelRef(JNIEnv* env, jobject bitmap) {
SkPixelRef* pixelRef = android::bitmap::toPixelRef(env, bitmap);
SkPixelRef* pixelRef = android::bitmap::toBitmap(env, bitmap);
pixelRef->ref();
return pixelRef;
}
@@ -401,7 +401,7 @@ jobject GraphicsJNI::createRegion(JNIEnv* env, SkRegion* region)
///////////////////////////////////////////////////////////////////////////////
android::PixelRef* GraphicsJNI::mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap,
android::Bitmap* GraphicsJNI::mapAshmemBitmap(JNIEnv* env, SkBitmap* bitmap,
SkColorTable* ctable, int fd, void* addr, size_t size, bool readOnly) {
const SkImageInfo& info = bitmap->info();
if (info.colorType() == kUnknown_SkColorType) {
@@ -423,7 +423,7 @@ android::PixelRef* GraphicsJNI::mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap,
// attempting to compute our own.
const size_t rowBytes = bitmap->rowBytes();
auto wrapper = new android::PixelRef(addr, fd, size, info, rowBytes, ctable);
auto wrapper = new android::Bitmap(addr, fd, size, info, rowBytes, ctable);
wrapper->getSkBitmap(bitmap);
if (readOnly) {
bitmap->pixelRef()->setImmutable();
@@ -445,14 +445,14 @@ sk_sp<SkColorSpace> GraphicsJNI::defaultColorSpace() {
///////////////////////////////////////////////////////////////////////////////
bool HeapAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
mStorage = android::PixelRef::allocateHeapPixelRef(bitmap, ctable);
mStorage = android::Bitmap::allocateHeapBitmap(bitmap, ctable);
return !!mStorage;
}
////////////////////////////////////////////////////////////////////////////////
RecyclingClippingPixelAllocator::RecyclingClippingPixelAllocator(
android::PixelRef* recycledBitmap, size_t recycledBytes)
android::Bitmap* recycledBitmap, size_t recycledBytes)
: mRecycledBitmap(recycledBitmap)
, mRecycledBytes(recycledBytes)
, mSkiaBitmap(nullptr)
@@ -550,7 +550,7 @@ AshmemPixelAllocator::AshmemPixelAllocator(JNIEnv *env) {
}
bool AshmemPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
mStorage = android::PixelRef::allocateAshmemPixelRef(bitmap, ctable);
mStorage = android::Bitmap::allocateAshmemBitmap(bitmap, ctable);
return !!mStorage;
}

View File

@@ -13,7 +13,7 @@
#include "SkColorSpace.h"
#include <jni.h>
#include <hwui/Canvas.h>
#include <hwui/PixelRef.h>
#include <hwui/Bitmap.h>
class SkBitmapRegionDecoder;
class SkCanvas;
@@ -72,7 +72,7 @@ public:
static jobject createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap);
static android::PixelRef* mapAshmemPixelRef(JNIEnv* env, SkBitmap* bitmap,
static android::Bitmap* mapAshmemBitmap(JNIEnv* env, SkBitmap* bitmap,
SkColorTable* ctable, int fd, void* addr, size_t size, bool readOnly);
/**
@@ -104,13 +104,13 @@ public:
/**
* Fetches the backing allocation object. Must be called!
*/
android::PixelRef* getStorageObjAndReset() {
android::Bitmap* getStorageObjAndReset() {
return mStorage.release();
};
SkCodec::ZeroInitialized zeroInit() const override { return SkCodec::kYes_ZeroInitialized; }
private:
sk_sp<android::PixelRef> mStorage;
sk_sp<android::Bitmap> mStorage;
};
/**
@@ -143,7 +143,7 @@ private:
class RecyclingClippingPixelAllocator : public SkBRDAllocator {
public:
RecyclingClippingPixelAllocator(android::PixelRef* recycledBitmap,
RecyclingClippingPixelAllocator(android::Bitmap* recycledBitmap,
size_t recycledBytes);
~RecyclingClippingPixelAllocator();
@@ -168,7 +168,7 @@ public:
SkCodec::ZeroInitialized zeroInit() const override { return SkCodec::kNo_ZeroInitialized; }
private:
android::PixelRef* mRecycledBitmap;
android::Bitmap* mRecycledBitmap;
const size_t mRecycledBytes;
SkBitmap* mSkiaBitmap;
bool mNeedsCopy;
@@ -179,13 +179,13 @@ public:
explicit AshmemPixelAllocator(JNIEnv* env);
~AshmemPixelAllocator() { };
virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable);
android::PixelRef* getStorageObjAndReset() {
android::Bitmap* getStorageObjAndReset() {
return mStorage.release();
};
private:
JavaVM* mJavaVM;
sk_sp<android::PixelRef> mStorage;
sk_sp<android::Bitmap> mStorage;
};

View File

@@ -446,8 +446,8 @@ static void drawBitmapArray(JNIEnv* env, jobject, jlong canvasHandle,
GraphicsJNI::defaultColorSpace());
SkBitmap bitmap;
bitmap.setInfo(info);
sk_sp<PixelRef> pixelRef = PixelRef::allocateHeapPixelRef(&bitmap, NULL);
if (!pixelRef) {
sk_sp<Bitmap> androidBitmap = Bitmap::allocateHeapBitmap(&bitmap, NULL);
if (!androidBitmap) {
return;
}

View File

@@ -186,14 +186,13 @@ static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
return NULL;
}
auto pixelRef = new PixelRef(
auto bitmap = new Bitmap(
(void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot,
screenshotInfo, rowBytes, nullptr);
screenshot.release();
pixelRef->setImmutable();
return bitmap::createBitmap(env, pixelRef,
bitmap::kBitmapCreateFlag_Premultiplied, NULL);
bitmap->setImmutable();
return bitmap::createBitmap(env, bitmap,
android::bitmap::kBitmapCreateFlag_Premultiplied, NULL);
}
static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj,

View File

@@ -10,13 +10,13 @@ BUGREPORT_FONT_CACHE_USAGE := false
HWUI_ENABLE_OPENGL_VALIDATION := false
hwui_src_files := \
hwui/Bitmap.cpp \
font/CacheTexture.cpp \
font/Font.cpp \
hwui/Canvas.cpp \
hwui/MinikinSkia.cpp \
hwui/MinikinUtils.cpp \
hwui/PaintImpl.cpp \
hwui/PixelRef.cpp \
hwui/Typeface.cpp \
renderstate/Blend.cpp \
renderstate/MeshState.cpp \

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "PixelRef.h"
#include "Bitmap.h"
#include "Caches.h"
@@ -34,10 +34,10 @@ static bool computeAllocationSize(const SkBitmap& bitmap, size_t* size) {
return true;
}
typedef sk_sp<PixelRef> (*AllocPixeRef)(size_t allocSize, const SkImageInfo& info, size_t rowBytes,
typedef sk_sp<Bitmap> (*AllocPixeRef)(size_t allocSize, const SkImageInfo& info, size_t rowBytes,
SkColorTable* ctable);
static sk_sp<PixelRef> allocatePixelRef(SkBitmap* bitmap, SkColorTable* ctable, AllocPixeRef alloc) {
static sk_sp<Bitmap> allocateBitmap(SkBitmap* bitmap, SkColorTable* ctable, AllocPixeRef alloc) {
const SkImageInfo& info = bitmap->info();
if (info.colorType() == kUnknown_SkColorType) {
LOG_ALWAYS_FATAL("unknown bitmap configuration");
@@ -62,24 +62,24 @@ static sk_sp<PixelRef> allocatePixelRef(SkBitmap* bitmap, SkColorTable* ctable,
return wrapper;
}
sk_sp<PixelRef> PixelRef::allocateHeapPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
return allocatePixelRef(bitmap, ctable, &PixelRef::allocateHeapPixelRef);
sk_sp<Bitmap> Bitmap::allocateHeapBitmap(SkBitmap* bitmap, SkColorTable* ctable) {
return allocateBitmap(bitmap, ctable, &Bitmap::allocateHeapBitmap);
}
sk_sp<PixelRef> PixelRef::allocateAshmemPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
return allocatePixelRef(bitmap, ctable, &PixelRef::allocateAshmemPixelRef);
sk_sp<Bitmap> Bitmap::allocateAshmemBitmap(SkBitmap* bitmap, SkColorTable* ctable) {
return allocateBitmap(bitmap, ctable, &Bitmap::allocateAshmemBitmap);
}
sk_sp<PixelRef> PixelRef::allocateHeapPixelRef(size_t size, const SkImageInfo& info, size_t rowBytes,
sk_sp<Bitmap> Bitmap::allocateHeapBitmap(size_t size, const SkImageInfo& info, size_t rowBytes,
SkColorTable* ctable) {
void* addr = calloc(size, 1);
if (!addr) {
return nullptr;
}
return sk_sp<PixelRef>(new PixelRef(addr, size, info, rowBytes, ctable));
return sk_sp<Bitmap>(new Bitmap(addr, size, info, rowBytes, ctable));
}
sk_sp<PixelRef> PixelRef::allocateAshmemPixelRef(size_t size, const SkImageInfo& info,
sk_sp<Bitmap> Bitmap::allocateAshmemBitmap(size_t size, const SkImageInfo& info,
size_t rowBytes, SkColorTable* ctable) {
// Create new ashmem region with read/write priv
int fd = ashmem_create_region("bitmap", size);
@@ -98,10 +98,10 @@ sk_sp<PixelRef> PixelRef::allocateAshmemPixelRef(size_t size, const SkImageInfo&
close(fd);
return nullptr;
}
return sk_sp<PixelRef>(new PixelRef(addr, fd, size, info, rowBytes, ctable));
return sk_sp<Bitmap>(new Bitmap(addr, fd, size, info, rowBytes, ctable));
}
void PixelRef::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, SkColorTable* ctable) {
void Bitmap::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, SkColorTable* ctable) {
if (kIndex_8_SkColorType != newInfo.colorType()) {
ctable = nullptr;
}
@@ -132,7 +132,7 @@ void PixelRef::reconfigure(const SkImageInfo& newInfo, size_t rowBytes, SkColorT
setPreLocked(getStorage(), mRowBytes, mColorTable.get());
}
PixelRef::PixelRef(void* address, size_t size, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
Bitmap::Bitmap(void* address, size_t size, const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
: SkPixelRef(info)
, mPixelStorageType(PixelStorageType::Heap) {
mPixelStorage.heap.address = address;
@@ -140,7 +140,7 @@ PixelRef::PixelRef(void* address, size_t size, const SkImageInfo& info, size_t r
reconfigure(info, rowBytes, ctable);
}
PixelRef::PixelRef(void* address, void* context, FreeFunc freeFunc,
Bitmap::Bitmap(void* address, void* context, FreeFunc freeFunc,
const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
: SkPixelRef(info)
, mPixelStorageType(PixelStorageType::External) {
@@ -150,7 +150,7 @@ PixelRef::PixelRef(void* address, void* context, FreeFunc freeFunc,
reconfigure(info, rowBytes, ctable);
}
PixelRef::PixelRef(void* address, int fd, size_t mappedSize,
Bitmap::Bitmap(void* address, int fd, size_t mappedSize,
const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable)
: SkPixelRef(info)
, mPixelStorageType(PixelStorageType::Ashmem) {
@@ -160,7 +160,7 @@ PixelRef::PixelRef(void* address, int fd, size_t mappedSize,
reconfigure(info, rowBytes, ctable);
}
PixelRef::~PixelRef() {
Bitmap::~Bitmap() {
switch (mPixelStorageType) {
case PixelStorageType::External:
mPixelStorage.external.freeFunc(mPixelStorage.external.address,
@@ -180,15 +180,15 @@ PixelRef::~PixelRef() {
}
}
bool PixelRef::hasHardwareMipMap() const {
bool Bitmap::hasHardwareMipMap() const {
return mHasHardwareMipMap;
}
void PixelRef::setHasHardwareMipMap(bool hasMipMap) {
void Bitmap::setHasHardwareMipMap(bool hasMipMap) {
mHasHardwareMipMap = hasMipMap;
}
void* PixelRef::getStorage() const {
void* Bitmap::getStorage() const {
switch (mPixelStorageType) {
case PixelStorageType::External:
return mPixelStorage.external.address;
@@ -199,18 +199,18 @@ void* PixelRef::getStorage() const {
}
}
bool PixelRef::onNewLockPixels(LockRec* rec) {
bool Bitmap::onNewLockPixels(LockRec* rec) {
rec->fPixels = getStorage();
rec->fRowBytes = mRowBytes;
rec->fColorTable = mColorTable.get();
return true;
}
size_t PixelRef::getAllocatedSizeInBytes() const {
size_t Bitmap::getAllocatedSizeInBytes() const {
return info().getSafeSize(mRowBytes);
}
int PixelRef::getAshmemFd() const {
int Bitmap::getAshmemFd() const {
switch (mPixelStorageType) {
case PixelStorageType::Ashmem:
return mPixelStorage.ashmem.fd;
@@ -219,7 +219,7 @@ int PixelRef::getAshmemFd() const {
}
}
size_t PixelRef::getAllocationByteCount() const {
size_t Bitmap::getAllocationByteCount() const {
switch (mPixelStorageType) {
case PixelStorageType::Heap:
return mPixelStorage.heap.size;
@@ -228,11 +228,11 @@ size_t PixelRef::getAllocationByteCount() const {
}
}
void PixelRef::reconfigure(const SkImageInfo& info) {
void Bitmap::reconfigure(const SkImageInfo& info) {
reconfigure(info, info.minRowBytes(), nullptr);
}
void PixelRef::setAlphaType(SkAlphaType alphaType) {
void Bitmap::setAlphaType(SkAlphaType alphaType) {
if (!SkColorTypeValidateAlphaType(info().colorType(), alphaType, &alphaType)) {
return;
}
@@ -240,7 +240,7 @@ void PixelRef::setAlphaType(SkAlphaType alphaType) {
changeAlphaType(alphaType);
}
void PixelRef::getSkBitmap(SkBitmap* outBitmap) {
void Bitmap::getSkBitmap(SkBitmap* outBitmap) {
outBitmap->setInfo(info(), rowBytes());
outBitmap->setPixelRef(this);
outBitmap->setHasHardwareMipMap(mHasHardwareMipMap);

View File

@@ -31,21 +31,21 @@ enum class PixelStorageType {
typedef void (*FreeFunc)(void* addr, void* context);
class ANDROID_API PixelRef : public SkPixelRef {
class ANDROID_API Bitmap : public SkPixelRef {
public:
static sk_sp<PixelRef> allocateHeapPixelRef(SkBitmap* bitmap, SkColorTable* ctable);
static sk_sp<PixelRef> allocateHeapPixelRef(size_t allocSize, const SkImageInfo& info,
static sk_sp<Bitmap> allocateHeapBitmap(SkBitmap* bitmap, SkColorTable* ctable);
static sk_sp<Bitmap> allocateHeapBitmap(size_t allocSize, const SkImageInfo& info,
size_t rowBytes, SkColorTable* ctable);
static sk_sp<PixelRef> allocateAshmemPixelRef(SkBitmap* bitmap, SkColorTable* ctable);
static sk_sp<PixelRef> allocateAshmemPixelRef(size_t allocSize, const SkImageInfo& info,
static sk_sp<Bitmap> allocateAshmemBitmap(SkBitmap* bitmap, SkColorTable* ctable);
static sk_sp<Bitmap> allocateAshmemBitmap(size_t allocSize, const SkImageInfo& info,
size_t rowBytes, SkColorTable* ctable);
PixelRef(void* address, size_t allocSize, const SkImageInfo& info, size_t rowBytes,
Bitmap(void* address, size_t allocSize, const SkImageInfo& info, size_t rowBytes,
SkColorTable* ctable);
PixelRef(void* address, void* context, FreeFunc freeFunc,
Bitmap(void* address, void* context, FreeFunc freeFunc,
const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable);
PixelRef(void* address, int fd, size_t mappedSize, const SkImageInfo& info,
Bitmap(void* address, int fd, size_t mappedSize, const SkImageInfo& info,
size_t rowBytes, SkColorTable* ctable);
int width() const { return info().width(); }
@@ -54,7 +54,7 @@ public:
// Can't mark as override since SkPixelRef::rowBytes isn't virtual
// but that's OK since we just want Bitmap to be able to rely
// on calling rowBytes() on an unlocked pixelref, which it will be
// doing on a PixelRef type, not a SkPixelRef, so static
// doing on a Bitmap type, not a SkPixelRef, so static
// dispatching will do what we want.
size_t rowBytes() const { return mRowBytes; }
void reconfigure(const SkImageInfo& info, size_t rowBytes, SkColorTable* ctable);
@@ -66,17 +66,17 @@ public:
int getAshmemFd() const;
size_t getAllocationByteCount() const;
void setHasHardwareMipMap(bool hasMipMap);
bool hasHardwareMipMap() const;
protected:
virtual bool onNewLockPixels(LockRec* rec) override;
virtual void onUnlockPixels() override { };
virtual size_t getAllocatedSizeInBytes() const override;
private:
friend class Bitmap;
virtual ~PixelRef();
virtual ~Bitmap();
void doFreePixels();
void* getStorage() const;
void setHasHardwareMipMap(bool hasMipMap);
bool hasHardwareMipMap() const;
PixelStorageType mPixelStorageType;

View File

@@ -21,7 +21,7 @@
#include <Matrix.h>
#include <Rect.h>
#include <RenderNode.h>
#include <hwui/PixelRef.h>
#include <hwui/Bitmap.h>
#include <renderstate/RenderState.h>
#include <renderthread/RenderThread.h>
#include <Snapshot.h>
@@ -129,7 +129,7 @@ public:
SkImageInfo info = SkImageInfo::Make(width, height,
colorType, kPremul_SkAlphaType, colorSpace);
bitmap.setInfo(info);
PixelRef::allocateHeapPixelRef(&bitmap, nullptr);
Bitmap::allocateHeapBitmap(&bitmap, nullptr);
return bitmap;
}