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
|
|
|
}
|
|
|
|
|
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();
|
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
|
|
|
}
|
2013-10-25 18:30:17 -07:00
|
|
|
// TODO: should just avoid setting the DisplayList's DisplayListData
|
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
|
|
|
}
|
|
|
|
|
2010-09-28 19:09:36 -07:00
|
|
|
void DisplayListRenderer::setViewport(int width, int height) {
|
2013-10-25 18:30:17 -07:00
|
|
|
// TODO: DisplayListRenderer shouldn't have a projection matrix, as it should never be used
|
|
|
|
mViewProjMatrix.loadOrtho(0, width, height, 0, -1, 1);
|
2010-09-28 19:09:36 -07:00
|
|
|
|
2013-12-30 15:32:54 -08:00
|
|
|
initializeViewport(width, height);
|
2010-09-28 19:09:36 -07:00
|
|
|
}
|
|
|
|
|
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) {
|
2013-12-30 15:32:54 -08:00
|
|
|
initializeSaveStack(0, 0, getWidth(), getHeight());
|
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));
|
2013-12-30 15:32:54 -08:00
|
|
|
return StatefulBaseRenderer::save(flags);
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2013-12-30 15:32:54 -08:00
|
|
|
StatefulBaseRenderer::restore();
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::restoreToCount(int saveCount) {
|
2011-01-23 12:01:41 -08:00
|
|
|
mRestoreSaveCount = saveCount;
|
2012-11-26 18:30:17 -08:00
|
|
|
insertTranslate();
|
2013-12-30 15:32:54 -08:00
|
|
|
StatefulBaseRenderer::restoreToCount(saveCount);
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
|
2014-02-05 16:47:00 -05:00
|
|
|
const SkPaint* paint, int flags) {
|
|
|
|
paint = refPaint(paint);
|
|
|
|
addStateOp(new (alloc()) SaveLayerOp(left, top, right, bottom, paint, flags));
|
2013-12-30 15:32:54 -08:00
|
|
|
return StatefulBaseRenderer::save(flags);
|
2010-10-27 18:57:51 -07:00
|
|
|
}
|
|
|
|
|
2013-12-26 15:13:13 -08:00
|
|
|
void DisplayListRenderer::translate(float dx, float dy, float dz) {
|
|
|
|
// ignore dz, not used at defer time
|
2012-02-16 19:24:51 -08:00
|
|
|
mHasTranslate = true;
|
|
|
|
mTranslateX += dx;
|
|
|
|
mTranslateY += dy;
|
|
|
|
insertRestoreToCount();
|
2013-12-30 15:32:54 -08:00
|
|
|
StatefulBaseRenderer::translate(dx, dy, dz);
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::rotate(float degrees) {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) RotateOp(degrees));
|
2013-12-30 15:32:54 -08:00
|
|
|
StatefulBaseRenderer::rotate(degrees);
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::scale(float sx, float sy) {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) ScaleOp(sx, sy));
|
2013-12-30 15:32:54 -08:00
|
|
|
StatefulBaseRenderer::scale(sx, sy);
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
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));
|
2013-12-30 15:32:54 -08:00
|
|
|
StatefulBaseRenderer::skew(sx, sy);
|
2011-01-18 11:19:19 -08:00
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
void DisplayListRenderer::setMatrix(const SkMatrix* matrix) {
|
2012-11-26 18:30:17 -08:00
|
|
|
matrix = refMatrix(matrix);
|
|
|
|
addStateOp(new (alloc()) SetMatrixOp(matrix));
|
2013-12-30 15:32:54 -08:00
|
|
|
StatefulBaseRenderer::setMatrix(matrix);
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
void DisplayListRenderer::concatMatrix(const SkMatrix* matrix) {
|
2012-11-26 18:30:17 -08:00
|
|
|
matrix = refMatrix(matrix);
|
|
|
|
addStateOp(new (alloc()) ConcatMatrixOp(matrix));
|
2013-12-30 15:32:54 -08:00
|
|
|
StatefulBaseRenderer::concatMatrix(matrix);
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
2014-01-01 14:45:21 -08:00
|
|
|
return StatefulBaseRenderer::clipRect(left, top, right, bottom, op);
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
bool DisplayListRenderer::clipPath(const SkPath* path, SkRegion::Op op) {
|
2012-11-26 18:30:17 -08:00
|
|
|
path = refPath(path);
|
|
|
|
addStateOp(new (alloc()) ClipPathOp(path, op));
|
2014-01-01 14:45:21 -08:00
|
|
|
return StatefulBaseRenderer::clipPath(path, op);
|
2012-12-03 12:34:51 -08:00
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
bool DisplayListRenderer::clipRegion(const SkRegion* region, SkRegion::Op op) {
|
2012-11-26 18:30:17 -08:00
|
|
|
region = refRegion(region);
|
|
|
|
addStateOp(new (alloc()) ClipRegionOp(region, op));
|
2014-01-01 14:45:21 -08:00
|
|
|
return StatefulBaseRenderer::clipRegion(region, op);
|
2012-12-03 12:34:51 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2014-01-01 14:45:21 -08:00
|
|
|
DrawDisplayListOp* op = new (alloc()) DrawDisplayListOp(displayList,
|
|
|
|
flags, *currentTransform());
|
2013-10-25 18:30:17 -07:00
|
|
|
addDrawOp(op);
|
|
|
|
mDisplayListData->children.push(op);
|
2014-02-05 16:50:41 -08:00
|
|
|
if (displayList->isProjectionReceiver()) {
|
|
|
|
mDisplayListData->projectionReceiveIndex = mDisplayListData->displayListOps.size() - 1;
|
|
|
|
}
|
2013-10-25 18:30:17 -07:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float left, float top,
|
|
|
|
const 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
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, const SkMatrix* matrix,
|
|
|
|
const 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
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
|
2010-09-26 18:40:37 -07:00
|
|
|
float srcRight, float srcBottom, float dstLeft, float dstTop,
|
2014-01-02 17:13:34 -08:00
|
|
|
float dstRight, float dstBottom, const 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
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t DisplayListRenderer::drawBitmapData(const SkBitmap* bitmap, float left, float top,
|
|
|
|
const 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
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t DisplayListRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
|
|
|
|
const float* vertices, const int* colors, const 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
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t DisplayListRenderer::drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
|
|
|
|
float left, float top, float right, float bottom, const 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,
|
2014-01-02 17:13:34 -08:00
|
|
|
const 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,
|
2014-01-02 17:13:34 -08:00
|
|
|
float rx, float ry, const 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
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t DisplayListRenderer::drawCircle(float x, float y, float radius, const 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,
|
2014-01-02 17:13:34 -08:00
|
|
|
const 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,
|
2014-01-02 17:13:34 -08:00
|
|
|
float startAngle, float sweepAngle, bool useCenter, const 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
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t DisplayListRenderer::drawPath(const SkPath* path, const 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
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t DisplayListRenderer::drawLines(const float* points, int count, const 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
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t DisplayListRenderer::drawPoints(const float* points, int count, const 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,
|
2014-01-02 17:13:34 -08:00
|
|
|
const SkPath* path, float hOffset, float vOffset, const SkPaint* paint) {
|
2012-07-23 15:22:52 -07:00
|
|
|
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,
|
2014-01-02 17:13:34 -08:00
|
|
|
const float* positions, const SkPaint* paint) {
|
2012-07-23 15:22:52 -07:00
|
|
|
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,
|
2014-01-02 17:13:34 -08:00
|
|
|
float x, float y, const float* positions, const 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
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
status_t DisplayListRenderer::drawRects(const float* rects, int count, const SkPaint* paint) {
|
2013-01-04 19:05:13 -08:00
|
|
|
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::resetShadow() {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) ResetShadowOp());
|
2013-08-09 14:06:29 -07:00
|
|
|
OpenGLRenderer::resetShadow();
|
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));
|
2013-08-09 14:06:29 -07:00
|
|
|
OpenGLRenderer::setupShadow(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;
|
2013-09-11 16:23:37 -07:00
|
|
|
if (op->getLocalBounds(mDrawModifiers, localBounds)) {
|
2013-11-19 18:00:46 -08:00
|
|
|
bool rejected = quickRejectConservative(localBounds.left, localBounds.top,
|
2012-11-26 18:30:17 -08:00
|
|
|
localBounds.right, localBounds.bottom);
|
|
|
|
op->setQuickRejected(rejected);
|
|
|
|
}
|
2013-09-11 16:23:37 -07:00
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
mHasDrawOps = true;
|
|
|
|
addOpInternal(op);
|
2012-01-23 17:09:05 -08:00
|
|
|
}
|
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|