summaryrefslogtreecommitdiff
path: root/libs/hwui/CanvasState.h
diff options
context:
space:
mode:
author John Reck <jreck@google.com> 2015-10-06 10:06:37 -0700
committer John Reck <jreck@google.com> 2015-10-06 10:24:07 -0700
commitd9ee550888011a64fa3f35e666360ec8278597d8 (patch)
tree12667bdaf346542c6445153167cd58360c218706 /libs/hwui/CanvasState.h
parent9ad05de29eb0320d9e3c64da7c469822ecd984d9 (diff)
Reduce, reuse, recycle SNAPSHOTS!
Shaves like, 1 whole us off of reset Change-Id: I459370448583d5e22fd302ba1353319564a814be
Diffstat (limited to 'libs/hwui/CanvasState.h')
-rw-r--r--libs/hwui/CanvasState.h24
1 files changed, 17 insertions, 7 deletions
diff --git a/libs/hwui/CanvasState.h b/libs/hwui/CanvasState.h
index f0fb9ba8b324..be57f44210ef 100644
--- a/libs/hwui/CanvasState.h
+++ b/libs/hwui/CanvasState.h
@@ -17,12 +17,12 @@
#ifndef ANDROID_HWUI_CANVAS_STATE_H
#define ANDROID_HWUI_CANVAS_STATE_H
+#include "Snapshot.h"
+
#include <SkMatrix.h>
#include <SkPath.h>
#include <SkRegion.h>
-#include "Snapshot.h"
-
namespace android {
namespace uirenderer {
@@ -74,6 +74,7 @@ public:
class CanvasState {
public:
CanvasState(CanvasStateClient& renderer);
+ ~CanvasState();
/**
* Initializes the first snapshot, computing the projection matrix,
@@ -157,11 +158,15 @@ public:
int getHeight() const { return mHeight; }
bool clipIsSimple() const { return currentSnapshot()->clipIsSimple(); }
- inline const Snapshot* currentSnapshot() const { return mSnapshot.get(); }
- inline Snapshot* writableSnapshot() { return mSnapshot.get(); }
- inline const Snapshot* firstSnapshot() const { return mFirstSnapshot.get(); }
+ inline const Snapshot* currentSnapshot() const { return mSnapshot; }
+ inline Snapshot* writableSnapshot() { return mSnapshot; }
+ inline const Snapshot* firstSnapshot() const { return &mFirstSnapshot; }
private:
+ Snapshot* allocSnapshot(Snapshot* previous, int savecount);
+ void freeSnapshot(Snapshot* snapshot);
+ void freeAllSnapshots();
+
/// indicates that the clip has been changed since the last time it was consumed
bool mDirtyClip;
@@ -172,13 +177,18 @@ private:
int mSaveCount;
/// Base state
- sp<Snapshot> mFirstSnapshot;
+ Snapshot mFirstSnapshot;
/// Host providing callbacks
CanvasStateClient& mCanvas;
/// Current state
- sp<Snapshot> mSnapshot;
+ Snapshot* mSnapshot;
+
+ // Pool of allocated snapshots to re-use
+ // NOTE: The dtors have already been invoked!
+ Snapshot* mSnapshotPool = nullptr;
+ int mSnapshotPoolCount = 0;
}; // class CanvasState