78 Commits

Author SHA1 Message Date
Romain Guy
627c6fd913 Add overdraw debugging that accounts for Deuteranomaly
Change-Id: I31f68a07aa7cf0490d2572e24e4c5ac2066a1151
2013-08-21 11:53:18 -07:00
Chris Craik
9ab2d18475 Ensure glActiveTexture is cleaned up correctly on functor resume
Change-Id: I103d7d63b17289d599c2c08dcc442cfba9b8e51d
2013-07-22 16:21:55 -07:00
Romain Guy
31e08e953f Share Caches' index buffer with FontRenderer
This reduces state changes when we draw 9patches and text together,
which happens *a lot*. Also disable the NV profiling extension by
default since it doesn't play nice with display lists deferrals.
To enable it set debug.hwui.nv_profiling to true.

Change-Id: I518b44b7d294e5def10c78911ceb9f01ae401609
2013-06-18 15:53:53 -07:00
Romain Guy
be1b127c7b Assume a texture is unbound after deleting it
Bug #9316260

The GL specification indicates that deleting a bound texture has
the side effect of binding the default texture (name=0). This change
replaces all calls to glDeleteTextures() by Caches::deleteTexture()
to properly keep track of texture bindings.

Change-Id: Ifbc60ef433e0f9776a668dd5bd5f0adbc65a77a0
2013-06-06 16:26:51 -07:00
Romain Guy
8aa195d708 Introduce Caches::bindTexture() to reduce glBindTexture calls
Change-Id: Ic345422567c020c0a9035ff51dcf2ae2a1fc59f4
2013-06-04 18:58:36 -07:00
Romain Guy
f9f0016b1f Enable GPU pixel buffers on OpenGL ES 3.0 devices
Change-Id: I164d72ccd7a9bf6ae0e3f79dfef50083558937ba
2013-06-04 11:57:58 -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
Romain Guy
cf51a41998 Introduce PixelBuffer API to enable PBOs
PBOs (Pixel Buffer Objects) can be used on OpenGL ES 3.0 to perform
asynchronous texture uploads to free up the CPU. This change does not
enable the use of PBOs unless a specific property is set (Adreno drivers
have issues with PBOs at the moment, Mali drivers work just fine.)

This change also cleans up Font/FontRenderer a little bit and improves
performance of drop shadows generations by using memcpy() instead of
a manual byte-by-byte copy.

On GL ES 2.0 devices, or when PBOs are disabled, a PixelBuffer instance
behaves like a simple byte array. The extra APIs introduced for PBOs
(map/unmap and bind/unbind) are pretty much no-ops for CPU pixel
buffers and won't introduce any significant overhead.

This change also fixes a bug with text drop shadows: if the drop
shadow is larger than the max texture size, the renderer would leave
the GL context in a bad state and generate 0x501 errors. This change
simply skips drop shadows if they are too large.

Change-Id: I2700aadb0c6093431dc5dee3d587d689190c4e23
2013-04-11 14:07:34 -07:00
Romain Guy
c46d07a29e Merge all shapes/paths caches to PathCache
This change will greatly simplify the multi-threading of all
shape types.

This change also uses PathTessellator to render convex paths.

Change-Id: I4e65bc95c9d24ecae2183b72204de5c2dfb6ada4
2013-03-18 18:32:17 -07:00
Romain Guy
5dc7fa7096 Add TaskManager API
This API can be used to run arbitrary tasks on a pool of worker
threads. The number of threads is calculated based on the number
of CPU cores available.

The API is made of 3 classes:

TaskManager
      Creates and manages the worker threads.

Task
      Describes the work to be done and the type of the output.
      A task contains a future used to wait for the worker thread
      to be done computing the result of the task.

TaskProcessor
      The processor dispatches tasks to the TaskManager and is
      responsible for performing the computation required by
      each task. A processor will only be asked to process tasks
      sent to the manager through the processor.

A typical use case:

class MyTask: Task<MyType>

class MyProcessor: TaskProcessor<MyType>

TaskManager m = new TaskManager();
MyProcessor p = new MyProcessor(m);
MyTask t = new MyTask();
p.add(t);

// Waits until the result is available
MyType result = t->getResult();

