Fix improper clipping after a save()
Change-Id: I13426a67f20d77e2710bd500d82884098f4be97c
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 3c36f95..cc8e6bc 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -177,7 +177,7 @@
}
void OpenGLRenderer::prepare() {
- mSnapshot = mFirstSnapshot;
+ mSnapshot = new Snapshot(mFirstSnapshot);
mSaveCount = 0;
glDisable(GL_SCISSOR_TEST);
@@ -188,7 +188,7 @@
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, mWidth, mHeight);
- mSnapshot->clipRect.set(0.0f, 0.0f, mWidth, mHeight);
+ mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
}
///////////////////////////////////////////////////////////////////////////////
@@ -569,6 +569,7 @@
chooseBlending(true, mode);
bindTexture(mFontRenderer.getTexture(), GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0);
+ glUniform1i(mCurrentProgram->getUniform("sampler"), 0);
int texCoordsSlot = mCurrentProgram->getAttrib("texCoords");
glEnableVertexAttribArray(texCoordsSlot);
diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h
index 020bdb0..399ae68 100644
--- a/libs/hwui/Snapshot.h
+++ b/libs/hwui/Snapshot.h
@@ -57,8 +57,13 @@
flags(0),
previous(s),
layer(NULL),
- fbo(s->fbo),
- localClip(s->localClip) {
+ fbo(s->fbo) {
+ if ((s->flags & Snapshot::kFlagClipSet) &&
+ !(s->flags & Snapshot::kFlagDirtyLocalClip)) {
+ localClip.set(s->localClip);
+ } else {
+ flags |= Snapshot::kFlagDirtyLocalClip;
+ }
}
/**
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml
index 80480db..f917dd5 100644
--- a/tests/HwAccelerationTest/AndroidManifest.xml
+++ b/tests/HwAccelerationTest/AndroidManifest.xml
@@ -124,6 +124,15 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+
+ <activity
+ android:name="MoreShadersActivity"
+ android:label="_Shaders2">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
</application>
</manifest>
diff --git a/tests/HwAccelerationTest/src/com/google/android/test/hwui/MoreShadersActivity.java b/tests/HwAccelerationTest/src/com/google/android/test/hwui/MoreShadersActivity.java
new file mode 100644
index 0000000..8ee3117
--- /dev/null
+++ b/tests/HwAccelerationTest/src/com/google/android/test/hwui/MoreShadersActivity.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+package com.google.android.test.hwui;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.BitmapShader;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.ComposeShader;
+import android.graphics.LinearGradient;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.Shader;
+import android.os.Bundle;
+import android.view.View;
+
+@SuppressWarnings({"UnusedDeclaration"})
+public class MoreShadersActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(new ShadersView(this));
+ }
+
+ static class ShadersView extends View {
+ private BitmapShader mScaledShader;
+ private int mTexWidth;
+ private int mTexHeight;
+ private Paint mPaint;
+ private float mDrawWidth;
+ private float mDrawHeight;
+ private LinearGradient mHorGradient;
+ private LinearGradient mVertGradient;
+ private ComposeShader mComposeShader;
+ private ComposeShader mCompose2Shader;
+ private Paint mLargePaint;
+ private BitmapShader mScaled2Shader;
+
+ ShadersView(Context c) {
+ super(c);
+
+ Bitmap texture = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1);
+ mTexWidth = texture.getWidth();
+ mTexHeight = texture.getHeight();
+ mDrawWidth = mTexWidth * 2.2f;
+ mDrawHeight = mTexHeight * 1.2f;
+
+ mScaledShader = new BitmapShader(texture, Shader.TileMode.MIRROR,
+ Shader.TileMode.MIRROR);
+ Matrix m2 = new Matrix();
+ m2.setScale(0.5f, 0.5f);
+ mScaledShader.setLocalMatrix(m2);
+
+ mScaled2Shader = new BitmapShader(texture, Shader.TileMode.MIRROR,
+ Shader.TileMode.MIRROR);
+ Matrix m3 = new Matrix();
+ m3.setScale(0.1f, 0.1f);
+ mScaled2Shader.setLocalMatrix(m3);
+
+ mHorGradient = new LinearGradient(0.0f, 0.0f, mDrawWidth, 0.0f,
+ Color.RED, 0x7f00ff00, Shader.TileMode.CLAMP);
+
+ mVertGradient = new LinearGradient(0.0f, 0.0f, 0.0f, mDrawHeight / 2.0f,
+ Color.YELLOW, Color.MAGENTA, Shader.TileMode.MIRROR);
+
+ mComposeShader = new ComposeShader(mScaledShader, mHorGradient,
+ PorterDuff.Mode.SRC_OVER);
+ mCompose2Shader = new ComposeShader(mHorGradient, mScaledShader,
+ PorterDuff.Mode.SRC_OUT);
+
+ mLargePaint = new Paint();
+ mLargePaint.setAntiAlias(true);
+ mLargePaint.setTextSize(36.0f);
+ mLargePaint.setColor(0xff000000);
+
+ mPaint = new Paint();
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ canvas.drawRGB(255, 255, 255);
+
+ canvas.save();
+ canvas.translate(40.0f, 40.0f);
+
+ mPaint.setShader(mComposeShader);
+ canvas.drawRect(0.0f, 0.0f, mDrawWidth, mDrawHeight, mPaint);
+
+ canvas.translate(0.0f, 40.0f + mDrawHeight);
+ mPaint.setShader(mCompose2Shader);
+ canvas.drawRect(0.0f, 0.0f, mDrawWidth, mDrawHeight, mPaint);
+
+ canvas.restore();
+
+ canvas.drawText("OpenGL rendering", 0.0f, 20.0f, mLargePaint);
+ canvas.save();
+ canvas.translate(40.0f + mDrawWidth + 40.0f, 40.0f);
+
+ //mLargePaint.setShader(mHorGradient);
+ canvas.drawText("OpenGL rendering", 0.0f, 20.0f, mLargePaint);
+
+ mLargePaint.setShader(mScaled2Shader);
+ canvas.drawText("OpenGL rendering", 0.0f, 60.0f, mLargePaint);
+
+ mLargePaint.setShader(mCompose2Shader);
+ canvas.drawText("OpenGL rendering", 0.0f, 100.0f, mLargePaint);
+
+ canvas.translate(0.0f, 40.0f + mDrawHeight);
+ mLargePaint.setShader(mVertGradient);
+ canvas.drawText("OpenGL rendering", 0.0f, 20.0f, mLargePaint);
+
+ canvas.restore();
+ }
+ }
+}