29 Commits

Author SHA1 Message Date
Romain Guy
4c2547fa92 Avoid 9patch cache lookups when possible
This optimization saves up to 0.3ms per frame on the Play Store's
front page, on a Nexus 4 device.

Change-Id: Iaa4ef33c6e3b37e175efd5b9eea9ef59b43f14f3
2013-06-11 17:14:59 -07:00
Romain Guy
3b748a44c6 Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.

This CL introduces an asset server that provides an atlas to all processes.

Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.

WHAT IS THE ASSETS ATLAS

The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)

HOW IS THE ASSETS ATLAS GENERATED

Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.

There are several steps that lead to the atlas generation:

1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas

2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.

3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.

HOW PROCESSES USE THE ATLAS

Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.

It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)

Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.

Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-05-02 13:32:09 -07:00
Chris Craik
62a42c13a6 Adjust offset for non-AA line drawing
bug:8114304

The original .375 was chosen to make GL_LINES align with Skia drawing.
The new value of .065 is chosen to be as small as possible to make
triangle-based lines align with Skia, while keeping lines drawn on
integer coordinates unambiguous as to which column/row they draw on.

Also adds more lines in CanvasCompare test to highlight the difference

Change-Id: If578684f2db320682219c3caa625cf79bc62d88f
2013-02-15 14:53:12 -08:00
Romain Guy
39284b763a Make gradients beautiful again
Bug #7239634

This change passes two matrices to the vertex shader instead of one.
We used to compute the final MVP matrix on the CPU to minimize the
number of operations in the vertex shaders. Shader compilers are
however smart enough to perform this optimization for us. Since we
need the MV matrix to properly compute gradients dithering, this
change splits the MVP matrix into two. This has the advantage of
removing one matrix multiplication per drawing operation on the
CPU.
The SGX 540 shader compiler produces the same number of instructions
in both cases. There is no penalty hit with having two matrices
instead of one. We also send so few vertices per frame that it
does not matter very much.

Change-Id: I17d47ac4772615418e0e1885b97493d31435a936
2012-09-26 16:39:40 -07:00
Chet Haase
0990ffbc4d Fix GL shader bugs
Fixing errors in emitted shader code that caused GL errors
at runtime

Change-Id: I267a84398a81329a6688b292505f8779bd750ad1
2012-09-18 14:10:10 -07:00
Steve Block
3762c31172 Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF) DO NOT MERGE
See https://android-git.corp.google.com/g/#/c/157220

Bug: 5449033
Change-Id: Ic9c19d30693bd56755f55906127cd6bd7126096c
2012-01-08 13:19:13 +00:00
Romain Guy
2d4fd36484 Reduce the number of active texture changes
Change-Id: I94046bdfe20740c26c8183822e3002d692fde7c4
2011-12-13 22:00:19 -08:00
Romain Guy
f3a910b423 Optimize state changes
Change-Id: Iae59bc8dfd6427d0967472462cc1994987092827
2011-12-12 20:35:21 -08:00
Romain Guy
f44e66fcf7 Remove leftover debugging code
Change-Id: I1589af7991da36744071d5081daa24ebae5b4dfd
2011-12-12 16:50:13 -08:00
Romain Guy
3e263fac8c Keep shaders to render properly
I don't know who's to blame, SGX or Tegra2 but one of those two GPUs is not
following the OpenGL ES 2.0 spec.

Change-Id: I2624e0efbc9c57d571c55c8b440a5e43f08a54f2
2011-12-12 16:47:48 -08:00
Romain Guy
6752d0ab02 Mark color uniform fetched after fetching it
Change-Id: I10e8027018608070a536eb8b51c7a4272e37006c
2011-12-12 12:15:17 -08:00
Romain Guy
24edca8b52 Code cleanup
Change-Id: If92e3addfc4d8546a60edcdea60a1fc89c27b680
2011-12-09 13:08:06 -08:00
Romain Guy
05bbde70fd Free up resources by deleting shaders early on
Change-Id: I29a39775732c0a48d3e6823f7afa3e741cae8541
2011-12-09 12:55:37 -08:00
Chet Haase
8a5cc92a15 Fix various hw-accelerated line/point bugs
All accelerated lines are now rendered as quads. Hairlines used to
be rendered as GL_LINES, but these lines don't render the same as our
non-accelerated lines, so we're using quads for everything. Also, fixed
a bug in the way that we were offsetting quads (and not offseting points)
to ensure that our lines/points actuall start on the same pixels as
Skia's.