Change-Id: I1fe845ba4c49bb0e1b0627ab147f9a861c8e0749
2013-03-12 15:06:42 -07:00
Romain Guy
0f6675332c Precache glyphs at final raster size
The deferred display lists model now allows us to precache glyphs
at their exact size on screen.

This change also removes debug markers when the renderer defers
and reorders display lists. It also adds a flush event marker.

Change-Id: I66ec5216dc12b93ecfdad52a7146b1cfb31fbeb4
2013-03-01 16:04:53 -08:00
Romain Guy
3ff0bfdd14 Add new property to debug non-rectangular clip operations
This change adds a new property called "debug.hwui.show_stencil_clip"
that accepts the following values:

- "highlight", colorizes in green any drawing command that's tested
  against a non-rectangular clip region
- "region", shows the non-rectangular clip region in blue every time
  it is used
- "hide", default value, nothing is shown

Change-Id: I83c8602310edc4aaeb8b905371cdd185b17d32b5
2013-02-25 15:01:58 -08:00
Romain Guy
ff316ec7a7 Implement support for drawBitmapMesh's colors array
Change-Id: I3d901f6267c2918771ac30ff55c8d80c3ab5b725
2013-02-13 18:39:43 -08:00
Romain Guy
8d4aeb7111 Add a render buffer cache to reuse stencil buffers
Bug #7146141

This new cache is used in a similar way to LayerCache. It helps
reuse already allocated stencil buffers and thus avoid churning
memory on every frame.

Change-Id: I19551d72da52c40039e65904563600e492c8b193
2013-02-13 11:27:05 -08:00
Romain Guy
da8d8b9699 Merge "Add a RenderBuffer object to store stencil buffers. Bug #7146141" 2013-02-07 20:11:56 +00:00
Romain Guy
3bbacf27c0 Add a RenderBuffer object to store stencil buffers.
Bug #7146141

This change is needed to add a render buffer cache to avoid
creating and destroying stencil buffers on every frame.

This change also allows the renderer to use a 1 bit or 4 bit
stencil buffer whenever possible.

Finally this change fixes a bug introduced by a previous CL
which causes the stencil buffer to not be updated in certain
conditions. The fix relies on a new optional parameter in
drawColorRects() that can be used to avoid performing a
quickReject on rectangles generated by the clip region.

Change-Id: I2f55a8e807009887b276a83cde9f53fd5c01199f
2013-02-07 12:11:22 -08:00
Chris Craik
1ba0289d18 Merge "Add cap tessellation support" 2013-02-07 00:14:38 +00:00
Chris Craik
65cd612fac Add cap tessellation support
bug:7117155
bug:8114304

Currently used for lines (with and without AA) and arcs with useCenter=false

Also removes 0.375, 0.375 offset for AA lines

Change-Id: Ic8ace418739344db1e2814edf65253fe7448b0b0
2013-02-06 15:35:12 -08:00
Romain Guy
ef35927abc Tag HardwareRenderers with a name to help debugging
The name of the renderer is the same as the window it belongs to.

Change-Id: Ie9adc0a1978afa026923ea41f5540eda6ba65a92
2013-01-31 19:07:29 -08:00
Romain Guy
f735c8e5cb Fix tiling on QCOM GPU
Rename Caches::startTiling parameter from opaque to discard to
make it clearer what its role is. Tweak calls to startTiling
to preserve the buffer when needed and discard it when possible.

Change-Id: If7f8ff19003f79f36885a0a7207cc61901f637d2
2013-01-31 17:45:55 -08:00
Romain Guy
8ce00301a0 Implement clipRect with a transform, clipRegion & clipPath
Bug #7146141

When non-rectangular clipping occurs in a layer the render buffer
used as the stencil buffer is not cached. If this happens on a
View's hardware layer the render buffer will live for as long
as the layer is bound to the view. When a stencil buffer is
required because of a call to Canvas.saveLayer() it will be allocated
on every frame. A future change will address this problem.

If "show GPU overdraw" is enabled, non-rectangular clips are not
supported anymore and we fall back to rectangular clips instead.
This is a limitation imposed by OpenGL ES that cannot be worked
around at this time.

This change also improves the Matrix4 implementation to easily
detect when a rect remains a rect after transform.

