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>
|
|
|
|
|
2014-03-18 09:22:59 -07:00
|
|
|
#include "Caches.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"
|
2014-03-18 09:22:59 -07:00
|
|
|
#include "RenderNode.h"
|
2012-01-30 17:41:55 -08:00
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2014-07-16 15:12:15 -07:00
|
|
|
DisplayListRenderer::DisplayListRenderer()
|
|
|
|
: mCaches(Caches::getInstance())
|
2014-08-21 17:41:57 -07:00
|
|
|
, mDisplayListData(NULL)
|
2014-07-16 15:12:15 -07:00
|
|
|
, mTranslateX(0.0f)
|
|
|
|
, mTranslateY(0.0f)
|
2014-08-21 17:41:57 -07:00
|
|
|
, mDeferredBarrierType(kBarrier_None)
|
2014-07-16 15:12:15 -07:00
|
|
|
, mHighContrastText(false)
|
|
|
|
, mRestoreSaveCount(-1) {
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DisplayListRenderer::~DisplayListRenderer() {
|
2014-02-26 11:00:11 -08:00
|
|
|
LOG_ALWAYS_FATAL_IF(mDisplayListData,
|
|
|
|
"Destroyed a DisplayListRenderer during a record!");
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2014-02-26 11:00:11 -08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Operations
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-05-02 18:50:34 -07:00
|
|
|
|
2014-02-26 11:00:11 -08:00
|
|
|
DisplayListData* DisplayListRenderer::finishRecording() {
|
2011-01-14 18:51:01 -08:00
|
|
|
mPaintMap.clear();
|
2012-12-03 12:34:51 -08:00
|
|
|
mRegionMap.clear();
|
2011-02-03 15:06:05 -08:00
|
|
|
mPathMap.clear();
|
2014-02-26 11:00:11 -08:00
|
|
|
DisplayListData* data = mDisplayListData;
|
|
|
|
mDisplayListData = 0;
|
|
|
|
return data;
|
2011-01-05 18:01:22 -08: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) {
|
2014-02-26 11:00:11 -08:00
|
|
|
|
|
|
|
LOG_ALWAYS_FATAL_IF(mDisplayListData,
|
|
|
|
"prepareDirty called a second time during a recording!");
|
|
|
|
mDisplayListData = new DisplayListData();
|
|
|
|
|
2014-08-14 13:34:01 -07:00
|
|
|
initializeSaveStack(0, 0, getWidth(), getHeight(), Vector3());
|
2012-09-11 17:17:07 -07:00
|
|
|
|
2014-08-21 17:41:57 -07:00
|
|
|
mDeferredBarrierType = kBarrier_InOrder;
|
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() {
|
2014-08-21 17:41:57 -07:00
|
|
|
flushRestoreToCount();
|
|
|
|
flushTranslate();
|
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));
|
2014-07-24 10:36:08 -07:00
|
|
|
mDisplayListData->functors.add(functor);
|
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--;
|
2014-08-21 17:41:57 -07:00
|
|
|
flushTranslate();
|
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;
|
2014-08-21 17:41:57 -07:00
|
|
|
flushTranslate();
|
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) {
|
2014-09-14 15:49:54 -07:00
|
|
|
// force matrix/clip isolation for layer
|
|
|
|
flags |= SkCanvas::kClip_SaveFlag | SkCanvas::kMatrix_SaveFlag;
|
|
|
|
|
2014-02-05 16:47:00 -05:00
|
|
|
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
|
2014-08-21 17:41:57 -07:00
|
|
|
mHasDeferredTranslate = true;
|
2012-02-16 19:24:51 -08:00
|
|
|
mTranslateX += dx;
|
|
|
|
mTranslateY += dy;
|
2014-08-21 17:41:57 -07:00
|
|
|
flushRestoreToCount();
|
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
|
|
|
}
|
|
|
|
|
2013-12-10 12:28:58 -05:00
|
|
|
void DisplayListRenderer::setMatrix(const SkMatrix& matrix) {
|
2012-11-26 18:30:17 -08:00
|
|
|
addStateOp(new (alloc()) SetMatrixOp(matrix));
|
2013-12-30 15:32:54 -08:00
|
|
|
StatefulBaseRenderer::setMatrix(matrix);
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2013-12-10 12:28:58 -05:00
|
|
|
void DisplayListRenderer::concatMatrix(const SkMatrix& matrix) {
|
2012-11-26 18:30:17 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-06-20 16:01:00 -07:00
|
|
|
status_t DisplayListRenderer::drawRenderNode(RenderNode* renderNode, Rect& dirty, int32_t flags) {
|
2014-08-21 17:41:57 -07:00
|
|
|
LOG_ALWAYS_FATAL_IF(!renderNode, "missing rendernode");
|
|
|
|
|
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
|
2014-08-08 18:42:51 -07:00
|
|
|
DrawRenderNodeOp* op = new (alloc()) DrawRenderNodeOp(renderNode, flags, *currentTransform());
|
2014-08-21 17:41:57 -07:00
|
|
|
addRenderNodeOp(op);
|
2012-11-26 18:30:17 -08: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) {
|
2014-10-31 14:49:06 -07:00
|
|
|
mDisplayListData->ref(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-08-06 13:42:24 -07:00
|
|
|
status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
bitmap = refBitmap(bitmap);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
2014-08-06 13:42:24 -07:00
|
|
|
addDrawOp(new (alloc()) DrawBitmapOp(bitmap, 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) {
|
2014-08-06 13:42:24 -07:00
|
|
|
if (srcLeft == 0 && srcTop == 0
|
|
|
|
&& srcRight == bitmap->width() && srcBottom == bitmap->height()
|
|
|
|
&& (srcBottom - srcTop == dstBottom - dstTop)
|
|
|
|
&& (srcRight - srcLeft == dstRight - dstLeft)) {
|
2013-03-04 10:19:31 -08:00
|
|
|
// transform simple rect to rect drawing case into position bitmap ops, since they merge
|
2014-08-06 13:42:24 -07:00
|
|
|
save(SkCanvas::kMatrix_SaveFlag);
|
|
|
|
translate(dstLeft, dstTop);
|
|
|
|
drawBitmap(bitmap, paint);
|
|
|
|
restore();
|
|
|
|
} else {
|
|
|
|
bitmap = refBitmap(bitmap);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
|
|
|
addDrawOp(new (alloc()) DrawBitmapRectOp(bitmap,
|
|
|
|
srcLeft, srcTop, srcRight, srcBottom,
|
|
|
|
dstLeft, dstTop, dstRight, dstBottom, paint));
|
2013-03-04 10:19:31 -08:00
|
|
|
}
|
2012-05-31 15:21:51 -07:00
|
|
|
return DrawGlInfo::kStatusDone;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2014-08-06 13:42:24 -07:00
|
|
|
status_t DisplayListRenderer::drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint) {
|
2012-11-26 18:30:17 -08:00
|
|
|
bitmap = refBitmapData(bitmap);
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
2014-08-06 13:42:24 -07:00
|
|
|
addDrawOp(new (alloc()) DrawBitmapDataOp(bitmap, 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) {
|
2014-04-11 13:40:05 -07:00
|
|
|
int vertexCount = (meshWidth + 1) * (meshHeight + 1);
|
2012-11-26 18:30:17 -08:00
|
|
|
bitmap = refBitmap(bitmap);
|
2014-04-11 13:40:05 -07:00
|
|
|
vertices = refBuffer<float>(vertices, vertexCount * 2); // 2 floats per vertex
|
2012-11-26 18:30:17 -08:00
|
|
|
paint = refPaint(paint);
|
2014-04-11 13:40:05 -07:00
|
|
|
colors = refBuffer<int>(colors, vertexCount); // 1 color per vertex
|
2012-11-26 18:30:17 -08:00
|
|
|
|
|
|
|
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-09-15 17:20:08 +02:00
|
|
|
status_t DisplayListRenderer::drawRoundRect(
|
|
|
|
CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top,
|
|
|
|
CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom,
|
|
|
|
CanvasPropertyPrimitive* rx, CanvasPropertyPrimitive* ry,
|
|
|
|
CanvasPropertyPaint* paint) {
|
2014-10-31 14:49:06 -07:00
|
|
|
mDisplayListData->ref(left);
|
|
|
|
mDisplayListData->ref(top);
|
|
|
|
mDisplayListData->ref(right);
|
|
|
|
mDisplayListData->ref(bottom);
|
|
|
|
mDisplayListData->ref(rx);
|
|
|
|
mDisplayListData->ref(ry);
|
|
|
|
mDisplayListData->ref(paint);
|
2014-09-15 17:20:08 +02:00
|
|
|
addDrawOp(new (alloc()) DrawRoundRectPropsOp(&left->value, &top->value,
|
|
|
|
&right->value, &bottom->value, &rx->value, &ry->value, &paint->value));
|
|
|
|
return DrawGlInfo::kStatusDone;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-01 21:27:37 -07:00
|
|
|
status_t DisplayListRenderer::drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
|
|
|
|
CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint) {
|
2014-10-31 14:49:06 -07:00
|
|
|
mDisplayListData->ref(x);
|
|
|
|
mDisplayListData->ref(y);
|
|
|
|
mDisplayListData->ref(radius);
|
|
|
|
mDisplayListData->ref(paint);
|
2014-05-01 21:27:37 -07:00
|
|
|
addDrawOp(new (alloc()) DrawCirclePropsOp(&x->value, &y->value,
|
|
|
|
&radius->value, &paint->value));
|
|
|
|
return DrawGlInfo::kStatusDone;
|
|
|
|
}
|
|
|
|
|
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) {
|
2014-07-11 10:58:10 -07:00
|
|
|
if (fabs(sweepAngle) >= 360.0f) {
|
2014-06-17 13:47:05 -07:00
|
|
|
return drawOval(left, top, right, bottom, 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;
|
|
|
|
}
|
|
|
|
|
2014-07-16 15:12:15 -07:00
|
|
|
static void simplifyPaint(int color, SkPaint* paint) {
|
|
|
|
paint->setColor(color);
|
|
|
|
paint->setShader(NULL);
|
|
|
|
paint->setColorFilter(NULL);
|
|
|
|
paint->setLooper(NULL);
|
|
|
|
paint->setStrokeWidth(4 + 0.04 * paint->getTextSize());
|
|
|
|
paint->setStrokeJoin(SkPaint::kRound_Join);
|
|
|
|
paint->setLooper(NULL);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-08-19 10:21:12 -07:00
|
|
|
if (!text || count <= 0 || paintWillNotDrawText(*paint)) 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);
|
2012-02-16 19:24:51 -08:00
|
|
|
|
2014-07-16 15:12:15 -07:00
|
|
|
if (CC_UNLIKELY(mHighContrastText)) {
|
|
|
|
// high contrast draw path
|
|
|
|
int color = paint->getColor();
|
|
|
|
int channelSum = SkColorGetR(color) + SkColorGetG(color) + SkColorGetB(color);
|
|
|
|
bool darken = channelSum < (128 * 3);
|
|
|
|
|
|
|
|
// outline
|
|
|
|
SkPaint* outlinePaint = copyPaint(paint);
|
|
|
|
simplifyPaint(darken ? SK_ColorWHITE : SK_ColorBLACK, outlinePaint);
|
|
|
|
outlinePaint->setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
addDrawOp(new (alloc()) DrawTextOp(text, bytesCount, count,
|
|
|
|
x, y, positions, outlinePaint, totalAdvance, bounds)); // bounds?
|
|
|
|
|
|
|
|
// inner
|
|
|
|
SkPaint* innerPaint = copyPaint(paint);
|
|
|
|
simplifyPaint(darken ? SK_ColorBLACK : SK_ColorWHITE, innerPaint);
|
|
|
|
innerPaint->setStyle(SkPaint::kFill_Style);
|
|
|
|
addDrawOp(new (alloc()) DrawTextOp(text, bytesCount, count,
|
|
|
|
x, y, positions, innerPaint, totalAdvance, bounds));
|
|
|
|
} else {
|
|
|
|
// standard draw path
|
|
|
|
paint = refPaint(paint);
|
|
|
|
|
|
|
|
DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count,
|
|
|
|
x, y, positions, paint, totalAdvance, bounds);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-10-15 09:21:10 -04:00
|
|
|
void DisplayListRenderer::setDrawFilter(SkDrawFilter* filter) {
|
|
|
|
mDrawFilter.reset(filter);
|
2012-11-26 18:30:17 -08:00
|
|
|
}
|
|
|
|
|
2014-08-21 17:41:57 -07:00
|
|
|
void DisplayListRenderer::insertReorderBarrier(bool enableReorder) {
|
|
|
|
flushRestoreToCount();
|
|
|
|
flushTranslate();
|
|
|
|
mDeferredBarrierType = enableReorder ? kBarrier_OutOfOrder : kBarrier_InOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisplayListRenderer::flushRestoreToCount() {
|
2012-11-26 18:30:17 -08:00
|
|
|
if (mRestoreSaveCount >= 0) {
|
2014-08-21 17:41:57 -07:00
|
|
|
addOpAndUpdateChunk(new (alloc()) RestoreToCountOp(mRestoreSaveCount));
|
2012-11-26 18:30:17 -08:00
|
|
|
mRestoreSaveCount = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-21 17:41:57 -07:00
|
|
|
void DisplayListRenderer::flushTranslate() {
|
|
|
|
if (mHasDeferredTranslate) {
|
2012-11-26 18:30:17 -08:00
|
|
|
if (mTranslateX != 0.0f || mTranslateY != 0.0f) {
|
2014-08-21 17:41:57 -07:00
|
|
|
addOpAndUpdateChunk(new (alloc()) TranslateOp(mTranslateX, mTranslateY));
|
2012-11-26 18:30:17 -08:00
|
|
|
mTranslateX = mTranslateY = 0.0f;
|
|
|
|
}
|
2014-08-21 17:41:57 -07:00
|
|
|
mHasDeferredTranslate = false;
|
2012-11-26 18:30:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-21 17:41:57 -07:00
|
|
|
size_t DisplayListRenderer::addOpAndUpdateChunk(DisplayListOp* op) {
|
|
|
|
int insertIndex = mDisplayListData->displayListOps.add(op);
|
|
|
|
if (mDeferredBarrierType != kBarrier_None) {
|
|
|
|
// op is first in new chunk
|
|
|
|
mDisplayListData->chunks.push();
|
|
|
|
DisplayListData::Chunk& newChunk = mDisplayListData->chunks.editTop();
|
|
|
|
newChunk.beginOpIndex = insertIndex;
|
|
|
|
newChunk.endOpIndex = insertIndex + 1;
|
|
|
|
newChunk.reorderChildren = (mDeferredBarrierType == kBarrier_OutOfOrder);
|
|
|
|
|
|
|
|
int nextChildIndex = mDisplayListData->children().size();
|
|
|
|
newChunk.beginChildIndex = newChunk.endChildIndex = nextChildIndex;
|
|
|
|
mDeferredBarrierType = kBarrier_None;
|
|
|
|
} else {
|
|
|
|
// standard case - append to existing chunk
|
|
|
|
mDisplayListData->chunks.editTop().endOpIndex = insertIndex + 1;
|
|
|
|
}
|
|
|
|
return insertIndex;
|
2012-11-26 18:30:17 -08:00
|
|
|
}
|
|
|
|
|
2014-08-21 17:41:57 -07:00
|
|
|
size_t DisplayListRenderer::flushAndAddOp(DisplayListOp* op) {
|
|
|
|
flushRestoreToCount();
|
|
|
|
flushTranslate();
|
|
|
|
return addOpAndUpdateChunk(op);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t DisplayListRenderer::addStateOp(StateOp* op) {
|
|
|
|
return flushAndAddOp(op);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t DisplayListRenderer::addDrawOp(DrawOp* op) {
|
2012-11-26 18:30:17 -08:00
|
|
|
Rect localBounds;
|
2014-06-23 13:13:08 -07:00
|
|
|
if (op->getLocalBounds(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
|
|
|
|
2014-02-26 11:00:11 -08:00
|
|
|
mDisplayListData->hasDrawOps = true;
|
2014-08-21 17:41:57 -07:00
|
|
|
return flushAndAddOp(op);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t DisplayListRenderer::addRenderNodeOp(DrawRenderNodeOp* op) {
|
|
|
|
int opIndex = addDrawOp(op);
|
|
|
|
int childIndex = mDisplayListData->addChild(op);
|
|
|
|
|
|
|
|
// update the chunk's child indices
|
|
|
|
DisplayListData::Chunk& chunk = mDisplayListData->chunks.editTop();
|
|
|
|
chunk.endChildIndex = childIndex + 1;
|
|
|
|
|
|
|
|
if (op->renderNode()->stagingProperties().isProjectionReceiver()) {
|
|
|
|
// use staging property, since recording on UI thread
|
|
|
|
mDisplayListData->projectionReceiveIndex = opIndex;
|
|
|
|
}
|
|
|
|
return opIndex;
|
2012-01-23 17:09:05 -08:00
|
|
|
}
|
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|