Separate interface definition and implementation of Snapshot
The Snapshot class is getting complicated enough that its implementation
should now live in a separate .cpp file. This will become particularly
useful when support for clip regions and paths will be added later on.
Change-Id: I050fac5683a9f7a0ff2f7a6beec3dd28aa5eb0d8
diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h
index aff7b93..c94af7e 100644
--- a/libs/hwui/Snapshot.h
+++ b/libs/hwui/Snapshot.h
@@ -23,7 +23,7 @@
#include <utils/RefBase.h>
#include <ui/Region.h>
-#include <SkCanvas.h>
+#include <SkRegion.h>
#include "Layer.h"
#include "Matrix.h"
@@ -43,43 +43,12 @@
*/
class Snapshot: public LightRefBase<Snapshot> {
public:
- Snapshot(): flags(0), previous(NULL), layer(NULL), fbo(0), invisible(false), empty(false) {
- transform = &mTransformRoot;
- clipRect = &mClipRectRoot;
- region = NULL;
- }
+
+ Snapshot();
+ Snapshot(const sp<Snapshot>& s, int saveFlags);
/**
- * Copies the specified snapshot/ The specified snapshot is stored as
- * the previous snapshot.
- */
- Snapshot(const sp<Snapshot>& s, int saveFlags):
- flags(0), previous(s), layer(NULL), fbo(s->fbo),
- invisible(s->invisible), empty(false), viewport(s->viewport), height(s->height) {
- if (saveFlags & SkCanvas::kMatrix_SaveFlag) {
- mTransformRoot.load(*s->transform);
- transform = &mTransformRoot;
- } else {
- transform = s->transform;
- }
-
- if (saveFlags & SkCanvas::kClip_SaveFlag) {
- mClipRectRoot.set(*s->clipRect);
- clipRect = &mClipRectRoot;
- } else {
- clipRect = s->clipRect;
- }
-
- if (s->flags & Snapshot::kFlagFboTarget) {
- flags |= Snapshot::kFlagFboTarget;
- region = s->region;
- } else {
- region = NULL;
- }
- }
-
- /**
- * Various flags set on #flags.
+ * Various flags set on ::flags.
*/
enum Flags {
/**
@@ -115,87 +84,41 @@
* by this snapshot's trasnformation.
*/
bool clip(float left, float top, float right, float bottom,
- SkRegion::Op op = SkRegion::kIntersect_Op) {
- Rect r(left, top, right, bottom);
- transform->mapRect(r);
- return clipTransformed(r, op);
- }
+ SkRegion::Op op = SkRegion::kIntersect_Op);
/**
* Modifies the current clip with the new clip rectangle and
* the specified operation. The specified rectangle is considered
* already transformed.
*/
- bool clipTransformed(const Rect& r, SkRegion::Op op = SkRegion::kIntersect_Op) {
- bool clipped = false;
-
- // NOTE: The unimplemented operations require support for regions
- // Supporting regions would require using a stencil buffer instead
- // of the scissor. The stencil buffer itself is not too expensive
- // (memory cost excluded) but on fillrate limited devices, managing
- // the stencil might have a negative impact on the framerate.
- switch (op) {
- case SkRegion::kDifference_Op:
- break;
- case SkRegion::kIntersect_Op:
- clipped = clipRect->intersect(r);
- if (!clipped) {
- clipRect->setEmpty();
- clipped = true;
- }
- break;
- case SkRegion::kUnion_Op:
- clipped = clipRect->unionWith(r);
- break;
- case SkRegion::kXOR_Op:
- break;
- case SkRegion::kReverseDifference_Op:
- break;
- case SkRegion::kReplace_Op:
- clipRect->set(r);
- clipped = true;
- break;
- }
-
- if (clipped) {
- flags |= Snapshot::kFlagClipSet;
- }
-
- return clipped;
- }
+ bool clipTransformed(const Rect& r, SkRegion::Op op = SkRegion::kIntersect_Op);
/**
* Sets the current clip.
*/
- void setClip(float left, float top, float right, float bottom) {
- clipRect->set(left, top, right, bottom);
- flags |= Snapshot::kFlagClipSet;
- }
+ void setClip(float left, float top, float right, float bottom);
- const Rect& getLocalClip() {
- mat4 inverse;
- inverse.loadInverse(*transform);
+ /**
+ * Returns the current clip in local coordinates. The clip rect is
+ * transformed by the inverse transform matrix.
+ */
+ const Rect& getLocalClip();
- mLocalClip.set(*clipRect);
- inverse.mapRect(mLocalClip);
+ /**
+ * Resets the clip to the specified rect.
+ */
+ void resetClip(float left, float top, float right, float bottom);
- return mLocalClip;
- }
+ /**
+ * Resets the current transform to a pure 3D translation.
+ */
+ void resetTransform(float x, float y, float z);
- void resetTransform(float x, float y, float z) {
- transform = &mTransformRoot;
- transform->loadTranslate(x, y, z);
- }
-
- void resetClip(float left, float top, float right, float bottom) {
- clipRect = &mClipRectRoot;
- clipRect->set(left, top, right, bottom);
- flags |= Snapshot::kFlagClipSet;
- }
-
- bool isIgnored() const {
- return invisible || empty;
- }
+ /**
+ * Indicates whether this snapshot should be ignored. A snapshot
+ * is typicalled ignored if its layer is invisible or empty.
+ */
+ bool isIgnored() const;
/**
* Dirty flags.
@@ -209,6 +132,8 @@
/**
* Only set when the flag kFlagIsLayer is set.
+ *
+ * This snapshot does not own the layer, this pointer must not be freed.
*/
Layer* layer;
@@ -249,17 +174,26 @@
/**
* Local transformation. Holds the current translation, scale and
* rotation values.
+ *
+ * This is a reference to a matrix owned by this snapshot or another
+ * snapshot. This pointer must not be freed. See ::mTransformRoot.
*/
mat4* transform;
/**
* Current clip region. The clip is stored in canvas-space coordinates,
* (screen-space coordinates in the regular case.)
+ *
+ * This is a reference to a rect owned by this snapshot or another
+ * snapshot. This pointer must not be freed. See ::mClipRectRoot.
*/
Rect* clipRect;
/**
* The ancestor layer's dirty region.
+ *
+ * This is a reference to a region owned by a layer. This pointer must
+ * not be freed.
*/
Region* region;