Change-Id: I0e69fb901792d38bc0c4ca1bf9fdb02d7db415b9
2013-01-17 15:39:31 -08:00
Romain Guy
5bb3c730f5 Apply dev. settings at runtime
Bug #7434649

Change-Id: I16f00eaa8a5eefd9f9849e196cf2cb1659215390
2012-11-30 16:29:33 -08:00
Romain Guy
a852ff3a4b Merge changes I9873540e,I4f6c38e3 into jb-mr1-dev
* changes:
  Skia's ColorMatrix vector is in the 0..255 range not 0..1 Bug #7248980
  Don't use the QCOM_tiled_rendering extension with functors Bug #7247880
2012-09-27 18:45:42 -07:00
Romain Guy
54c1a64d54 Don't use the QCOM_tiled_rendering extension with functors
Bug #7247880

Change-Id: I4f6c38e37b953c58e6107097c613891a49dac766
2012-09-27 17:57:24 -07:00
Chris Craik
16b897c488 Fix rectangle AA offset calculation
bug:4419017

Fixes compiler warning
Handle bezier thresholds with large stroke widths better
Fix sub-hairlines (for scaleX == scaleY)

Change-Id: Ida387483348ee61424b7fba729abca2a88bd68b3
2012-09-27 15:01:36 -07:00
Chris Craik
cb4d600957 Add stroke support to polygonal shape rendering
bug:4419017
bug:7230005

- Adds support for stroke/strokeAndFill for shapes without joins
- Fixes path-polygonization threshold calculation
- Fixes rendering offset (now only used for points)
- Several formatting fixes

Change-Id: If72473dc881e45752e2ec212d0dcd1e3f97979ea
2012-09-26 14:38:11 -07:00
Romain Guy
7c450aaa3c Add support for a new developer setting: overdraw debugging
Change-Id: I350ba4486577c3289f82c20938f7a35138778727
2012-09-21 19:15:00 -07:00
Romain Guy
85ef80d890 Foundation for tiling optimization
Change-Id: I4db32a4749f196472ba0dde7e102439d2ba4a3a7
2012-09-13 20:26:50 -07:00
Chris Craik
378d131e65 Merge "Varying-based AA rect drawing" into jb-mr1-dev 2012-09-06 10:52:14 -07:00
Chris Craik
6ebdc114e0 Varying-based AA rect drawing
Instead of calculating opacity from relative position in the shader, use a
shader varying to do this computation for us.

bug:5045101

Also adds a test to HwAccelerationTest to show incorrect antialiasing in
scaled drawAARect / boundarySize calculation.

Change-Id: Icdc41acb01dc10ce354834f8389a5aed2f439162
2012-09-05 16:45:03 -07:00
Romain Guy
0baaac5e9a Revert "Revert "Add more support for transformed clip rects and paths""
This reverts commit a8557d2169e14997637f57bc897640c8882d4a46.

Change-Id: I36d4883d548fc47ba6c0b4a42012107d0d2f85a6
2012-08-31 20:31:32 -07:00
Mathias Agopian
a8557d2169 Revert "Add more support for transformed clip rects and paths"
this introduced a dead lock in GradientCache's ctor.

This reverts commit dfe082f63e94cde9aee271c94d13de5e7217e036.

Bug: 7096001
Change-Id: I57b8bbab11fb7cb502fa58e3bbf5d19864db874f
2012-08-31 20:04:18 -07:00
Romain Guy
dfe082f63e Add more support for transformed clip rects and paths
Change-Id: I41791b1e1bffef77d503dc9e52428395d2309688
2012-08-31 17:17:40 -07:00
Romain Guy
4ff0cf4b83 Add new debug tool to track hardware layers updates
You can setprop debug.hwui.show_layers_updates true to flash
hw layers in green when they update. This is also a setting
in the Dev. section of the settings app.

Change-Id: Ibe1d63a4f81567dc1d590c9b088d2e7505df8abf
2012-08-06 14:51:10 -07:00
Romain Guy
211efea737 Add dithering to gradients
Change-Id: Ic1208855bde3a254eca2fd7cef43e0f1318ce419
2012-08-01 19:18:35 -07:00
Romain Guy
8a4ac610e1 Don't clear the dirty clip flag if it's not applied
Bug #6833979