Change-Id: I51b923cc08a9858444c430ba07bc8aa0c83cbe6a
2011-04-27 14:23:29 -07:00
Romain Guy
67f27952c1 Correctly release the OpenGL Canvas on EGL error.
Change-Id: Ib31fd8445f7ce5f7aa7e0205de0e7db80d024fc2
2010-12-07 20:12:50 -08:00
Romain Guy
5b3b35296e Optimize FBO drawing with regions.
This optimization is currently disabled until Launcher is
modified to take advantage of it. The optimization can be
enabled by turning on RENDER_LAYERS_AS_REGIONS in the
OpenGLRenderer.h file.

Change-Id: I2fdf59d0f4dc690a3d7f712173ab8db3848b27b1
2010-11-02 16:17:23 -07:00
Romain Guy
707b2f78cc Optimize GLSL shaders.
Change-Id: I9a5e01bced63d8da0c61330a543a2b805388a59d
2010-10-11 16:34:59 -07:00
Romain Guy
31529ff791 Correctly free memory.
Change-Id: I08fcbfa7d27ae413e0a8e8ca6ea305c8530a72c1
2010-09-17 10:26:31 -07:00
Romain Guy
98173a277f Delete shaders after a compile error. Also disable extra logging.
Change-Id: I9b1558b0feac3d9b2cca926feeaf73921664cc73
2010-08-11 16:40:25 -07:00
Romain Guy
889f8d1403 Moved all the rendering code to the new shader generator.
The generator supports features that are not yet implement in the
renderer: color matrix, lighting, porterduff color blending and
composite shaders.

This change also adds support for repeated/mirrored non-power of 2
bitmap shaders.

Change-Id: I903a11a070c0eb9cc8850a60ef305751e5b47234
2010-07-29 14:37:42 -07:00
Romain Guy
ac670c0433 Generate shaders to cover all possible cases.
With this change, all the vertex and fragment shaders used by the GL
renderer are now generated based on a program description supplied
by the caller. This allows the renderer to generate a large number
of shaders without having to write all the possible combinations by
hand. The generated shaders are stored in a program cache.

Change-Id: If54d286e77ae021c724d42090da476df12a18ebb
2010-07-27 19:52:29 -07:00
Romain Guy
694b519ac6 Add text rendering.
Change-Id: Ibe5a9fa844d531b31b55e43de403a98d49f659b9
2010-07-21 21:33:20 -07:00
Romain Guy
c0ac193b94 Add support for linear gradients.
Change-Id: Id15329da065045b3f06fdaed615f33cd57608496
2010-07-19 18:44:05 -07:00
Romain Guy
f9764a4f53 Add program for linear gradient.
This change adds a new DrawLinearGradientProgram class to enable the drawing
of linear gradients. Two new vertex and fragment shaders are introduced,
based on DrawTextureProgram's shaders.

Change-Id: I885afc076bb6cef8cd3962ae21a086fa6a03bf96
2010-07-16 23:18:27 -07:00
Romain Guy
6926c72e25 Correctly support pre-multiplied alpha, optimizations, more stuff.
Add support for the following drawing functions:
- drawBitmap(int[]...)
- drawPaint()

Optimizes shader state changes by enabling/disabling attribute arrays
only when needed.

Adds quick rejects when drawing trivial shapes to avoid unnecessary
OpenGL operations.

Change-Id: Ic2c6c2ed1523d08a63a8c95601a1ec40b6c7fbc9
2010-07-12 20:20:03 -07:00
Romain Guy
260e102162 Optimize shader binding changes.
This change also cleans up the internal API a little bit by using mat4
everywhere instead of float[16] (for the ortho matrix for instance.)

Change-Id: I35924c7dc17bad17f30307118d5ed437c2ed37e0
2010-07-12 14:43:40 -07:00
Romain Guy
0b9db91c3d Remove math from the vertex shader.
Change-Id: I02847a60a8734bf8b3d29ec12e76297795095e38
2010-07-09 18:53:25 -07:00
Romain Guy
16202fc974 Fix alpha blending and improve fragment shaders performance.
Change-Id: Ib74f6941d25ca6f6a41708e541174eaa7e8d9bc2
2010-07-09 16:13:28 -07:00
Romain Guy
5cbbce5357 Reduced the complexity of layers composition.
This change also refactors the code base a bit by moving classes out of
OpenGLRenderer into separate headers/implementations. This makes the code
more manageable.

This change also adds documentation for implementation methods. The
undocumented methods are simply Skia's Canvas methods.

Change-Id: I54c68b443580a0129251dddc1a7ac95813d5289e
2010-06-27 22:59:20 -07:00