Merge "Use unique_ptr instead of SkAutoTDelete."

This commit is contained in:
Ben Wagner
2015-08-07 22:03:24 +00:00
committed by Android (Google) Code Review
13 changed files with 77 additions and 93 deletions

View File

@@ -1,24 +1,24 @@
#define LOG_TAG "BitmapFactory"
#include "AutoDecodeCancel.h"
#include "BitmapFactory.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include "GraphicsJNI.h"
#include "NinePatchPeeker.h"
#include "SkFrontBufferedStream.h"
#include "SkImageDecoder.h"
#include "SkMath.h"
#include "SkPixelRef.h"
#include "SkStream.h"
#include "SkTemplates.h"
#include "SkUtils.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include "AutoDecodeCancel.h"
#include "Utils.h"
#include "JNIHelp.h"
#include "GraphicsJNI.h"
#include "core_jni_helpers.h"
#include <JNIHelp.h>
#include <androidfw/Asset.h>
#include <androidfw/ResourceTypes.h>
#include <cutils/compiler.h>
#include <memory>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/mman.h>
@@ -291,7 +291,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
// Only setup the decoder to be deleted after its stack-based, refcounted
// components (allocators, peekers, etc) are declared. This prevents RefCnt
// asserts from firing due to the order objects are deleted from the stack.
SkAutoTDelete<SkImageDecoder> add(decoder);
std::unique_ptr<SkImageDecoder> add(decoder);
AutoDecoderCancel adc(options, decoder);
@@ -453,13 +453,13 @@ static jobject nativeDecodeStream(JNIEnv* env, jobject clazz, jobject is, jbyteA
jobject padding, jobject options) {
jobject bitmap = NULL;
SkAutoTDelete<SkStream> stream(CreateJavaInputStreamAdaptor(env, is, storage));
std::unique_ptr<SkStream> stream(CreateJavaInputStreamAdaptor(env, is, storage));
if (stream.get()) {
SkAutoTDelete<SkStreamRewindable> bufferedStream(
SkFrontBufferedStream::Create(stream.detach(), BYTES_TO_BUFFER));
std::unique_ptr<SkStreamRewindable> bufferedStream(
SkFrontBufferedStream::Create(stream.release(), BYTES_TO_BUFFER));
SkASSERT(bufferedStream.get() != NULL);
bitmap = doDecode(env, bufferedStream, padding, options);
bitmap = doDecode(env, bufferedStream.get(), padding, options);
}
return bitmap;
}
@@ -496,16 +496,16 @@ static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fi
return nullObjectReturn("Could not open file");
}
SkAutoTDelete<SkFILEStream> fileStream(new SkFILEStream(file,
std::unique_ptr<SkFILEStream> fileStream(new SkFILEStream(file,
SkFILEStream::kCallerPasses_Ownership));
// Use a buffered stream. Although an SkFILEStream can be rewound, this
// ensures that SkImageDecoder::Factory never rewinds beyond the
// current position of the file descriptor.
SkAutoTDelete<SkStreamRewindable> stream(SkFrontBufferedStream::Create(fileStream.detach(),
std::unique_ptr<SkStreamRewindable> stream(SkFrontBufferedStream::Create(fileStream.release(),
BYTES_TO_BUFFER));
return doDecode(env, stream, padding, bitmapFactoryOptions);
return doDecode(env, stream.get(), padding, bitmapFactoryOptions);
}
static jobject nativeDecodeAsset(JNIEnv* env, jobject clazz, jlong native_asset,
@@ -514,16 +514,16 @@ static jobject nativeDecodeAsset(JNIEnv* env, jobject clazz, jlong native_asset,
Asset* asset = reinterpret_cast<Asset*>(native_asset);
// since we know we'll be done with the asset when we return, we can
// just use a simple wrapper
SkAutoTDelete<SkStreamRewindable> stream(new AssetStreamAdaptor(asset));
return doDecode(env, stream, padding, options);
AssetStreamAdaptor stream(asset);
return doDecode(env, &stream, padding, options);
}
static jobject nativeDecodeByteArray(JNIEnv* env, jobject, jbyteArray byteArray,
jint offset, jint length, jobject options) {
AutoJavaByteArray ar(env, byteArray);
SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(ar.ptr() + offset, length, false));
return doDecode(env, stream, NULL, options);
SkMemoryStream stream(ar.ptr() + offset, length, false);
return doDecode(env, &stream, NULL, options);
}
static void nativeRequestCancel(JNIEnv*, jobject joptions) {
@@ -536,7 +536,7 @@ static jboolean nativeIsSeekable(JNIEnv* env, jobject, jobject fileDescriptor) {
}
jobject decodeBitmap(JNIEnv* env, void* data, size_t size) {
SkMemoryStream stream(data, size);
SkMemoryStream stream(data, size);
return doDecode(env, &stream, NULL, NULL);
}

View File

@@ -16,28 +16,25 @@
#define LOG_TAG "BitmapRegionDecoder"
#include "AutoDecodeCancel.h"
#include "BitmapFactory.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include "SkBitmap.h"
#include "SkData.h"
#include "SkImageEncoder.h"
#include "GraphicsJNI.h"
#include "SkImageEncoder.h"
#include "SkUtils.h"
#include "SkTemplates.h"
#include "SkPixelRef.h"
#include "SkStream.h"
#include "BitmapFactory.h"
#include "AutoDecodeCancel.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include "Utils.h"
#include "JNIHelp.h"
#include "core_jni_helpers.h"
#include "android_util_Binder.h"
#include "android_nio_utils.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include "android_util_Binder.h"
#include "core_jni_helpers.h"
#include <JNIHelp.h>
#include <androidfw/Asset.h>
#include <binder/Parcel.h>
#include <jni.h>
#include <androidfw/Asset.h>
#include <sys/stat.h>
using namespace android;

View File

@@ -1,11 +1,13 @@
#include "CreateJavaOutputStreamAdaptor.h"
#include "JNIHelp.h"
#include "SkData.h"
#include "SkRefCnt.h"
#include "SkStream.h"
#include "SkTypes.h"
#include "Utils.h"
#include <JNIHelp.h>
#include <memory>
static jmethodID gInputStream_readMethodID;
static jmethodID gInputStream_skipMethodID;
@@ -164,7 +166,7 @@ static SkMemoryStream* adaptor_to_mem_stream(SkStream* stream) {
SkStreamRewindable* CopyJavaInputStream(JNIEnv* env, jobject stream,
jbyteArray storage) {
SkAutoTDelete<SkStream> adaptor(CreateJavaInputStreamAdaptor(env, stream, storage));
std::unique_ptr<SkStream> adaptor(CreateJavaInputStreamAdaptor(env, stream, storage));
if (NULL == adaptor.get()) {
return NULL;
}

View File

@@ -1,9 +1,8 @@
#include "jni.h"
#include "core_jni_helpers.h"
#include "GraphicsJNI.h"
#include "SkInterpolator.h"
#include "SkTemplates.h"
#include "core_jni_helpers.h"
#include <jni.h>
static jlong Interpolator_constructor(JNIEnv* env, jobject clazz, jint valueCount, jint frameCount)
{

View File

@@ -15,16 +15,13 @@
** limitations under the License.
*/
#include "jni.h"
#include "GraphicsJNI.h"
#include <core_jni_helpers.h>
#include "SkMatrix.h"
#include "SkTemplates.h"
#include "Matrix.h"
#include "SkMatrix.h"
#include "core_jni_helpers.h"
#include <Caches.h>
#include <jni.h>
namespace android {

View File

@@ -1,21 +1,20 @@
#include "Canvas.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include "GraphicsJNI.h"
#include "Paint.h"
#include "ScopedLocalRef.h"
#include "SkFrontBufferedStream.h"
#include "SkMovie.h"
#include "SkStream.h"
#include "GraphicsJNI.h"
#include "SkTemplates.h"
#include "SkUtils.h"
#include "Utils.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include "Paint.h"
#include "core_jni_helpers.h"
#include <androidfw/Asset.h>
#include <androidfw/ResourceTypes.h>
#include <jni.h>
#include <netinet/in.h>
#include "core_jni_helpers.h"
static jclass gMovie_class;
static jmethodID gMovie_constructorMethodID;
static jfieldID gMovie_nativeInstanceID;
@@ -84,8 +83,8 @@ static void movie_draw(JNIEnv* env, jobject movie, jlong canvasHandle,
static jobject movie_decodeAsset(JNIEnv* env, jobject clazz, jlong native_asset) {
android::Asset* asset = reinterpret_cast<android::Asset*>(native_asset);
if (asset == NULL) return NULL;
SkAutoTDelete<SkStreamRewindable> stream(new android::AssetStreamAdaptor(asset));
SkMovie* moov = SkMovie::DecodeStream(stream.get());
android::AssetStreamAdaptor stream(asset);
SkMovie* moov = SkMovie::DecodeStream(&stream);
return create_jmovie(env, moov);
}
@@ -105,10 +104,10 @@ static jobject movie_decodeStream(JNIEnv* env, jobject clazz, jobject istream) {
// will only read 6.
// FIXME: Get this number from SkImageDecoder
// bufferedStream takes ownership of strm
SkAutoTDelete<SkStreamRewindable> bufferedStream(SkFrontBufferedStream::Create(strm, 6));
std::unique_ptr<SkStreamRewindable> bufferedStream(SkFrontBufferedStream::Create(strm, 6));
SkASSERT(bufferedStream.get() != NULL);
SkMovie* moov = SkMovie::DecodeStream(bufferedStream);
SkMovie* moov = SkMovie::DecodeStream(bufferedStream.get());
return create_jmovie(env, moov);
}

View File

@@ -1,14 +1,12 @@
#include <jni.h>
#include "GraphicsJNI.h"
#include "core_jni_helpers.h"
#include "SkPathEffect.h"
#include "Sk1DPathEffect.h"
#include "SkCornerPathEffect.h"
#include "SkDashPathEffect.h"
#include "SkDiscretePathEffect.h"
#include "Sk1DPathEffect.h"
#include "SkTemplates.h"
#include "SkPathEffect.h"
#include "core_jni_helpers.h"
#include <jni.h>
class SkPathEffectGlue {
public:

View File

@@ -16,9 +16,10 @@
#include "Canvas.h"
#include "Picture.h"
#include "SkStream.h"
#include <memory>
namespace android {
Picture::Picture(const Picture* src) {
@@ -81,7 +82,7 @@ Picture* Picture::CreateFromStream(SkStream* stream) {
void Picture::serialize(SkWStream* stream) const {
if (NULL != mRecorder.get()) {
SkAutoTDelete<SkPicture> tempPict(this->makePartialCopy());
std::unique_ptr<SkPicture> tempPict(this->makePartialCopy());
tempPict->serialize(stream);
} else if (NULL != mPicture.get()) {
validate();
@@ -89,7 +90,7 @@ void Picture::serialize(SkWStream* stream) const {
} else {
SkPictureRecorder recorder;
recorder.beginRecording(0, 0);
SkAutoTUnref<SkPicture> empty(recorder.endRecording());
std::unique_ptr<SkPicture> empty(recorder.endRecording());
empty->serialize(stream);
}
}

View File

@@ -20,7 +20,8 @@
#include "SkPicture.h"
#include "SkPictureRecorder.h"
#include "SkRefCnt.h"
#include "SkTemplates.h"
#include <memory>
class SkStream;
class SkWStream;
@@ -55,7 +56,7 @@ private:
int mWidth;
int mHeight;
SkAutoTUnref<const SkPicture> mPicture;
SkAutoTDelete<SkPictureRecorder> mRecorder;
std::unique_ptr<SkPictureRecorder> mRecorder;
// Make a copy of a picture that is in the midst of being recorded. The
// resulting picture will have balanced saves and restores.

View File

@@ -1,15 +1,12 @@
#include <jni.h>
#include "GraphicsJNI.h"
#include "SkShader.h"
#include "SkGradientShader.h"
#include "SkComposeShader.h"
#include "SkTemplates.h"
#include "SkGradientShader.h"
#include "SkShader.h"
#include "SkXfermode.h"
#include "core_jni_helpers.h"
#include <Caches.h>
#include "core_jni_helpers.h"
#include <jni.h>
using namespace android::uirenderer;

View File

@@ -14,16 +14,14 @@
* limitations under the License.
*/
#include "jni.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include "GraphicsJNI.h"
#include "core_jni_helpers.h"
#include "Picture.h"
#include "SkCanvas.h"
#include "SkStream.h"
#include "SkTemplates.h"
#include "CreateJavaOutputStreamAdaptor.h"
#include "core_jni_helpers.h"
#include <jni.h>
namespace android {

View File

@@ -16,35 +16,28 @@
#define LOG_TAG "SurfaceControl"
#include <stdio.h>
#include "jni.h"
#include "JNIHelp.h"
#include "android_os_Parcel.h"
#include "android_util_Binder.h"
#include "android/graphics/Bitmap.h"
#include "android/graphics/GraphicsJNI.h"
#include "android/graphics/Region.h"
#include "core_jni_helpers.h"
#include <JNIHelp.h>
#include <ScopedUtfChars.h>
#include <android_runtime/android_view_Surface.h>
#include <android_runtime/android_view_SurfaceSession.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <jni.h>
#include <memory>
#include <stdio.h>
#include <ui/DisplayInfo.h>
#include <ui/FrameStats.h>
#include <ui/Rect.h>
#include <ui/Region.h>
#include <utils/Log.h>
#include <ScopedUtfChars.h>
#include "SkTemplates.h"
// ----------------------------------------------------------------------------
namespace android {
@@ -131,7 +124,7 @@ static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
int bottom = env->GetIntField(sourceCropObj, gRectClassInfo.bottom);
Rect sourceCrop(left, top, right, bottom);
SkAutoTDelete<ScreenshotClient> screenshot(new ScreenshotClient());
std::unique_ptr<ScreenshotClient> screenshot(new ScreenshotClient());
status_t res;
if (allLayers) {
minLayer = 0;
@@ -179,7 +172,7 @@ static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
Bitmap* bitmap = new Bitmap(
(void*) screenshot->getPixels(), (void*) screenshot.get(), DeleteScreenshot,
screenshotInfo, rowBytes, nullptr);
screenshot.detach();
screenshot.release();
bitmap->peekAtPixelRef()->setImmutable();
return GraphicsJNI::createBitmap(env, bitmap,

View File

@@ -26,6 +26,8 @@
#include <SkTArray.h>
#include <SkTemplates.h>
#include <memory>
namespace android {
// Holds an SkCanvas reference plus additional native data.
@@ -151,7 +153,7 @@ private:
void drawTextDecorations(float x, float y, float length, const SkPaint& paint);
SkAutoTUnref<SkCanvas> mCanvas;
SkAutoTDelete<SkDeque> mSaveStack; // lazily allocated, tracks partial saves.
std::unique_ptr<SkDeque> mSaveStack; // lazily allocated, tracks partial saves.
};
Canvas* Canvas::create_canvas(const SkBitmap& bitmap) {