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

Commit 1e59f9d1 authored by Romain Guy's avatar Romain Guy
Browse files

Fix texture coordinates for sub-bitmap rendering.

Change-Id: I05a31775e03f5b223a55a5144d420351abac89be
parent f504a2fa
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -1369,10 +1369,10 @@ void OpenGLRenderer::drawBitmap(SkBitmap* bitmap,
    const float width = texture->width;
    const float height = texture->height;

    const float u1 = srcLeft / width;
    const float v1 = srcTop / height;
    const float u2 = srcRight / width;
    const float v2 = srcBottom / height;
    const float u1 = (srcLeft + 0.5f) / width;
    const float v1 = (srcTop + 0.5f)  / height;
    const float u2 = (srcRight - 0.5f) / width;
    const float v2 = (srcBottom - 0.5f) / height;

    mCaches.unbindMeshBuffer();
    resetDrawTextureTexCoords(u1, v1, u2, v2);
+2.8 KiB
Loading image diff...
+25 −0
Original line number Diff line number Diff line
@@ -18,7 +18,10 @@ package com.android.test.hwui;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
@@ -42,6 +45,7 @@ public class ThinPatchesActivity extends Activity {

    private class PatchView extends View {
        private Drawable mPatch1, mPatch2;
        private Bitmap mTexture;

        public PatchView(Activity activity) {
            super(activity);
@@ -49,6 +53,20 @@ public class ThinPatchesActivity extends Activity {
            final Resources resources = activity.getResources();
            mPatch1 = resources.getDrawable(R.drawable.patch);
            mPatch2 = resources.getDrawable(R.drawable.btn_toggle_on);

            mTexture = Bitmap.createBitmap(4, 3, Bitmap.Config.ARGB_8888);
            mTexture.setPixel(0, 0, 0xffff0000);
            mTexture.setPixel(1, 0, 0xffffffff);
            mTexture.setPixel(2, 0, 0xff000000);
            mTexture.setPixel(3, 0, 0xffff0000);
            mTexture.setPixel(0, 1, 0xffff0000);
            mTexture.setPixel(1, 1, 0xff000000);
            mTexture.setPixel(2, 1, 0xffffffff);
            mTexture.setPixel(3, 1, 0xffff0000);
            mTexture.setPixel(0, 2, 0xffff0000);
            mTexture.setPixel(1, 2, 0xffff0000);
            mTexture.setPixel(2, 2, 0xffff0000);
            mTexture.setPixel(3, 2, 0xffff0000);
        }

        @Override
@@ -62,10 +80,17 @@ public class ThinPatchesActivity extends Activity {
            mPatch1.setBounds(left, top, left + width, top + height);
            mPatch1.draw(canvas);

            canvas.save();
            canvas.translate(0.0f, height + 20.0f);
            
            mPatch2.setBounds(left, top, left + width, top + height);
            mPatch2.draw(canvas);

            canvas.restore();

//            Rect src = new Rect(1, 0, 3, 2);
//            RectF dst = new RectF(0, 0, getWidth(), getHeight());
//            canvas.drawBitmap(mTexture, src, dst, null);
        }
    }
}