Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e9df83b authored by Leon Scroggins's avatar Leon Scroggins Committed by Android (Google) Code Review
Browse files

Merge "Changes to framework for ToT Skia."

parents dcdb8df2 b59508fc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ LOCAL_SRC_FILES:= \
	android_util_Process.cpp \
	android_util_StringBlock.cpp \
	android_util_XmlBlock.cpp \
	android/graphics/AndroidPicture.cpp \
	android/graphics/AutoDecodeCancel.cpp \
	android/graphics/Bitmap.cpp \
	android/graphics/BitmapFactory.cpp \
+112 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "AndroidPicture.h"
#include "SkCanvas.h"
#include "SkStream.h"

AndroidPicture::AndroidPicture(const AndroidPicture* src) {
    if (NULL != src) {
        mWidth = src->width();
        mHeight = src->height();
        if (NULL != src->mPicture.get()) {
            mPicture.reset(SkRef(src->mPicture.get()));
        } if (NULL != src->mRecorder.get()) {
            mPicture.reset(src->makePartialCopy());
        }
    } else {
        mWidth = 0;
        mHeight = 0;
    }
}

SkCanvas* AndroidPicture::beginRecording(int width, int height) {
    mPicture.reset(NULL);
    mRecorder.reset(new SkPictureRecorder);
    mWidth = width;
    mHeight = height;
    return mRecorder->beginRecording(width, height, NULL, 0);
}

void AndroidPicture::endRecording() {
    if (NULL != mRecorder.get()) {
        mPicture.reset(mRecorder->endRecording());
        mRecorder.reset(NULL);
    }
}

int AndroidPicture::width() const {
    if (NULL != mPicture.get()) {
        SkASSERT(mPicture->width() == mWidth);
        SkASSERT(mPicture->height() == mHeight);
    }

    return mWidth;
}

int AndroidPicture::height() const {
    if (NULL != mPicture.get()) {
        SkASSERT(mPicture->width() == mWidth);
        SkASSERT(mPicture->height() == mHeight);
    }

    return mHeight;
}

AndroidPicture* AndroidPicture::CreateFromStream(SkStream* stream) {
    AndroidPicture* newPict = new AndroidPicture;

    newPict->mPicture.reset(SkPicture::CreateFromStream(stream));
    if (NULL != newPict->mPicture.get()) {
        newPict->mWidth = newPict->mPicture->width();
        newPict->mHeight = newPict->mPicture->height();
    }

    return newPict;
}

void AndroidPicture::serialize(SkWStream* stream) const {
    if (NULL != mRecorder.get()) {
        SkAutoTDelete<SkPicture> tempPict(this->makePartialCopy());
        tempPict->serialize(stream);
    } else if (NULL != mPicture.get()) {
        mPicture->serialize(stream);
    } else {
        SkPicture empty;
        empty.serialize(stream);
    }
}

void AndroidPicture::draw(SkCanvas* canvas) {
    if (NULL != mRecorder.get()) {
        this->endRecording();
        SkASSERT(NULL != mPicture.get());
    }
    if (NULL != mPicture.get()) {
        // TODO: remove this const_cast once pictures are immutable
        const_cast<SkPicture*>(mPicture.get())->draw(canvas);
    }
}

SkPicture* AndroidPicture::makePartialCopy() const {
    SkASSERT(NULL != mRecorder.get());

    SkPictureRecorder reRecorder;

    SkCanvas* canvas = reRecorder.beginRecording(mWidth, mHeight, NULL, 0);
    mRecorder->partialReplay(canvas);
    return reRecorder.endRecording();
}
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_PICTURE_H
#define ANDROID_PICTURE_H

#include "SkPicture.h"
#include "SkPictureRecorder.h"
#include "SkRefCnt.h"
#include "SkTemplates.h"

class SkCanvas;
class SkPicture;
class SkPictureRecorder;
class SkStream;
class SkWStream;

// Skia's SkPicture class has been split into an SkPictureRecorder
// and an SkPicture. AndroidPicture recreates the functionality
// of the old SkPicture interface by flip-flopping between the two
// new classes.
class AndroidPicture {
public:
    explicit AndroidPicture(const AndroidPicture* src = NULL);

    SkCanvas* beginRecording(int width, int height);

    void endRecording();

    int width() const;

    int height() const;

    static AndroidPicture* CreateFromStream(SkStream* stream);

    void serialize(SkWStream* stream) const;

    void draw(SkCanvas* canvas);

private:
    int mWidth;
    int mHeight;
    SkAutoTUnref<const SkPicture> mPicture;
    SkAutoTDelete<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.
    SkPicture* makePartialCopy() const;
};
#endif // ANDROID_PICTURE_H
+3 −2
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
#include "jni.h"
#include "JNIHelp.h"
#include "GraphicsJNI.h"
#include "AndroidPicture.h"

#include "SkCanvas.h"
#include "SkDevice.h"
@@ -345,13 +346,13 @@ android::TypefaceImpl* GraphicsJNI::getNativeTypeface(JNIEnv* env, jobject paint
    return p;
}

SkPicture* GraphicsJNI::getNativePicture(JNIEnv* env, jobject picture)
AndroidPicture* GraphicsJNI::getNativePicture(JNIEnv* env, jobject picture)
{
    SkASSERT(env);
    SkASSERT(picture);
    SkASSERT(env->IsInstanceOf(picture, gPicture_class));
    jlong pictureHandle = env->GetLongField(picture, gPicture_nativeInstanceID);
    SkPicture* p = reinterpret_cast<SkPicture*>(pictureHandle);
    AndroidPicture* p = reinterpret_cast<AndroidPicture*>(pictureHandle);
    SkASSERT(p);
    return p;
}
+2 −2
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
class SkBitmapRegionDecoder;
class SkCanvas;
class SkPaint;
class SkPicture;
class AndroidPicture;

class GraphicsJNI {
public:
@@ -50,7 +50,7 @@ public:
    static SkPaint*  getNativePaint(JNIEnv*, jobject paint);
    static android::TypefaceImpl* getNativeTypeface(JNIEnv*, jobject paint);
    static SkBitmap* getNativeBitmap(JNIEnv*, jobject bitmap);
    static SkPicture* getNativePicture(JNIEnv*, jobject picture);
    static AndroidPicture* getNativePicture(JNIEnv*, jobject picture);
    static SkRegion* getNativeRegion(JNIEnv*, jobject region);

    // Given the 'native' long held by the Rasterizer.java object, return a
Loading