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
|
|
|
|
2014-10-15 09:21:10 -04:00
|
|
|
#include <SkDrawFilter.h>
|
2010-09-26 18:40:37 -07:00
|
|
|
#include <SkMatrix.h>
|
|
|
|
#include <SkPaint.h>
|
|
|
|
#include <SkPath.h>
|
2014-10-15 15:46:42 -04:00
|
|
|
#include <SkRegion.h>
|
2014-10-15 09:21:10 -04:00
|
|
|
#include <SkTLazy.h>
|
2011-10-12 13:48:51 -07:00
|
|
|
#include <cutils/compiler.h>
|
|
|
|
|
2015-01-20 07:51:14 -08:00
|
|
|
#include "Canvas.h"
|
2014-10-10 13:38:16 -04:00
|
|
|
#include "CanvasState.h"
|
2014-10-15 15:46:42 -04:00
|
|
|
#include "DisplayList.h"
|
2014-12-16 08:37:20 -05:00
|
|
|
#include "SkiaCanvasProxy.h"
|
2014-10-10 13:38:16 -04:00
|
|
|
#include "RenderNode.h"
|
2014-11-06 09:45:10 -08:00
|
|
|
#include "ResourceCache.h"
|
2010-09-26 18:40:37 -07:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Defines
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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;
|
2014-11-07 07:53:43 -08:00
|
|
|
class DeferredLayerUpdater;
|
2012-11-26 18:30:17 -08:00
|
|
|
class DisplayListOp;
|
|
|
|
class DrawOp;
|
2014-10-15 15:46:42 -04:00
|
|
|
class RenderNode;
|
2012-11-26 18:30:17 -08:00
|
|
|
class StateOp;
|
|
|
|
|
2010-09-28 19:09:36 -07:00
|
|
|
/**
|
2014-01-01 14:45:21 -08:00
|
|
|
* Records drawing commands in a display list for later playback into an OpenGLRenderer.
|
2010-09-28 19:09:36 -07:00
|
|
|
*/
|
2015-04-20 13:34:45 -07:00
|
|
|
class ANDROID_API DisplayListCanvas: public Canvas, public CanvasStateClient {
|
2010-09-28 19:09:36 -07:00
|
|
|
public:
|
2015-04-20 13:34:45 -07:00
|
|
|
DisplayListCanvas();
|
|
|
|
virtual ~DisplayListCanvas();
|
2010-09-28 19:09:36 -07:00
|
|
|
|
2014-08-21 17:41:57 -07:00
|
|
|
void insertReorderBarrier(bool enableReorder);
|
|
|
|
|
2014-06-23 13:13:08 -07:00
|
|
|
DisplayListData* finishRecording();
|
2011-01-05 18:01:22 -08:00
|
|
|
|
2013-12-30 15:32:54 -08:00
|
|
|
// ----------------------------------------------------------------------------
|
2014-12-09 15:03:44 -05:00
|
|
|
// HWUI Frame state operations
|
2013-12-30 15:32:54 -08:00
|
|
|
// ----------------------------------------------------------------------------
|
2014-12-09 15:03:44 -05:00
|
|
|
|
|
|
|
void prepareDirty(float left, float top, float right, float bottom);
|
|
|
|
void prepare() { prepareDirty(0.0f, 0.0f, width(), height()); }
|
|
|
|
bool finish();
|
|
|
|
void interrupt();
|
|
|
|
void resume();
|
2011-01-10 14:10:36 -08:00
|
|
|
|
2013-12-30 15:32:54 -08:00
|
|
|
// ----------------------------------------------------------------------------
|
2014-12-09 15:03:44 -05:00
|
|
|
// HWUI Canvas state operations
|
2013-12-30 15:32:54 -08:00
|
|
|
// ----------------------------------------------------------------------------
|
2014-10-10 13:38:16 -04:00
|
|
|
|
2014-12-09 15:03:44 -05:00
|
|
|
void setViewport(int width, int height) { mState.setViewport(width, height); }
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2014-10-10 13:38:16 -04:00
|
|
|
const Rect& getRenderTargetClipBounds() const { return mState.getRenderTargetClipBounds(); }
|
2013-12-30 15:32:54 -08:00
|
|
|
|
2014-06-23 13:13:08 -07:00
|
|
|
bool isCurrentTransformSimple() {
|
2014-10-10 13:38:16 -04:00
|
|
|
return mState.currentTransform()->isSimple();
|
2014-06-23 13:13:08 -07:00
|
|
|
}
|
|
|
|
|
2013-12-30 15:32:54 -08:00
|
|
|
// ----------------------------------------------------------------------------
|
2014-12-09 15:03:44 -05:00
|
|
|
// HWUI Canvas draw operations
|
2013-12-30 15:32:54 -08:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Bitmap-based
|
2014-12-09 15:03:44 -05:00
|
|
|
void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
|
|
|
|
// TODO: move drawPatch() to Canvas.h
|
2015-04-15 15:52:10 -07:00
|
|
|
void drawPatch(const SkBitmap& bitmap, const Res_png_9patch* patch,
|
2014-12-09 15:03:44 -05:00
|
|
|
float left, float top, float right, float bottom, const SkPaint* paint);
|
2013-12-30 15:32:54 -08:00
|
|
|
|
|
|
|
// Shapes
|
2014-12-09 15:03:44 -05:00
|
|
|
void drawRects(const float* rects, int count, const SkPaint* paint);
|
|
|
|
void drawRoundRect(CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top,
|
2014-09-15 17:20:08 +02:00
|
|
|
CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom,
|
|
|
|
CanvasPropertyPrimitive* rx, CanvasPropertyPrimitive* ry,
|
|
|
|
CanvasPropertyPaint* paint);
|
2014-12-09 15:03:44 -05:00
|
|
|
void drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
|
2014-05-01 21:27:37 -07:00
|
|
|
CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint);
|
2013-12-30 15:32:54 -08:00
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2013-12-30 15:32:54 -08:00
|
|
|
// ----------------------------------------------------------------------------
|
2014-12-09 15:03:44 -05:00
|
|
|
// HWUI Canvas draw operations - special
|
2013-12-30 15:32:54 -08:00
|
|
|
// ----------------------------------------------------------------------------
|
2014-12-09 15:03:44 -05:00
|
|
|
void drawLayer(DeferredLayerUpdater* layerHandle, float x, float y);
|
2015-04-27 16:41:00 -07:00
|
|
|
void drawRenderNode(RenderNode* renderNode);
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2013-12-30 15:32:54 -08:00
|
|
|
// TODO: rename for consistency
|
2015-04-27 16:41:00 -07:00
|
|
|
void callDrawGLFunction(Functor* functor);
|
2012-01-23 17:09:05 -08:00
|
|
|
|
2014-07-16 15:12:15 -07:00
|
|
|
void setHighContrastText(bool highContrastText) {
|
|
|
|
mHighContrastText = highContrastText;
|
|
|
|
}
|
2014-10-10 13:38:16 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2014-12-09 15:03:44 -05:00
|
|
|
// CanvasStateClient interface
|
2014-10-10 13:38:16 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
2014-12-22 14:28:49 -08:00
|
|
|
virtual void onViewportInitialized() override { }
|
|
|
|
virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) override { }
|
2015-02-27 10:55:28 -08:00
|
|
|
virtual GLuint getTargetFbo() const override { return -1; }
|
2014-10-10 13:38:16 -04:00
|
|
|
|
2014-12-09 15:03:44 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// android/graphics/Canvas interface
|
|
|
|
// ----------------------------------------------------------------------------
|
2014-12-16 08:37:20 -05:00
|
|
|
virtual SkCanvas* asSkCanvas() override;
|
|
|
|
|
2015-04-22 09:04:45 -07:00
|
|
|
virtual void setBitmap(const SkBitmap& bitmap) override {
|
2015-04-20 13:34:45 -07:00
|
|
|
LOG_ALWAYS_FATAL("DisplayListCanvas is not backed by a bitmap.");
|
2014-12-09 15:03:44 -05:00
|
|
|
}
|
|
|
|
|
2015-01-05 15:51:13 -08:00
|
|
|
virtual bool isOpaque() override { return false; }
|
|
|
|
virtual int width() override { return mState.getWidth(); }
|
|
|
|
virtual int height() override { return mState.getHeight(); }
|
2014-12-09 15:03:44 -05:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// android/graphics/Canvas state operations
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Save (layer)
|
2015-01-05 15:51:13 -08:00
|
|
|
virtual int getSaveCount() const override { return mState.getSaveCount(); }
|
|
|
|
virtual int save(SkCanvas::SaveFlags flags) override;
|
|
|
|
virtual void restore() override;
|
|
|
|
virtual void restoreToCount(int saveCount) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
|
|
|
|
virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint,
|
2015-01-05 15:51:13 -08:00
|
|
|
SkCanvas::SaveFlags flags) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
virtual int saveLayerAlpha(float left, float top, float right, float bottom,
|
2015-01-05 15:51:13 -08:00
|
|
|
int alpha, SkCanvas::SaveFlags flags) override {
|
2014-12-09 15:03:44 -05:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAlpha(alpha);
|
|
|
|
return saveLayer(left, top, right, bottom, &paint, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Matrix
|
2015-01-05 15:51:13 -08:00
|
|
|
virtual void getMatrix(SkMatrix* outMatrix) const override { mState.getMatrix(outMatrix); }
|
|
|
|
virtual void setMatrix(const SkMatrix& matrix) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
|
2015-01-05 15:51:13 -08:00
|
|
|
virtual void concat(const SkMatrix& matrix) override;
|
|
|
|
virtual void rotate(float degrees) override;
|
|
|
|
virtual void scale(float sx, float sy) override;
|
|
|
|
virtual void skew(float sx, float sy) override;
|
|
|
|
virtual void translate(float dx, float dy) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
|
|
|
|
// Clip
|
2015-01-05 15:51:13 -08:00
|
|
|
virtual bool getClipBounds(SkRect* outRect) const override;
|
|
|
|
virtual bool quickRejectRect(float left, float top, float right, float bottom) const override;
|
|
|
|
virtual bool quickRejectPath(const SkPath& path) const override;
|
2014-12-09 15:03:44 -05:00
|
|
|
|
2015-01-05 15:51:13 -08:00
|
|
|
virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op) override;
|
|
|
|
virtual bool clipPath(const SkPath* path, SkRegion::Op op) override;
|
|
|
|
virtual bool clipRegion(const SkRegion* region, SkRegion::Op op) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
|
|
|
|
// Misc
|
2015-01-05 15:51:13 -08:00
|
|
|
virtual SkDrawFilter* getDrawFilter() override { return mDrawFilter.get(); }
|
|
|
|
virtual void setDrawFilter(SkDrawFilter* filter) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// android/graphics/Canvas draw operations
|
|
|
|
// ----------------------------------------------------------------------------
|
2015-01-05 15:51:13 -08:00
|
|
|
virtual void drawColor(int color, SkXfermode::Mode mode) override;
|
|
|
|
virtual void drawPaint(const SkPaint& paint) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
|
|
|
|
// Geometry
|
2015-01-05 15:51:13 -08:00
|
|
|
virtual void drawPoint(float x, float y, const SkPaint& paint) override {
|
2014-12-09 15:03:44 -05:00
|
|
|
float points[2] = { x, y };
|
|
|
|
drawPoints(points, 2, paint);
|
|
|
|
}
|
2015-01-05 15:51:13 -08:00
|
|
|
virtual void drawPoints(const float* points, int count, const SkPaint& paint) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
virtual void drawLine(float startX, float startY, float stopX, float stopY,
|
2015-01-05 15:51:13 -08:00
|
|
|
const SkPaint& paint) override {
|
2014-12-09 15:03:44 -05:00
|
|
|
float points[4] = { startX, startY, stopX, stopY };
|
|
|
|
drawLines(points, 4, paint);
|
|
|
|
}
|
2015-01-05 15:51:13 -08:00
|
|
|
virtual void drawLines(const float* points, int count, const SkPaint& paint) override;
|
|
|
|
virtual void drawRect(float left, float top, float right, float bottom, const SkPaint& paint) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
virtual void drawRoundRect(float left, float top, float right, float bottom,
|
2015-01-05 15:51:13 -08:00
|
|
|
float rx, float ry, const SkPaint& paint) override;
|
|
|
|
virtual void drawCircle(float x, float y, float radius, const SkPaint& paint) override;
|
|
|
|
virtual void drawOval(float left, float top, float right, float bottom, const SkPaint& paint) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
virtual void drawArc(float left, float top, float right, float bottom,
|
2015-01-05 15:51:13 -08:00
|
|
|
float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) override;
|
|
|
|
virtual void drawPath(const SkPath& path, const SkPaint& paint) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
|
|
|
|
const float* verts, const float* tex, const int* colors,
|
2015-01-05 15:51:13 -08:00
|
|
|
const uint16_t* indices, int indexCount, const SkPaint& paint) override
|
2015-04-20 13:34:45 -07:00
|
|
|
{ /* DisplayListCanvas does not support drawVertices(); ignore */ }
|
2014-12-09 15:03:44 -05:00
|
|
|
|
|
|
|
// Bitmap-based
|
2015-01-05 15:51:13 -08:00
|
|
|
virtual void drawBitmap(const SkBitmap& bitmap, float left, float top, const SkPaint* paint) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
virtual void drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix,
|
2015-01-05 15:51:13 -08:00
|
|
|
const SkPaint* paint) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
virtual void drawBitmap(const SkBitmap& bitmap, float srcLeft, float srcTop,
|
|
|
|
float srcRight, float srcBottom, float dstLeft, float dstTop,
|
2015-01-05 15:51:13 -08:00
|
|
|
float dstRight, float dstBottom, const SkPaint* paint) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
|
2015-01-05 15:51:13 -08:00
|
|
|
const float* vertices, const int* colors, const SkPaint* paint) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
|
|
|
|
// Text
|
|
|
|
virtual void drawText(const uint16_t* glyphs, const float* positions, int count,
|
|
|
|
const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop,
|
2015-01-05 15:51:13 -08:00
|
|
|
float boundsRight, float boundsBottom, float totalAdvance) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
virtual void drawPosText(const uint16_t* text, const float* positions, int count,
|
2015-01-05 15:51:13 -08:00
|
|
|
int posCount, const SkPaint& paint) override;
|
2014-12-09 15:03:44 -05:00
|
|
|
virtual void drawTextOnPath(const uint16_t* glyphs, int count, const SkPath& path,
|
2015-01-05 15:51:13 -08:00
|
|
|
float hOffset, float vOffset, const SkPaint& paint) override;
|
|
|
|
virtual bool drawTextAbsolutePos() const override { return false; }
|
2014-12-09 15:03:44 -05:00
|
|
|
|
|
|
|
|
2010-09-26 18:40:37 -07:00
|
|
|
private:
|
2014-10-10 13:38:16 -04:00
|
|
|
|
|
|
|
CanvasState mState;
|
2014-12-16 08:37:20 -05:00
|
|
|
std::unique_ptr<SkiaCanvasProxy> mSkiaCanvasProxy;
|
2014-10-10 13:38:16 -04:00
|
|
|
|
2014-08-21 17:41:57 -07:00
|
|
|
enum DeferredBarrierType {
|
|
|
|
kBarrier_None,
|
|
|
|
kBarrier_InOrder,
|
|
|
|
kBarrier_OutOfOrder,
|
|
|
|
};
|
|
|
|
|
|
|
|
void flushRestoreToCount();
|
|
|
|
void flushTranslate();
|
|
|
|
void flushReorderBarrier();
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
LinearAllocator& alloc() { return mDisplayListData->allocator; }
|
2014-08-08 18:42:51 -07:00
|
|
|
|
|
|
|
// Each method returns final index of op
|
2014-08-21 17:41:57 -07:00
|
|
|
size_t addOpAndUpdateChunk(DisplayListOp* op);
|
|
|
|
// flushes any deferred operations, and appends the op
|
|
|
|
size_t flushAndAddOp(DisplayListOp* op);
|
|
|
|
|
|
|
|
size_t addStateOp(StateOp* op);
|
|
|
|
size_t addDrawOp(DrawOp* op);
|
|
|
|
size_t addRenderNodeOp(DrawRenderNodeOp* op);
|
|
|
|
|
2015-06-09 13:12:40 -07:00
|
|
|
void refBitmapsInShader(const SkShader* shader);
|
2010-09-26 18:40:37 -07:00
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
template<class T>
|
2014-01-02 17:13:34 -08:00
|
|
|
inline const T* refBuffer(const T* srcBuffer, int32_t count) {
|
2014-12-22 14:28:49 -08:00
|
|
|
if (!srcBuffer) return nullptr;
|
2014-01-02 17:13:34 -08:00
|
|
|
|
2012-11-26 18:30:17 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
inline const SkPath* refPath(const SkPath* path) {
|
2014-12-22 14:28:49 -08:00
|
|
|
if (!path) return nullptr;
|
2011-02-03 15:06:05 -08:00
|
|
|
|
2015-02-12 14:10:21 -05:00
|
|
|
// The points/verbs within the path are refcounted so this copy operation
|
|
|
|
// is inexpensive and maintains the generationID of the original path.
|
|
|
|
const SkPath* cachedPath = new SkPath(*path);
|
|
|
|
mDisplayListData->pathResources.add(cachedPath);
|
2014-12-22 17:16:56 -08:00
|
|
|
return cachedPath;
|
2010-09-26 18:40:37 -07:00
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
inline const SkPaint* refPaint(const SkPaint* paint) {
|
2014-12-22 14:28:49 -08:00
|
|
|
if (!paint) return nullptr;
|
2010-11-08 12:08:41 -08:00
|
|
|
|
2014-10-15 09:21:10 -04:00
|
|
|
// If there is a draw filter apply it here and store the modified paint
|
|
|
|
// so that we don't need to modify the paint every time we access it.
|
2014-11-21 22:05:46 +00:00
|
|
|
SkTLazy<SkPaint> filteredPaint;
|
2014-10-15 09:21:10 -04:00
|
|
|
if (mDrawFilter.get()) {
|
2015-03-25 10:08:30 -04:00
|
|
|
filteredPaint.set(*paint);
|
2014-12-22 17:16:56 -08:00
|
|
|
mDrawFilter->filter(filteredPaint.get(), SkDrawFilter::kPaint_Type);
|
2015-03-25 10:08:30 -04:00
|
|
|
paint = filteredPaint.get();
|
2014-10-15 09:21:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// compute the hash key for the paint and check the cache.
|
|
|
|
const uint32_t key = paint->getHash();
|
|
|
|
const SkPaint* cachedPaint = mPaintMap.valueFor(key);
|
|
|
|
// In the unlikely event that 2 unique paints have the same hash we do a
|
|
|
|
// object equality check to ensure we don't erroneously dedup them.
|
2014-12-22 14:28:49 -08:00
|
|
|
if (cachedPaint == nullptr || *cachedPaint != *paint) {
|
2014-12-22 17:16:56 -08:00
|
|
|
cachedPaint = new SkPaint(*paint);
|
|
|
|
std::unique_ptr<const SkPaint> copy(cachedPaint);
|
|
|
|
mDisplayListData->paints.push_back(std::move(copy));
|
|
|
|
|
2012-02-21 18:32:32 -08:00
|
|
|
// replaceValueFor() performs an add if the entry doesn't exist
|
2014-10-15 09:21:10 -04:00
|
|
|
mPaintMap.replaceValueFor(key, cachedPaint);
|
2015-06-09 13:12:40 -07:00
|
|
|
refBitmapsInShader(cachedPaint->getShader());
|
2010-10-25 15:47:32 -07:00
|
|
|
}
|
2010-11-08 12:08:41 -08:00
|
|
|
|
2014-10-15 09:21:10 -04:00
|
|
|
return cachedPaint;
|
2010-11-08 12:08:41 -08:00
|
|
|
}
|
|
|
|
|
2014-07-16 15:12:15 -07:00
|
|
|
inline SkPaint* copyPaint(const SkPaint* paint) {
|
2014-12-22 14:28:49 -08:00
|
|
|
if (!paint) return nullptr;
|
2014-07-16 15:12:15 -07:00
|
|
|
|
2014-12-22 17:16:56 -08:00
|
|
|
SkPaint* returnPaint = new SkPaint(*paint);
|
|
|
|
std::unique_ptr<const SkPaint> copy(returnPaint);
|
|
|
|
mDisplayListData->paints.push_back(std::move(copy));
|
|
|
|
|
|
|
|
return returnPaint;
|
2014-07-16 15:12:15 -07:00
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
inline const SkRegion* refRegion(const SkRegion* region) {
|
2012-12-03 12:34:51 -08:00
|
|
|
if (!region) {
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
2014-12-22 17:16:56 -08:00
|
|
|
const SkRegion* cachedRegion = mRegionMap.valueFor(region);
|
2012-12-03 12:34:51 -08:00
|
|
|
// TODO: Add generation ID to SkRegion
|
2014-12-22 17:16:56 -08:00
|
|
|
if (cachedRegion == nullptr) {
|
|
|
|
std::unique_ptr<const SkRegion> copy(new SkRegion(*region));
|
|
|
|
cachedRegion = copy.get();
|
|
|
|
mDisplayListData->regions.push_back(std::move(copy));
|
|
|
|
|
2012-12-03 12:34:51 -08:00
|
|
|
// replaceValueFor() performs an add if the entry doesn't exist
|
2014-12-22 17:16:56 -08:00
|
|
|
mRegionMap.replaceValueFor(region, cachedRegion);
|
2012-12-03 12:34:51 -08:00
|
|
|
}
|
|
|
|
|
2014-12-22 17:16:56 -08:00
|
|
|
return cachedRegion;
|
2012-12-03 12:34:51 -08:00
|
|
|
}
|
|
|
|
|
2015-04-15 15:52:10 -07:00
|
|
|
inline const SkBitmap* refBitmap(const 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.
|
2015-05-07 13:50:55 -07:00
|
|
|
SkBitmap* localBitmap = new (alloc()) SkBitmap(bitmap);
|
2015-05-07 13:14:15 -07:00
|
|
|
alloc().autoDestroy(localBitmap);
|
|
|
|
mDisplayListData->bitmapResources.push_back(localBitmap);
|
|
|
|
return localBitmap;
|
2012-05-15 11:10:01 -07:00
|
|
|
}
|
|
|
|
|
2014-01-02 17:13:34 -08:00
|
|
|
inline const Res_png_9patch* refPatch(const Res_png_9patch* patch) {
|
2014-02-26 11:00:11 -08:00
|
|
|
mDisplayListData->patchResources.add(patch);
|
2014-11-06 09:45:10 -08:00
|
|
|
mResourceCache.incrementRefcount(patch);
|
2013-06-26 15:45:41 -07:00
|
|
|
return patch;
|
|
|
|
}
|
|
|
|
|
2014-10-15 09:21:10 -04:00
|
|
|
DefaultKeyedVector<uint32_t, const SkPaint*> mPaintMap;
|
2014-01-02 17:13:34 -08:00
|
|
|
DefaultKeyedVector<const SkPath*, const SkPath*> mPathMap;
|
|
|
|
DefaultKeyedVector<const SkRegion*, const SkRegion*> mRegionMap;
|
2011-01-14 15:31:00 -08:00
|
|
|
|
2014-11-06 09:45:10 -08:00
|
|
|
ResourceCache& mResourceCache;
|
2014-02-26 11:00:11 -08:00
|
|
|
DisplayListData* mDisplayListData;
|
2012-09-07 11:58:36 -07:00
|
|
|
|
2012-02-16 19:24:51 -08:00
|
|
|
float mTranslateX;
|
|
|
|
float mTranslateY;
|
2014-08-21 17:41:57 -07:00
|
|
|
bool mHasDeferredTranslate;
|
|
|
|
DeferredBarrierType mDeferredBarrierType;
|
2014-07-16 15:12:15 -07:00
|
|
|
bool mHighContrastText;
|
2012-09-27 17:55:46 -07:00
|
|
|
|
2014-03-05 16:37:35 -08:00
|
|
|
int mRestoreSaveCount;
|
|
|
|
|
2014-10-15 09:21:10 -04:00
|
|
|
SkAutoTUnref<SkDrawFilter> mDrawFilter;
|
|
|
|
|
2014-03-12 13:56:30 -07:00
|
|
|
friend class RenderNode;
|
2010-09-28 19:09:36 -07:00
|
|
|
|
2015-04-20 13:34:45 -07:00
|
|
|
}; // class DisplayListCanvas
|
2010-09-26 18:40:37 -07:00
|
|
|
|
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
|