Change-Id: I0ea78b7f31a557a335de10d910d03b0520029080
2012-07-17 17:32:48 -07:00
Romain Guy
b1d0a4ed21 Refactor GammaFontRenderer
This change is the first step to a shader-based text antialias
gamma correction.

Change-Id: I9eb02d4c56cb95d05219f712290c865b46141954
2012-07-13 18:25:35 -07:00
Romain Guy
586cae3ac6 Improve rendering speed by disabling scissor tests
This change improves execution of display lists, particularly on
tiled renderers. The goal is to disable the scissor test as
often as possible. Drawing commands are rarely clipped by View
bounds so most of them can be drawn without doing a scissor test.

The speed improvements scale with the number of views and drawing
commands.

Change-Id: Ibd9b5e051a3e4300562463805acc4fd744ba6266
2012-07-13 15:28:31 -07:00
Romain Guy
dfa1046eca Add call sites for OpenGL's debug label extension
Change-Id: I9c689127e8166cbef92c935f8aa07217ab806dda
2012-05-12 16:22:35 -07:00
Romain Guy
bb0acdf9e1 Delete display list objects and resources on the UI thread
Bug #6073717
Bug #6065504
Bug #6026515
Bug #5971725

Prior to this patch, the destructor of DisplayList would always run
on the finalizer thread. This could cause a race condition if the UI
thread was busy rendering display lists at the same time leading to
various random native crashes.

Change-Id: Ie11108e3b1538d4b358a1a8b4cce1b2d33152d0c
2012-03-05 13:44:35 -08:00
Romain Guy
13631f3da8 Add debug markers to OpenGLRenderer
These markers will be used to group the GL commands by View in the
OpenGL ES debugging tool. This will help correlate individual GL
calls to higher level components like Views.

Change-Id: I73607ba2e7224a80ac32527968261ee008f049c6
2012-01-30 17:41:55 -08:00
Romain Guy
82bc7a7727 Properly restore the GL scissor after a GL draw functor
Bug #5781254

Change-Id: I1dc4809563a793b6b579814951d4d73b4c34bf32
2012-01-03 14:14:55 -08:00
Romain Guy
8f85e80b64 Generate even fewer GL commands
Change-Id: I0f4dcacb03ef5ee7f6ebd501df98bfead5f0a7f8
2011-12-14 19:23:32 -08:00
Romain Guy
a1d3c91afb Further reduce the number of GL commands sent to the driver
Change-Id: Id922b2a166ea4573b767c27d3195e11c70320b23
2011-12-13 14:58:14 -08:00
Romain Guy
15bc6437f8 Reduce the number of GL commands generated by the UI
This optimization along with the previous one lets us render an
application like Gmail using only 30% of the number of GL commands
previously required

Change-Id: Ifee63edaf495e04490b5abd5433bb9a07bc327a8
2011-12-13 13:11:32 -08:00
Romain Guy
f3a910b423 Optimize state changes
Change-Id: Iae59bc8dfd6427d0967472462cc1994987092827
2011-12-12 20:35:21 -08:00
Romain Guy
8ff6b9ebee Terminate EGL when an app goes in the background
This does not happen on high end gfx devices. This happens
only if only one EGL context is initialized in the current
process.

Change-Id: Ibd1737efdf84eef8a84108b05795440d1ae9964e
2011-11-10 16:44:49 -08:00
Romain Guy
7953745dd5 Reduce the size of libhwui by 50%
This change removes unnessary symbols. All symbols are hidden by
default, public APIs with exported symbols are explicitly marked
with ANDROID_API.

Change-Id: I692fde432a86c12108de1cfd1f6504919a7d5f3f
2011-10-12 13:48:51 -07:00
Romain Guy
6d7475d666 Destroy layers and flush layers cache when a window is destroyed.
Change-Id: I3fa1bc3ff50fb99e3d2e490925bd6b0a0f809fff
2011-07-27 16:29:39 -07:00
Romain Guy
bdf7609867 Trim OpenGLRenderer's memory usage whenever possible
Change-Id: I9225077184f374b1a43300add15cc1d5b6869d1c
2011-07-18 15:00:43 -07:00