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

Commit f3c16a12 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Reduce gradients textures size whenever possible" into jb-mr1-dev

parents 08532ab9 320d46bf
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include <utils/threads.h>

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

void GradientCache::getGradientInfo(const uint32_t* colors, const int count,
        GradientInfo& info) {
    uint32_t width = 1 << (31 - __builtin_clz(256 * (count - 1)));
    bool hasAlpha = false;
    uint32_t width = 256 * (count - 1);

    if (!Caches::getInstance().extensions.hasNPot()) {
        width = 1 << (31 - __builtin_clz(width));
    }

    bool hasAlpha = false;
    for (int i = 0; i < count; i++) {
        if (((colors[i] >> 24) & 0xff) < 255) {
            hasAlpha = true;
+7 −9
Original line number Diff line number Diff line
@@ -69,12 +69,10 @@ const char* gVS_Header_Varyings_HasBitmap =
        "varying highp vec2 outBitmapTexCoords;\n";
const char* gVS_Header_Varyings_PointHasBitmap =
        "varying highp vec2 outPointBitmapTexCoords;\n";
// TODO: These values are used to sample from textures,
//       they may need to be highp
const char* gVS_Header_Varyings_HasGradient[6] = {
        // Linear
        "varying highp vec2 linear;\n",
        "varying highp float linear;\n",
        "varying float linear;\n",

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

        "    highp vec4 gradientColor = mix(startColor, endColor, clamp(linear, 0.0, 1.0));\n",
        "    vec4 gradientColor = mix(startColor, endColor, clamp(linear, 0.0, 1.0));\n",

        // Circular
        "    highp vec4 gradientColor = texture2D(gradientSampler, vec2(length(circular), 0.5));\n",
        "    vec4 gradientColor = texture2D(gradientSampler, vec2(length(circular), 0.5));\n",

        "    highp vec4 gradientColor = mix(startColor, endColor, clamp(length(circular), 0.0, 1.0));\n",
        "    vec4 gradientColor = mix(startColor, endColor, clamp(length(circular), 0.0, 1.0));\n",

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

        "    highp float index = atan(sweep.y, sweep.x) * 0.15915494309; // inv(2 * PI)\n"
        "    highp vec4 gradientColor = mix(startColor, endColor, clamp(index - floor(index), 0.0, 1.0));\n"
        "    vec4 gradientColor = mix(startColor, endColor, clamp(index - floor(index), 0.0, 1.0));\n"
};
const char* gFS_Main_FetchBitmap =
        "    vec4 bitmapColor = texture2D(bitmapSampler, outBitmapTexCoords);\n";
+9 −0
Original line number Diff line number Diff line
@@ -32,6 +32,15 @@

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

        <activity
                android:name="TextPathActivity"
                android:label="_TextPath">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
                android:name="GradientStopsActivity"
                android:label="_GradientStops">
+77 −0
Original line number Diff line number Diff line
/*
 * 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.android.test.hwui;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.view.View;
import android.widget.ScrollView;

@SuppressWarnings({"UnusedDeclaration"})
public class TextPathActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ScrollView scroller = new ScrollView(this);
        scroller.addView(new CustomTextView(this));
        setContentView(scroller);
    }

    static class CustomTextView extends View {
        private final Paint mHugePaint;

        CustomTextView(Context c) {
            super(c);

            mHugePaint = new Paint();
            mHugePaint.setAntiAlias(true);
            mHugePaint.setColor(0xff000000);
            mHugePaint.setTextSize(300f);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), 3000);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawRGB(255, 255, 255);

            Path path = new Path();

            canvas.translate(100.0f, 300.0f);
            drawTextAsPath(canvas, "Hello", path);

            canvas.translate(0.0f, 400.0f);
            drawTextAsPath(canvas, "OpenGL", path);
        }

        private void drawTextAsPath(Canvas canvas, String text, Path path) {
            int count = text.length();
            mHugePaint.getTextPath(text, 0, count, 0, 0, path);
            path.close();
            canvas.drawPath(path, mHugePaint);
        }
    }
}