2010-09-26 18:40:37 -07:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#ifndef ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
|
|
|
|
#define ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
|
2010-09-26 18:40:37 -07:00
|
|
|
|
|
|
|
#include <SkMatrix.h>
|
|
|
|
#include <SkPaint.h>
|
|
|
|
#include <SkPath.h>
|
2011-10-12 13:48:51 -07:00
|
|
|
#include <cutils/compiler.h>
|
|
|
|
|
2013-02-14 15:36:01 -08:00
|
|
|
#include "DisplayList.h"
|
2011-03-24 10:51:31 -07:00
|
|
|
#include "DisplayListLogBuffer.h"
|
2010-09-26 18:40:37 -07:00
|
|
|
#include "OpenGLRenderer.h"
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Defines
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-07-27 16:28:21 -07:00
|
|
|
#define MIN_WRITER_SIZE 4096
|
2012-02-16 19:24:51 -08:00
|
|
|
#define OP_MAY_BE_SKIPPED_MASK 0xff000000
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2011-01-13 17:21:49 -08:00
|
|
|
// Debug
|
|
|
|
#if DEBUG_DISPLAY_LIST
|
2011-12-20 16:23:08 +00:00
|
|
|
#define DISPLAY_LIST_LOGD(...) ALOGD(__VA_ARGS__)
|
2011-01-13 17:21:49 -08:00
|
|
|
#else
|
|
|
|
#define DISPLAY_LIST_LOGD(...)
|
|
|
|
#endif
|
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2010-09-28 19:09:36 -07:00
|
|
|
// Display list
|
2010-09-26 18:40:37 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-02-04 16:16:33 -08:00
|
|
|
class DeferredDisplayList;
|
2010-09-28 19:09:36 -07:00
|
|
|
class DisplayListRenderer;
|
2012-11-26 18:30:17 -08:00
|
|
|
class DisplayListOp;
|
|
|
|
class DrawOp;
|
|
|
|
class StateOp;
|
|
|
|
|
2010-09-28 19:09:36 -07:00
|
|
|
/**
|
|
|
|
* Records drawing commands in a display list for latter playback.
|
|
|
|
*/
|
|
|
|
class DisplayListRenderer: public OpenGLRenderer {
|
|
|
|
public:
|
2011-10-12 13:48:51 -07:00
|
|
|
ANDROID_API DisplayListRenderer();
|
|
|
|
virtual ~DisplayListRenderer();
|
2010-09-28 19:09:36 -07:00
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
ANDROID_API DisplayList* getDisplayList(DisplayList* displayList);
|
2011-01-05 18:01:22 -08:00
|
|
|
|
2012-05-15 11:10:01 -07:00
|
|
|
virtual bool isDeferred();
|
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
virtual void setViewport(int width, int height);
|
2012-10-18 15:05:02 -07:00
|
|
|
virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque);
|
2011-10-12 13:48:51 -07:00
|
|
|
virtual void finish();
|
2010-09-28 19:09:36 -07:00
|
|
|
|
2012-03-26 16:45:05 -07:00
|
|
|
virtual status_t callDrawGLFunction(Functor *functor, Rect& dirty);
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
virtual void interrupt();
|
|
|
|
virtual void resume();
|
2011-01-10 14:10:36 -08:00
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
virtual int save(int flags);
|
|
|
|
virtual void restore();
|
|
|
|
virtual void restoreToCount(int saveCount);
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
virtual int saveLayer(float left, float top, float right, float bottom,
|
2013-03-08 13:12:16 -08:00
|
|
|
int alpha, SkXfermode::Mode mode, int flags);
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
virtual void translate(float dx, float dy);
|
|
|
|
virtual void rotate(float degrees);
|
|
|
|
virtual void scale(float sx, float sy);
|
|
|
|
virtual void skew(float sx, float sy);
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
virtual void setMatrix(SkMatrix* matrix);
|
|
|
|
virtual void concatMatrix(SkMatrix* matrix);
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
|
2012-12-03 12:34:51 -08:00
|
|
|
virtual bool clipPath(SkPath* path, SkRegion::Op op);
|
|
|
|
virtual bool clipRegion(SkRegion* region, SkRegion::Op op);
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2013-02-04 16:16:33 -08:00
|
|
|
virtual status_t drawDisplayList(DisplayList* displayList, Rect& dirty, int32_t flags);
|
2013-03-15 17:24:33 -07:00
|
|
|
virtual status_t drawLayer(Layer* layer, float x, float y);
|
2012-05-31 15:21:51 -07:00
|
|
|
virtual status_t drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
|
|
|
|
virtual status_t drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
|
|
|
|
virtual status_t drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
|
2010-09-26 18:40:37 -07:00
|
|
|
float srcRight, float srcBottom, float dstLeft, float dstTop,
|
2010-10-08 08:37:55 -07:00
|
|
|
float dstRight, float dstBottom, SkPaint* paint);
|
2012-05-31 15:21:51 -07:00
|
|
|
virtual status_t drawBitmapData(SkBitmap* bitmap, float left, float top, SkPaint* paint);
|
|
|
|
virtual status_t drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
|
2011-01-20 19:09:30 -08:00
|
|
|
float* vertices, int* colors, SkPaint* paint);
|
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-04-17 18:54:38 -07:00
|
|
|
virtual status_t drawPatch(SkBitmap* bitmap, Res_png_9patch* patch,
|
2010-10-08 08:37:55 -07:00
|
|
|
float left, float top, float right, float bottom, SkPaint* paint);
|
2012-05-31 15:21:51 -07:00
|
|
|
virtual status_t drawColor(int color, SkXfermode::Mode mode);
|
|
|
|
virtual status_t drawRect(float left, float top, float right, float bottom, SkPaint* paint);
|
|
|
|
virtual status_t drawRoundRect(float left, float top, float right, float bottom,
|
2011-01-19 21:54:02 -08:00
|
|
|
float rx, float ry, SkPaint* paint);
|
2012-05-31 15:21:51 -07:00
|
|
|
virtual status_t drawCircle(float x, float y, float radius, SkPaint* paint);
|
|
|
|
virtual status_t drawOval(float left, float top, float right, float bottom, SkPaint* paint);
|
|
|
|
virtual status_t drawArc(float left, float top, float right, float bottom,
|
2011-01-23 16:15:02 -08:00
|
|
|
float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
|
2012-05-31 15:21:51 -07:00
|
|
|
virtual status_t drawPath(SkPath* path, SkPaint* paint);
|
|
|
|
virtual status_t drawLines(float* points, int count, SkPaint* paint);
|
|
|
|
virtual status_t drawPoints(float* points, int count, SkPaint* paint);
|
|
|
|
virtual status_t drawTextOnPath(const char* text, int bytesCount, int count, SkPath* path,
|
2012-02-24 16:48:34 -08:00
|
|
|
float hOffset, float vOffset, SkPaint* paint);
|
2012-05-31 15:21:51 -07:00
|
|
|
virtual status_t drawPosText(const char* text, int bytesCount, int count,
|
|
|
|
const float* positions, SkPaint* paint);
|
2013-03-04 10:19:31 -08:00
|
|
|
virtual status_t drawText(const char* text, int bytesCount, int count, float x, float y,
|
2013-05-03 16:35:54 -07:00
|
|
|
const float* positions, SkPaint* paint, float totalAdvance, const Rect& bounds,
|
|
|
|
DrawOpMode drawOpMode);
|
2013-03-04 10:19:31 -08:00
|
|
|
|
2013-01-04 19:05:13 -08:00
|
|
|
virtual status_t drawRects(const float* rects, int count, SkPaint* paint);
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
virtual void resetShader();
|
|
|
|
virtual void setupShader(SkiaShader* shader);
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
virtual void resetColorFilter();
|
|
|
|
virtual void setupColorFilter(SkiaColorFilter* filter);
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
virtual void resetShadow();
|
|
|
|
virtual void setupShadow(float radius, float dx, float dy, int color);
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2012-01-23 17:09:05 -08:00
|
|
|
virtual void resetPaintFilter();
|
|
|
|
virtual void setupPaintFilter(int clearBits, int setBits);
|
|
|
|
|
2011-10-12 13:48:51 -07:00
|
|
|
ANDROID_API void reset();
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
sp<DisplayListData> getDisplayListData() const {
|
|
|
|
return mDisplayListData;
|
2010-09-28 19:09:36 -07:00
|
|
|
}
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
const Vector<SkBitmap*>& getBitmapResources() const {
|
|
|
|
return mBitmapResources;
|
2010-09-28 19:09:36 -07:00
|
|
|
}
|
|
|
|
|
2012-05-15 11:10:01 -07:00
|
|
|
const Vector<SkBitmap*>& getOwnedBitmapResources() const {
|
|
|
|
return mOwnedBitmapResources;
|
|
|
|
}
|
|
|
|
|
2011-06-22 16:14:36 -07:00
|
|
|
const Vector<SkiaColorFilter*>& getFilterResources() const {
|
|
|
|
return mFilterResources;
|
|
|
|
}
|
|
|
|
|
2013-06-26 15:45:41 -07:00
|
|
|
const Vector<Res_png_9patch*>& getPatchResources() const {
|
|
|
|
return mPatchResources;
|
|
|
|
}
|
|
|
|
|
2011-01-14 15:31:00 -08:00
|
|
|
const Vector<SkiaShader*>& getShaders() const {
|
|
|
|
return mShaders;
|
2010-09-28 19:09:36 -07:00
|
|
|
}
|
|
|
|
|
2010-10-25 15:47:32 -07:00
|
|
|
const Vector<SkPaint*>& getPaints() const {
|
|
|
|
return mPaints;
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
|
|
|
|
2011-02-03 15:06:05 -08:00
|
|
|
const Vector<SkPath*>& getPaths() const {
|
|
|
|
return mPaths;
|
|
|
|
}
|
|
|
|
|
2012-05-02 18:50:34 -07:00
|
|
|
const SortedVector<SkPath*>& getSourcePaths() const {
|
|
|
|
return mSourcePaths;
|
|
|
|
}
|
|
|
|
|
2012-12-03 12:34:51 -08:00
|
|
|
const Vector<SkRegion*>& getRegions() const {
|
|
|
|
return mRegions;
|
|
|
|
}
|
|
|
|
|
Fix occasional crash bug with layers
Launcher occasionally crashes with a stack trace indicating that the memory
of a Layer object is corrupt. It is possible for us to delete a Layer
structure and then, briefly, use it to draw a DisplayList again before
that DisplayList gets recreated (without the layer that got deleted).
When this happens, if the memory got corrupted, it's possible to crash.
The fix is to add Layer to the other objects which we currently refcount
(bitmaps, shaders, etc.). Then instead of deleting a Layer, we decrement the
refcount. We increment when creating it, then increment it again when it's
referenced from a DisplayList. Then we decrement the refcount instead of
deleting it, and decrement when we clear a DisplayList that refers to it.
Then when the refcount reaches 0, we delete it.
Issue #6994632 Native crash in launcher when trying to launch all apps screen
Change-Id: I0627be8d49bb2f9ba8d158a84b764bb4e7df934c
2012-09-14 15:31:25 -07:00
|
|
|
const Vector<Layer*>& getLayers() const {
|
|
|
|
return mLayers;
|
|
|
|
}
|
|
|
|
|
2010-10-25 15:47:32 -07:00
|
|
|
const Vector<SkMatrix*>& getMatrices() const {
|
|
|
|
return mMatrices;
|
2010-09-28 19:09:36 -07:00
|
|
|
}
|
|
|
|
|
2012-09-27 17:55:46 -07:00
|
|
|
uint32_t getFunctorCount() const {
|
|
|
|
return mFunctorCount;
|
|
|
|
}
|
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
private:
|
2012-11-26 18:30:17 -08:00
|
|
|
void insertRestoreToCount();
|
|
|
|
void insertTranslate();
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
LinearAllocator& alloc() { return mDisplayListData->allocator; }
|
|
|
|
void addStateOp(StateOp* op);
|
2013-03-01 14:31:04 -08:00
|
|
|
void addDrawOp(DrawOp* op);
|
2012-11-26 18:30:17 -08:00
|
|
|
void addOpInternal(DisplayListOp* op) {
|
2012-02-16 19:24:51 -08:00
|
|
|
insertRestoreToCount();
|
2012-11-26 18:30:17 -08:00
|
|
|
insertTranslate();
|
|
|
|
mDisplayListData->displayListOps.add(op);
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
template<class T>
|
|
|
|
inline T* refBuffer(const T* srcBuffer, int32_t count) {
|
|
|
|
if (srcBuffer == NULL) return NULL;
|
|
|
|
T* dstBuffer = (T*) mDisplayListData->allocator.alloc(count * sizeof(T));
|
|
|
|
memcpy(dstBuffer, srcBuffer, count * sizeof(T));
|
|
|
|
return dstBuffer;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
inline char* refText(const char* text, size_t byteLength) {
|
|
|
|
return (char*) refBuffer<uint8_t>((uint8_t*)text, byteLength);
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
inline SkPath* refPath(SkPath* path) {
|
|
|
|
if (!path) return NULL;
|
2011-02-03 15:06:05 -08:00
|
|
|
|
|
|
|
SkPath* pathCopy = mPathMap.valueFor(path);
|
|
|
|
if (pathCopy == NULL || pathCopy->getGenerationID() != path->getGenerationID()) {
|
2011-03-18 16:24:19 -07:00
|
|
|
pathCopy = new SkPath(*path);
|
2012-02-23 17:08:38 -08:00
|
|
|
pathCopy->setSourcePath(path);
|
2012-02-21 18:32:32 -08:00
|
|
|
// replaceValueFor() performs an add if the entry doesn't exist
|
|
|
|
mPathMap.replaceValueFor(path, pathCopy);
|
2011-03-18 16:24:19 -07:00
|
|
|
mPaths.add(pathCopy);
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
2012-05-02 18:50:34 -07:00
|
|
|
if (mSourcePaths.indexOf(path) < 0) {
|
2012-09-07 11:58:36 -07:00
|
|
|
mCaches.resourceCache.incrementRefcount(path);
|
2012-05-02 18:50:34 -07:00
|
|
|
mSourcePaths.add(path);
|
|
|
|
}
|
2012-11-26 18:30:17 -08:00
|
|
|
return pathCopy;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
inline SkPaint* refPaint(SkPaint* paint) {
|
2011-01-14 15:31:00 -08:00
|
|
|
if (!paint) {
|
Optimize interactions with glyph cache
There are two fixes here:
- precaching: instead of caching-then-drawing whenever there is a new
glyph, we cache at DisplayList record time. Then when we finally draw that
DisplayList, we just upload the affected texture(s) once, instead of once
per change. This is a huge savings in upload time, especially when there are
larger glyphs being used by the app.
- packing: Previously, glyphs would line up horizontally on each cache line, leaving
potentially tons of space vertically, especially when smaller glyphs got put into cache
lines intended for large glyphs (which can happen when an app uses lots of unique
glyphs, a common case with, for example, chinese/japanese/korean languages). The new
approach packs glyphs vertically as well as horizontally to use the space more efficiently
and provide space for more glyphs in these situations.
Change-Id: I84338aa25db208c7bf13f3f92b4d05ed40c33527
2012-08-09 13:39:02 -07:00
|
|
|
return paint;
|
2010-10-25 15:47:32 -07:00
|
|
|
}
|
2010-11-08 12:08:41 -08:00
|
|
|
|
2012-01-19 18:33:25 -08:00
|
|
|
SkPaint* paintCopy = mPaintMap.valueFor(paint);
|
2010-10-25 15:47:32 -07:00
|
|
|
if (paintCopy == NULL || paintCopy->getGenerationID() != paint->getGenerationID()) {
|
|
|
|
paintCopy = new SkPaint(*paint);
|
2012-02-21 18:32:32 -08:00
|
|
|
// replaceValueFor() performs an add if the entry doesn't exist
|
|
|
|
mPaintMap.replaceValueFor(paint, paintCopy);
|
2010-10-25 15:47:32 -07:00
|
|
|
mPaints.add(paintCopy);
|
|
|
|
}
|
2010-11-08 12:08:41 -08:00
|
|
|
|
Optimize interactions with glyph cache
There are two fixes here:
- precaching: instead of caching-then-drawing whenever there is a new
glyph, we cache at DisplayList record time. Then when we finally draw that
DisplayList, we just upload the affected texture(s) once, instead of once
per change. This is a huge savings in upload time, especially when there are
larger glyphs being used by the app.
- packing: Previously, glyphs would line up horizontally on each cache line, leaving
potentially tons of space vertically, especially when smaller glyphs got put into cache
lines intended for large glyphs (which can happen when an app uses lots of unique
glyphs, a common case with, for example, chinese/japanese/korean languages). The new
approach packs glyphs vertically as well as horizontally to use the space more efficiently
and provide space for more glyphs in these situations.
Change-Id: I84338aa25db208c7bf13f3f92b4d05ed40c33527
2012-08-09 13:39:02 -07:00
|
|
|
return paintCopy;
|
2010-11-08 12:08:41 -08:00
|
|
|
}
|
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
inline SkRegion* refRegion(SkRegion* region) {
|
2012-12-03 12:34:51 -08:00
|
|
|
if (!region) {
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkRegion* regionCopy = mRegionMap.valueFor(region);
|
|
|
|
// TODO: Add generation ID to SkRegion
|
|
|
|
if (regionCopy == NULL) {
|
|
|
|
regionCopy = new SkRegion(*region);
|
|
|
|
// replaceValueFor() performs an add if the entry doesn't exist
|
|
|
|
mRegionMap.replaceValueFor(region, regionCopy);
|
|
|
|
mRegions.add(regionCopy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return regionCopy;
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
inline SkMatrix* refMatrix(SkMatrix* matrix) {
|
2013-07-16 13:47:01 -07:00
|
|
|
if (matrix) {
|
|
|
|
// Copying the matrix is cheap and prevents against the user changing
|
|
|
|
// the original matrix before the operation that uses it
|
|
|
|
SkMatrix* copy = new SkMatrix(*matrix);
|
|
|
|
mMatrices.add(copy);
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
return matrix;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2013-03-28 11:32:33 -07:00
|
|
|
inline Layer* refLayer(Layer* layer) {
|
|
|
|
mLayers.add(layer);
|
|
|
|
mCaches.resourceCache.incrementRefcount(layer);
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
inline SkBitmap* refBitmap(SkBitmap* bitmap) {
|
2010-10-25 15:47:32 -07:00
|
|
|
// Note that this assumes the bitmap is immutable. There are cases this won't handle
|
|
|
|
// correctly, such as creating the bitmap from scratch, drawing with it, changing its
|
|
|
|
// contents, and drawing again. The only fix would be to always copy it the first time,
|
|
|
|
// which doesn't seem worth the extra cycles for this unlikely case.
|
2010-10-08 08:37:55 -07:00
|
|
|
mBitmapResources.add(bitmap);
|
2012-09-07 11:58:36 -07:00
|
|
|
mCaches.resourceCache.incrementRefcount(bitmap);
|
2012-11-26 18:30:17 -08:00
|
|
|
return bitmap;
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
inline SkBitmap* refBitmapData(SkBitmap* bitmap) {
|
2012-05-15 11:10:01 -07:00
|
|
|
mOwnedBitmapResources.add(bitmap);
|
2012-09-07 11:58:36 -07:00
|
|
|
mCaches.resourceCache.incrementRefcount(bitmap);
|
2012-11-26 18:30:17 -08:00
|
|
|
return bitmap;
|
2012-05-15 11:10:01 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
inline SkiaShader* refShader(SkiaShader* shader) {
|
|
|
|
if (!shader) return NULL;
|
2011-01-14 15:31:00 -08:00
|
|
|
|
|
|
|
SkiaShader* shaderCopy = mShaderMap.valueFor(shader);
|
|
|
|
// TODO: We also need to handle generation ID changes in compose shaders
|
2011-01-14 15:37:54 -08:00
|
|
|
if (shaderCopy == NULL || shaderCopy->getGenerationId() != shader->getGenerationId()) {
|
2011-01-14 15:31:00 -08:00
|
|
|
shaderCopy = shader->copy();
|
2012-02-21 18:32:32 -08:00
|
|
|
// replaceValueFor() performs an add if the entry doesn't exist
|
|
|
|
mShaderMap.replaceValueFor(shader, shaderCopy);
|
2011-01-14 15:37:54 -08:00
|
|
|
mShaders.add(shaderCopy);
|
2012-09-07 11:58:36 -07:00
|
|
|
mCaches.resourceCache.incrementRefcount(shaderCopy);
|
2011-01-14 15:31:00 -08:00
|
|
|
}
|
2012-11-26 18:30:17 -08:00
|
|
|
return shaderCopy;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
inline SkiaColorFilter* refColorFilter(SkiaColorFilter* colorFilter) {
|
2010-10-22 16:17:12 -07:00
|
|
|
mFilterResources.add(colorFilter);
|
2012-09-07 11:58:36 -07:00
|
|
|
mCaches.resourceCache.incrementRefcount(colorFilter);
|
2012-11-26 18:30:17 -08:00
|
|
|
return colorFilter;
|
2010-10-22 16:17:12 -07:00
|
|
|
}
|
|
|
|
|
2013-06-26 15:45:41 -07:00
|
|
|
inline Res_png_9patch* refPatch(Res_png_9patch* patch) {
|
|
|
|
mPatchResources.add(patch);
|
|
|
|
mCaches.resourceCache.incrementRefcount(patch);
|
|
|
|
return patch;
|
|
|
|
}
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
Vector<SkBitmap*> mBitmapResources;
|
2012-05-15 11:10:01 -07:00
|
|
|
Vector<SkBitmap*> mOwnedBitmapResources;
|
2010-10-22 16:17:12 -07:00
|
|
|
Vector<SkiaColorFilter*> mFilterResources;
|
2013-06-26 15:45:41 -07:00
|
|
|
Vector<Res_png_9patch*> mPatchResources;
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2010-10-25 15:47:32 -07:00
|
|
|
Vector<SkPaint*> mPaints;
|
2010-11-08 12:08:41 -08:00
|
|
|
DefaultKeyedVector<SkPaint*, SkPaint*> mPaintMap;
|
2011-01-14 15:31:00 -08:00
|
|
|
|
2011-02-03 15:06:05 -08:00
|
|
|
Vector<SkPath*> mPaths;
|
|
|
|
DefaultKeyedVector<SkPath*, SkPath*> mPathMap;
|
|
|
|
|
2012-05-02 18:50:34 -07:00
|
|
|
SortedVector<SkPath*> mSourcePaths;
|
|
|
|
|
2012-12-03 12:34:51 -08:00
|
|
|
Vector<SkRegion*> mRegions;
|
|
|
|
DefaultKeyedVector<SkRegion*, SkRegion*> mRegionMap;
|
|
|
|
|
2011-01-14 15:31:00 -08:00
|
|
|
Vector<SkiaShader*> mShaders;
|
|
|
|
DefaultKeyedVector<SkiaShader*, SkiaShader*> mShaderMap;
|
|
|
|
|
2010-10-25 15:47:32 -07:00
|
|
|
Vector<SkMatrix*> mMatrices;
|
|
|
|
|
Fix occasional crash bug with layers
Launcher occasionally crashes with a stack trace indicating that the memory
of a Layer object is corrupt. It is possible for us to delete a Layer
structure and then, briefly, use it to draw a DisplayList again before
that DisplayList gets recreated (without the layer that got deleted).
When this happens, if the memory got corrupted, it's possible to crash.
The fix is to add Layer to the other objects which we currently refcount
(bitmaps, shaders, etc.). Then instead of deleting a Layer, we decrement the
refcount. We increment when creating it, then increment it again when it's
referenced from a DisplayList. Then we decrement the refcount instead of
deleting it, and decrement when we clear a DisplayList that refers to it.
Then when the refcount reaches 0, we delete it.
Issue #6994632 Native crash in launcher when trying to launch all apps screen
Change-Id: I0627be8d49bb2f9ba8d158a84b764bb4e7df934c
2012-09-14 15:31:25 -07:00
|
|
|
Vector<Layer*> mLayers;
|
|
|
|
|
2011-01-23 12:01:41 -08:00
|
|
|
int mRestoreSaveCount;
|
2012-02-16 19:24:51 -08:00
|
|
|
|
2012-09-07 11:58:36 -07:00
|
|
|
Caches& mCaches;
|
2012-11-26 18:30:17 -08:00
|
|
|
sp<DisplayListData> mDisplayListData;
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2012-02-16 19:24:51 -08:00
|
|
|
float mTranslateX;
|
|
|
|
float mTranslateY;
|
|
|
|
bool mHasTranslate;
|
2011-08-25 14:01:48 -07:00
|
|
|
bool mHasDrawOps;
|
2011-01-23 12:01:41 -08:00
|
|
|
|
2012-09-27 17:55:46 -07:00
|
|
|
uint32_t mFunctorCount;
|
|
|
|
|
2010-09-28 19:09:36 -07:00
|
|
|
friend class DisplayList;
|
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
}; // class DisplayListRenderer
|
|
|
|
|
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
|