Skip to content

Commit f3c16a1

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Reduce gradients textures size whenever possible" into jb-mr1-dev
2 parents 08532ab + 320d46b commit f3c16a1

File tree

4 files changed

+100
-11
lines changed

4 files changed

+100
-11
lines changed

libs/hwui/GradientCache.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <utils/threads.h>
2020

21+
#include "Caches.h"
2122
#include "Debug.h"
2223
#include "GradientCache.h"
2324
#include "Properties.h"
@@ -128,9 +129,13 @@ void GradientCache::clear() {
128129

129130
void GradientCache::getGradientInfo(const uint32_t* colors, const int count,
130131
GradientInfo& info) {
131-
uint32_t width = 1 << (31 - __builtin_clz(256 * (count - 1)));
132-
bool hasAlpha = false;
132+
uint32_t width = 256 * (count - 1);
133+
134+
if (!Caches::getInstance().extensions.hasNPot()) {
135+
width = 1 << (31 - __builtin_clz(width));
136+
}
133137

138+
bool hasAlpha = false;
134139
for (int i = 0; i < count; i++) {
135140
if (((colors[i] >> 24) & 0xff) < 255) {
136141
hasAlpha = true;

libs/hwui/ProgramCache.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ const char* gVS_Header_Varyings_HasBitmap =
6969
"varying highp vec2 outBitmapTexCoords;\n";
7070
const char* gVS_Header_Varyings_PointHasBitmap =
7171
"varying highp vec2 outPointBitmapTexCoords;\n";
72-
// TODO: These values are used to sample from textures,
73-
// they may need to be highp
7472
const char* gVS_Header_Varyings_HasGradient[6] = {
7573
// Linear
7674
"varying highp vec2 linear;\n",
77-
"varying highp float linear;\n",
75+
"varying float linear;\n",
7876

7977
// Circular
8078
"varying highp vec2 circular;\n",
@@ -268,21 +266,21 @@ const char* gFS_Main_FetchA8Texture[2] = {
268266
};
269267
const char* gFS_Main_FetchGradient[6] = {
270268
// Linear
271-
" highp vec4 gradientColor = texture2D(gradientSampler, linear);\n",
269+
" vec4 gradientColor = texture2D(gradientSampler, linear);\n",
272270

273-
" highp vec4 gradientColor = mix(startColor, endColor, clamp(linear, 0.0, 1.0));\n",
271+
" vec4 gradientColor = mix(startColor, endColor, clamp(linear, 0.0, 1.0));\n",
274272

275273
// Circular
276-
" highp vec4 gradientColor = texture2D(gradientSampler, vec2(length(circular), 0.5));\n",
274+
" vec4 gradientColor = texture2D(gradientSampler, vec2(length(circular), 0.5));\n",
277275

278-
" highp vec4 gradientColor = mix(startColor, endColor, clamp(length(circular), 0.0, 1.0));\n",
276+
" vec4 gradientColor = mix(startColor, endColor, clamp(length(circular), 0.0, 1.0));\n",
279277

280278
// Sweep
281279
" highp float index = atan(sweep.y, sweep.x) * 0.15915494309; // inv(2 * PI)\n"
282-
" highp vec4 gradientColor = texture2D(gradientSampler, vec2(index - floor(index), 0.5));\n",
280+
" vec4 gradientColor = texture2D(gradientSampler, vec2(index - floor(index), 0.5));\n",
283281

284282
" highp float index = atan(sweep.y, sweep.x) * 0.15915494309; // inv(2 * PI)\n"
285-
" highp vec4 gradientColor = mix(startColor, endColor, clamp(index - floor(index), 0.0, 1.0));\n"
283+
" vec4 gradientColor = mix(startColor, endColor, clamp(index - floor(index), 0.0, 1.0));\n"
286284
};
287285
const char* gFS_Main_FetchBitmap =
288286
" vec4 bitmapColor = texture2D(bitmapSampler, outBitmapTexCoords);\n";

tests/HwAccelerationTest/AndroidManifest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232

3333
<meta-data android:name="android.graphics.renderThread" android:value="true" />
3434

35+
<activity
36+
android:name="TextPathActivity"
37+
android:label="_TextPath">
38+
<intent-filter>
39+
<action android:name="android.intent.action.MAIN" />
40+
<category android:name="android.intent.category.LAUNCHER" />
41+
</intent-filter>
42+
</activity>
43+
3544
<activity
3645
android:name="GradientStopsActivity"
3746
android:label="_GradientStops">
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (C) 2010 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.android.test.hwui;
18+
19+
import android.app.Activity;
20+
import android.content.Context;
21+
import android.graphics.Canvas;
22+
import android.graphics.Paint;
23+
import android.graphics.Path;
24+
import android.os.Bundle;
25+
import android.view.View;
26+
import android.widget.ScrollView;
27+
28+
@SuppressWarnings({"UnusedDeclaration"})
29+
public class TextPathActivity extends Activity {
30+
@Override
31+
protected void onCreate(Bundle savedInstanceState) {
32+
super.onCreate(savedInstanceState);
33+
34+
ScrollView scroller = new ScrollView(this);
35+
scroller.addView(new CustomTextView(this));
36+
setContentView(scroller);
37+
}
38+
39+
static class CustomTextView extends View {
40+
private final Paint mHugePaint;
41+
42+
CustomTextView(Context c) {
43+
super(c);
44+
45+
mHugePaint = new Paint();
46+
mHugePaint.setAntiAlias(true);
47+
mHugePaint.setColor(0xff000000);
48+
mHugePaint.setTextSize(300f);
49+
}
50+
51+
@Override
52+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
53+
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), 3000);
54+
}
55+
56+
@Override
57+
protected void onDraw(Canvas canvas) {
58+
super.onDraw(canvas);
59+
canvas.drawRGB(255, 255, 255);
60+
61+
Path path = new Path();
62+
63+
canvas.translate(100.0f, 300.0f);
64+
drawTextAsPath(canvas, "Hello", path);
65+
66+
canvas.translate(0.0f, 400.0f);
67+
drawTextAsPath(canvas, "OpenGL", path);
68+
}
69+
70+
private void drawTextAsPath(Canvas canvas, String text, Path path) {
71+
int count = text.length();
72+
mHugePaint.getTextPath(text, 0, count, 0, 0, path);
73+
path.close();
74+
canvas.drawPath(path, mHugePaint);
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)