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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "OpenGLRenderer"
|
|
|
|
|
2012-03-13 11:18:20 -07:00
|
|
|
#include <SkCamera.h>
|
2013-03-15 19:06:39 -07:00
|
|
|
#include <SkCanvas.h>
|
2011-03-24 10:51:31 -07:00
|
|
|
|
2012-03-26 16:45:05 -07:00
|
|
|
#include <private/hwui/DrawGlInfo.h>
|
|
|
|
|
2013-02-14 15:36:01 -08:00
|
|
|
#include "DisplayList.h"
|
2013-02-04 16:16:33 -08:00
|
|
|
#include "DeferredDisplayList.h"
|
2011-03-24 10:51:31 -07:00
|
|
|
#include "DisplayListLogBuffer.h"
|
2012-11-26 18:30:17 -08:00
|
|
|
#include "DisplayListOp.h"
|
2010-09-26 18:40:37 -07:00
|
|
|
#include "DisplayListRenderer.h"
|
2011-03-24 10:51:31 -07:00
|
|
|
#include "Caches.h"
|
2012-01-30 17:41:55 -08:00
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2012-09-07 11:58:36 -07:00
|
|
|
DisplayListRenderer::DisplayListRenderer():
|
2012-11-26 18:30:17 -08:00
|
|
|
mCaches(Caches::getInstance()), mDisplayListData(new DisplayListData),
|
2012-09-27 17:55:46 -07:00
|
|
|
mTranslateX(0.0f), mTranslateY(0.0f), mHasTranslate(false),
|
|
|
|
mHasDrawOps(false), mFunctorCount(0) {
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DisplayListRenderer::~DisplayListRenderer() {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::reset() {
|
2012-11-26 18:30:17 -08:00
|
|
|
mDisplayListData = new DisplayListData();
|
2012-09-07 11:58:36 -07:00
|
|
|
mCaches.resourceCache.lock();
|
|
|
|
|
2010-10-08 08:37:55 -07:00
|
|
|
for (size_t i = 0; i < mBitmapResources.size(); i++) {
|
2012-09-07 11:58:36 -07:00
|
|
|
mCaches.resourceCache.decrementRefcountLocked(mBitmapResources.itemAt(i));
|
2010-10-08 08:37:55 -07:00
|
|
|
}
|
2010-10-25 15:47:32 -07:00
|
|
|
|
2012-05-15 11:10:01 -07:00
|
|
|
for (size_t i = 0; i < mOwnedBitmapResources.size(); i++) {
|
2012-09-07 11:58:36 -07:00
|
|
|
mCaches.resourceCache.decrementRefcountLocked(mOwnedBitmapResources.itemAt(i));
|
2012-05-15 11:10:01 -07:00
|
|
|
}
|
|
|
|
|
2011-06-22 16:14:36 -07:00
|
|
|
for (size_t i = 0; i < mFilterResources.size(); i++) {
|
2012-09-07 11:58:36 -07:00
|
|
|
mCaches.resourceCache.decrementRefcountLocked(mFilterResources.itemAt(i));
|
2011-06-22 16:14:36 -07:00
|
|
|
}
|
|
|
|
|
2013-06-26 15:45:41 -07:00
|
|
|
for (size_t i = 0; i < mPatchResources.size(); i++) {
|
|
|
|
mCaches.resourceCache.decrementRefcountLocked(mPatchResources.itemAt(i));
|
|
|
|
}
|
|
|
|
|
2011-01-14 18:51:01 -08:00
|
|
|
for (size_t i = 0; i < mShaders.size(); i++) {
|
2012-09-07 11:58:36 -07:00
|
|
|
mCaches.resourceCache.decrementRefcountLocked(mShaders.itemAt(i));
|
2011-01-14 18:51:01 -08:00
|
|
|
}
|
|
|
|
|
2012-05-02 18:50:34 -07:00
|
|
|
for (size_t i = 0; i < mSourcePaths.size(); i++) {
|
2012-09-07 11:58:36 -07:00
|
|
|
mCaches.resourceCache.decrementRefcountLocked(mSourcePaths.itemAt(i));
|
2012-05-02 18:50:34 -07:00
|
|
|
}
|
2012-09-07 11:58:36 -07:00
|
|
|
|
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
|
|
|
for (size_t i = 0; i < mLayers.size(); i++) {
|
|
|
|
mCaches.resourceCache.decrementRefcountLocked(mLayers.itemAt(i));
|
|
|
|
}
|
|
|
|
|
2012-09-07 11:58:36 -07:00
|
|
|
mCaches.resourceCache.unlock();
|
|
|
|
|
|
|
|
mBitmapResources.clear();
|
|
|
|
mOwnedBitmapResources.clear();
|
|
|
|
mFilterResources.clear();
|
2013-06-26 15:45:41 -07:00
|
|
|
mPatchResources.clear();
|
2012-05-02 18:50:34 -07:00
|
|
|
mSourcePaths.clear();
|
|
|
|
|
2012-09-07 11:58:36 -07:00
|
|
|
mShaders.clear();
|
|
|
|
mShaderMap.clear();
|
|
|
|
|
2011-01-14 18:51:01 -08:00
|
|
|
mPaints.clear();
|
|
|
|
mPaintMap.clear();
|
2011-06-22 16:14:36 -07:00
|
|
|
|
2012-12-03 12:34:51 -08:00
|
|
|
mRegions.clear();
|
|
|
|
mRegionMap.clear();
|
|
|
|
|
2011-02-03 15:06:05 -08:00
|
|
|
mPaths.clear();
|
|
|
|
mPathMap.clear();
|
2011-06-22 16:14:36 -07:00
|
|
|
|
2010-10-25 15:47:32 -07:00
|
|
|
mMatrices.clear();
|
2011-08-25 14:01:48 -07:00
|
|
|
|
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
|
|
|
mLayers.clear();
|
|
|
|
|
2011-08-25 14:01:48 -07:00
|
|
|
mHasDrawOps = false;
|
2012-09-27 17:55:46 -07:00
|
|
|
mFunctorCount = 0;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Operations
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-07-21 17:02:54 -07:00
|
|
|
DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
|
|
|
|
if (!displayList) {
|
|
|
|
displayList = new DisplayList(*this);
|
2011-01-05 18:01:22 -08:00
|
|
|
} else {
|
2011-07-21 17:02:54 -07:00
|
|
|
displayList->initFromDisplayListRenderer(*this, true);
|
2011-01-05 18:01:22 -08:00
|
|
|
}
|
2011-08-25 14:01:48 -07:00
|
|
|
displayList->setRenderable(mHasDrawOps);
|
2011-07-21 17:02:54 -07:00
|
|
|
return displayList;
|
2011-01-05 18:01:22 -08:00
|
|
|
}
|
|
|
|
|
2012-05-15 11:10:01 -07:00
|
|
|
bool DisplayListRenderer::isDeferred() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-28 19:09:36 -07:00
|
|
|
void DisplayListRenderer::setViewport(int width, int height) {
|
|
|
|
mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
|
|
|
|
|
|
|
|
mWidth = width;
|
|
|
|
mHeight = height;
|
|
|
|
}
|
|
|
|
|
2012-10-18 15:05:02 -07:00
|
|
|
status_t DisplayListRenderer::prepareDirty(float left, float top,
|
2011-01-24 16:33:45 -08:00
|
|
|
float right, float bottom, bool opaque) {
|
2010-09-28 19:09:36 -07:00
|
|
|
mSnapshot = new Snapshot(mFirstSnapshot,
|
|
|
|
SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
|
|
|
|
mSaveCount = 1;
|
2012-09-11 17:17:07 -07:00
|
|
|
|
2010-09-28 19:09:36 -07:00
|
|
|
mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
|
2012-09-11 17:17:07 -07:00
|
|
|
mDirtyClip = opaque;
|
|
|
|
|
2011-01-23 12:01:41 -08:00
|
|
|
mRestoreSaveCount = -1;
|
2012-09-11 17:17:07 -07:00
|
|
|
|
2012-06-06 19:03:58 -07:00
|
|
|
return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
|
2011-01-23 12:01:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::finish() {
|
|
|
|
insertRestoreToCount();
|
2012-11-26 18:30:17 -08:00
|
|
|
insertTranslate();
|
2010-09-28 19:09:36 -07:00
|
|
|
}
|
|
|
|
|
2011-01-10 14:10:36 -08:00
|
|
|
void DisplayListRenderer::interrupt() {
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:43:01 -08:00
|
|
|
void DisplayListRenderer::resume() {
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-03-26 16:45:05 -07:00
|
|
|
status_t DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
|
2011-03-07 18:06:46 -08:00
|
|
|
// Ignore dirty during recording, it matters only when we replay
|
2012-11-26 18:30:17 -08:00
|
|
|
addDrawOp(new (alloc()) DrawFunctorOp(functor));
|
2012-09-27 17:55:46 -07:00
|
|
|
mFunctorCount++;
|
2012-03-26 16:45:05 -07:00
|
|
|
return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
|
2011-01-10 14:10:36 -08:00
|
|
|
}
|
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
int DisplayListRenderer::save(int flags) {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) SaveOp(flags));
|
2010-09-26 18:40:37 -07:00
|
|
|
return OpenGLRenderer::save(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::restore() {
|
2011-08-25 14:01:48 -07:00
|
|
|
if (mRestoreSaveCount < 0) {
|
2012-02-16 19:24:51 -08:00
|
|
|
restoreToCount(getSaveCount() - 1);
|
|
|
|
return;
|
2011-08-25 14:01:48 -07:00
|
|
|
}
|
2012-02-16 19:24:51 -08:00
|
|
|
|
|
|
|
mRestoreSaveCount--;
|
2012-11-26 18:30:17 -08:00
|
|
|
insertTranslate();
|
2010-09-26 18:40:37 -07:00
|
|
|
OpenGLRenderer::restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::restoreToCount(int saveCount) {
|
2011-01-23 12:01:41 -08:00
|
|
|
mRestoreSaveCount = saveCount;
|
2012-11-26 18:30:17 -08:00
|
|
|
insertTranslate();
|
2010-09-26 18:40:37 -07:00
|
|
|
OpenGLRenderer::restoreToCount(saveCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
|
2013-03-08 13:12:16 -08:00
|
|
|
int alpha, SkXfermode::Mode mode, int flags) {
|
|
|
|
addStateOp(new (alloc()) SaveLayerOp(left, top, right, bottom, alpha, mode, flags));
|
2010-10-27 18:57:51 -07:00
|
|
|
return OpenGLRenderer::save(flags);
|
|
|
|
}
|
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
void DisplayListRenderer::translate(float dx, float dy) {
|
2012-02-16 19:24:51 -08:00
|
|
|
mHasTranslate = true;
|
|
|
|
mTranslateX += dx;
|
|
|
|
mTranslateY += dy;
|
|
|
|
insertRestoreToCount();
|
2010-09-26 18:40:37 -07:00
|
|
|
OpenGLRenderer::translate(dx, dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::rotate(float degrees) {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) RotateOp(degrees));
|
2010-09-26 18:40:37 -07:00
|
|
|
OpenGLRenderer::rotate(degrees);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::scale(float sx, float sy) {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) ScaleOp(sx, sy));
|
2010-09-26 18:40:37 -07:00
|
|
|
OpenGLRenderer::scale(sx, sy);
|
|
|
|
}
|
|
|
|
|
2011-01-18 11:19:19 -08:00
|
|
|
void DisplayListRenderer::skew(float sx, float sy) {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) SkewOp(sx, sy));
|
2011-01-18 11:19:19 -08:00
|
|
|
OpenGLRenderer::skew(sx, sy);
|
|
|
|
}
|
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
|
2012-11-26 18:30:17 -08:00
|
|
|
matrix = refMatrix(matrix);
|
|
|
|
addStateOp(new (alloc()) SetMatrixOp(matrix));
|
2010-09-26 18:40:37 -07:00
|
|
|
OpenGLRenderer::setMatrix(matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
|
2012-11-26 18:30:17 -08:00
|
|
|
matrix = refMatrix(matrix);
|
|
|
|
addStateOp(new (alloc()) ConcatMatrixOp(matrix));
|
2010-09-26 18:40:37 -07:00
|
|
|
OpenGLRenderer::concatMatrix(matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
|
|
|
|
SkRegion::Op op) {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) ClipRectOp(left, top, right, bottom, op));
|
2010-09-26 18:40:37 -07:00
|
|
|
return OpenGLRenderer::clipRect(left, top, right, bottom, op);
|
|
|
|
}
|
|
|
|
|
2012-12-03 12:34:51 -08:00
|
|
|
bool DisplayListRenderer::clipPath(SkPath* path, SkRegion::Op op) {
|
2012-11-26 18:30:17 -08:00
|
|
|
path = refPath(path);
|
|
|
|
addStateOp(new (alloc()) ClipPathOp(path, op));
|
2012-12-03 12:34:51 -08:00
|
|
|
return OpenGLRenderer::clipPath(path, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisplayListRenderer::clipRegion(SkRegion* region, SkRegion::Op op) {
|
2012-11-26 18:30:17 -08:00
|
|
|
region = refRegion(region);
|
|
|
|
addStateOp(new (alloc()) ClipRegionOp(region, op));
|
2012-12-03 12:34:51 -08:00
|
|
|
return OpenGLRenderer::clipRegion(region, op);
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:45:05 -07:00
|
|
|
status_t DisplayListRenderer::drawDisplayList(DisplayList* displayList,
|
2013-02-04 16:16:33 -08:00
|
|
|
Rect& dirty, int32_t flags) {
|
2011-03-07 18:06:46 -08:00
|
|
|
// dirty is an out parameter and should not be recorded,
|
|
|
|
// it matters only when replaying the display list
|
2012-03-26 14:37:51 -07:00
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
// TODO: To be safe, the display list should be ref-counted in the
|
|
|
|
// resources cache, but we rely on the caller (UI toolkit) to
|
|
|
|
// do the right thing for now
|
|
|
|
|
|
|
|
addDrawOp(new (alloc()) DrawDisplayListOp(displayList, flags));
|
2012-03-26 16:45:05 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2010-11-08 12:08:41 -08:00
|
|
|
}
|
|
|
|
|
2013-03-15 17:24:33 -07:00
|
|
|
status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y) {
|
2013-03-28 11:32:33 -07:00
|
|
|
layer = refLayer(layer);
|
2013-03-15 17:24:33 -07:00
|
|
|
addDrawOp(new (alloc()) DrawLayerOp(layer, x, y));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2011-01-11 14:29:25 -08:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
bitmap = refBitmap(bitmap);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
2013-06-27 15:27:09 -07:00
|
|
|
addDrawOp(new (alloc()) DrawBitmapOp(bitmap, left, top, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
bitmap = refBitmap(bitmap);
|
|
|
|
matrix = refMatrix(matrix);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
|
|
|
addDrawOp(new (alloc()) DrawBitmapMatrixOp(bitmap, matrix, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::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-11-26 18:30:17 -08:00
|
|
|
bitmap = refBitmap(bitmap);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
2013-03-04 10:19:31 -08:00
|
|
|
if (srcLeft == 0 && srcTop == 0 &&
|
|
|
|
srcRight == bitmap->width() && srcBottom == bitmap->height() &&
|
|
|
|
(srcBottom - srcTop == dstBottom - dstTop) &&
|
|
|
|
(srcRight - srcLeft == dstRight - dstLeft)) {
|
|
|
|
// transform simple rect to rect drawing case into position bitmap ops, since they merge
|
2013-06-27 15:27:09 -07:00
|
|
|
addDrawOp(new (alloc()) DrawBitmapOp(bitmap, dstLeft, dstTop, paint));
|
2013-03-04 10:19:31 -08:00
|
|
|
return DrawGlInfo::kStatusDone;
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
addDrawOp(new (alloc()) DrawBitmapRectOp(bitmap,
|
|
|
|
srcLeft, srcTop, srcRight, srcBottom,
|
|
|
|
dstLeft, dstTop, dstRight, dstBottom, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::drawBitmapData(SkBitmap* bitmap, float left, float top,
|
|
|
|
SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
bitmap = refBitmapData(bitmap);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
|
|
|
addDrawOp(new (alloc()) DrawBitmapDataOp(bitmap, left, top, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2012-05-14 19:44:40 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
|
2011-01-20 19:09:30 -08:00
|
|
|
float* vertices, int* colors, SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
int count = (meshWidth + 1) * (meshHeight + 1) * 2;
|
|
|
|
bitmap = refBitmap(bitmap);
|
|
|
|
vertices = refBuffer<float>(vertices, count);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
colors = refBuffer<int>(colors, count);
|
|
|
|
|
|
|
|
addDrawOp(new (alloc()) DrawBitmapMeshOp(bitmap, meshWidth, meshHeight,
|
|
|
|
vertices, colors, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2011-01-20 19:09:30 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
status_t DisplayListRenderer::drawPatch(SkBitmap* bitmap, Res_png_9patch* patch,
|
|
|
|
float left, float top, float right, float bottom, SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
bitmap = refBitmap(bitmap);
|
2013-06-26 15:45:41 -07:00
|
|
|
patch = refPatch(patch);
|
2013-06-21 11:35:52 -07:00
|
|
|
paint = refPaint(paint);
|
2012-11-26 18:30:17 -08:00
|
|
|
|
2013-06-20 18:30:28 -07:00
|
|
|
addDrawOp(new (alloc()) DrawPatchOp(bitmap, patch, left, top, right, bottom, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
|
2012-11-26 18:30:17 -08:00
|
|
|
addDrawOp(new (alloc()) DrawColorOp(color, mode));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
|
2010-10-08 08:37:55 -07:00
|
|
|
SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
paint = refPaint(paint);
|
|
|
|
addDrawOp(new (alloc()) DrawRectOp(left, top, right, bottom, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
|
2012-02-21 13:43:44 -08:00
|
|
|
float rx, float ry, SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
paint = refPaint(paint);
|
|
|
|
addDrawOp(new (alloc()) DrawRoundRectOp(left, top, right, bottom, rx, ry, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2011-01-19 21:54:02 -08:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
paint = refPaint(paint);
|
|
|
|
addDrawOp(new (alloc()) DrawCircleOp(x, y, radius, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2011-01-19 21:54:02 -08:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
|
2011-01-23 14:18:41 -08:00
|
|
|
SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
paint = refPaint(paint);
|
|
|
|
addDrawOp(new (alloc()) DrawOvalOp(left, top, right, bottom, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2011-01-23 14:18:41 -08:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::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-11-26 18:30:17 -08:00
|
|
|
paint = refPaint(paint);
|
|
|
|
addDrawOp(new (alloc()) DrawArcOp(left, top, right, bottom,
|
|
|
|
startAngle, sweepAngle, useCenter, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2011-01-23 16:15:02 -08:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
path = refPath(path);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
|
|
|
addDrawOp(new (alloc()) DrawPathOp(path, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
points = refBuffer<float>(points, count);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
|
|
|
addDrawOp(new (alloc()) DrawLinesOp(points, count, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2011-03-21 13:11:28 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
status_t DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
points = refBuffer<float>(points, count);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
|
|
|
addDrawOp(new (alloc()) DrawPointsOp(points, count, paint));
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-07-23 15:22:52 -07:00
|
|
|
status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
|
|
|
|
SkPath* path, float hOffset, float vOffset, SkPaint* paint) {
|
|
|
|
if (!text || count <= 0) return DrawGlInfo::kStatusDone;
|
2012-11-26 18:30:17 -08:00
|
|
|
|
|
|
|
text = refText(text, bytesCount);
|
|
|
|
path = refPath(path);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
|
|
|
DrawOp* op = new (alloc()) DrawTextOnPathOp(text, bytesCount, count, path,
|
|
|
|
hOffset, vOffset, paint);
|
2013-03-01 14:31:04 -08:00
|
|
|
addDrawOp(op);
|
2012-07-23 15:22:52 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
|
|
|
|
const float* positions, SkPaint* paint) {
|
|
|
|
if (!text || count <= 0) return DrawGlInfo::kStatusDone;
|
2012-11-26 18:30:17 -08:00
|
|
|
|
|
|
|
text = refText(text, bytesCount);
|
|
|
|
positions = refBuffer<float>(positions, count * 2);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
|
|
|
DrawOp* op = new (alloc()) DrawPosTextOp(text, bytesCount, count, positions, paint);
|
2013-03-01 14:31:04 -08:00
|
|
|
addDrawOp(op);
|
2012-07-23 15:22:52 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
|
|
|
}
|
|
|
|
|
2012-07-27 16:41:22 -07:00
|
|
|
status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
|
2013-03-04 10:19:31 -08:00
|
|
|
float x, float y, const float* positions, SkPaint* paint,
|
2013-05-03 16:35:54 -07:00
|
|
|
float totalAdvance, const Rect& bounds, DrawOpMode drawOpMode) {
|
2013-03-04 10:19:31 -08:00
|
|
|
|
2012-05-31 15:21:51 -07:00
|
|
|
if (!text || count <= 0) return DrawGlInfo::kStatusDone;
|
2012-02-16 19:24:51 -08:00
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
text = refText(text, bytesCount);
|
|
|
|
positions = refBuffer<float>(positions, count * 2);
|
|
|
|
paint = refPaint(paint);
|
2012-02-16 19:24:51 -08:00
|
|
|
|
2013-05-03 16:35:54 -07:00
|
|
|
DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count,
|
|
|
|
x, y, positions, paint, totalAdvance, bounds);
|
2013-03-01 14:31:04 -08:00
|
|
|
addDrawOp(op);
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2013-01-04 19:05:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t DisplayListRenderer::drawRects(const float* rects, int count, SkPaint* paint) {
|
|
|
|
if (count <= 0) return DrawGlInfo::kStatusDone;
|
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
rects = refBuffer<float>(rects, count);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
addDrawOp(new (alloc()) DrawRectsOp(rects, count, paint));
|
2013-01-04 19:05:13 -08:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2012-01-17 17:39:26 -08:00
|
|
|
}
|
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
void DisplayListRenderer::resetShader() {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) ResetShaderOp());
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::setupShader(SkiaShader* shader) {
|
2012-11-26 18:30:17 -08:00
|
|
|
shader = refShader(shader);
|
|
|
|
addStateOp(new (alloc()) SetupShaderOp(shader));
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::resetColorFilter() {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) ResetColorFilterOp());
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
|
2012-11-26 18:30:17 -08:00
|
|
|
filter = refColorFilter(filter);
|
|
|
|
addStateOp(new (alloc()) SetupColorFilterOp(filter));
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::resetShadow() {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) ResetShadowOp());
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) SetupShadowOp(radius, dx, dy, color));
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2012-01-23 17:09:05 -08:00
|
|
|
void DisplayListRenderer::resetPaintFilter() {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) ResetPaintFilterOp());
|
2012-01-23 17:09:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) SetupPaintFilterOp(clearBits, setBits));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::insertRestoreToCount() {
|
|
|
|
if (mRestoreSaveCount >= 0) {
|
|
|
|
DisplayListOp* op = new (alloc()) RestoreToCountOp(mRestoreSaveCount);
|
|
|
|
mDisplayListData->displayListOps.add(op);
|
|
|
|
mRestoreSaveCount = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::insertTranslate() {
|
|
|
|
if (mHasTranslate) {
|
|
|
|
if (mTranslateX != 0.0f || mTranslateY != 0.0f) {
|
|
|
|
DisplayListOp* op = new (alloc()) TranslateOp(mTranslateX, mTranslateY);
|
|
|
|
mDisplayListData->displayListOps.add(op);
|
|
|
|
mTranslateX = mTranslateY = 0.0f;
|
|
|
|
}
|
|
|
|
mHasTranslate = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::addStateOp(StateOp* op) {
|
|
|
|
addOpInternal(op);
|
|
|
|
}
|
|
|
|
|
2013-03-01 14:31:04 -08:00
|
|
|
void DisplayListRenderer::addDrawOp(DrawOp* op) {
|
2012-11-26 18:30:17 -08:00
|
|
|
Rect localBounds;
|
|
|
|
if (op->getLocalBounds(localBounds)) {
|
2013-03-01 14:31:04 -08:00
|
|
|
bool rejected = quickRejectNoScissor(localBounds.left, localBounds.top,
|
2012-11-26 18:30:17 -08:00
|
|
|
localBounds.right, localBounds.bottom);
|
|
|
|
op->setQuickRejected(rejected);
|
|
|
|
}
|
|
|
|
mHasDrawOps = true;
|
|
|
|
addOpInternal(op);
|
2012-01-23 17:09:05 -08:00
|
|
|
}
|
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|