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

Commit bc8bd76b authored by Derek Sollenberger's avatar Derek Sollenberger Committed by Android (Google) Code Review
Browse files

Merge "Refactor android.graphics.Picture JNI bindings."

parents 19f01ebe 4b0959d8
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -804,20 +804,12 @@ class GLES20Canvas extends HardwareCanvas {

    @Override
    public void drawPicture(Picture picture) {
        if (picture.createdFromStream) {
            return;
        }

        picture.endRecording();
        // TODO: Implement rendering
    }

    @Override
    public void drawPicture(Picture picture, Rect dst) {
        if (picture.createdFromStream) {
            return;
        }

        save();
        translate(dst.left, dst.top);
        if (picture.getWidth() > 0 && picture.getHeight() > 0) {
@@ -829,10 +821,6 @@ class GLES20Canvas extends HardwareCanvas {

    @Override
    public void drawPicture(Picture picture, RectF dst) {
        if (picture.createdFromStream) {
            return;
        }

        save();
        translate(dst.left, dst.top);
        if (picture.getWidth() > 0 && picture.getHeight() > 0) {
+1 −1
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ LOCAL_SRC_FILES:= \
	android_util_Process.cpp \
	android_util_StringBlock.cpp \
	android_util_XmlBlock.cpp \
	android/graphics/AndroidPicture.cpp \
	android_graphics_Picture.cpp \
	android/graphics/AutoDecodeCancel.cpp \
	android/graphics/Bitmap.cpp \
	android/graphics/BitmapFactory.cpp \
+0 −112
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();
}
+0 −12
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
#include "jni.h"
#include "JNIHelp.h"
#include "GraphicsJNI.h"
#include "AndroidPicture.h"

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

AndroidPicture* GraphicsJNI::getNativePicture(JNIEnv* env, jobject picture)
{
    SkASSERT(env);
    SkASSERT(picture);
    SkASSERT(env->IsInstanceOf(picture, gPicture_class));
    jlong pictureHandle = env->GetLongField(picture, gPicture_nativeInstanceID);
    AndroidPicture* p = reinterpret_cast<AndroidPicture*>(pictureHandle);
    SkASSERT(p);
    return p;
}

SkRegion* GraphicsJNI::getNativeRegion(JNIEnv* env, jobject region)
{
    SkASSERT(env);
+0 −2
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@
class SkBitmapRegionDecoder;
class SkCanvas;
class SkPaint;
class AndroidPicture;

class GraphicsJNI {
public:
@@ -50,7 +49,6 @@ public:
    static SkPaint*  getNativePaint(JNIEnv*, jobject paint);
    static android::TypefaceImpl* getNativeTypeface(JNIEnv*, jobject paint);
    static SkBitmap* getNativeBitmap(JNIEnv*, jobject bitmap);
    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