summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/graphics/android/context
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2012-07-19 13:01:13 -0700
committerJohn Reck <jreck@google.com>2012-07-19 13:04:23 -0700
commit6fda3e621352a695b3b6a02c6008d372b7c6febc (patch)
tree88b9f79255b25157b408874105e92540f0d88dd0 /Source/WebCore/platform/graphics/android/context
parenteb8e22896b89fd99a56a0e70888838ca22a558cf (diff)
downloadexternal_webkit-6fda3e621352a695b3b6a02c6008d372b7c6febc.zip
external_webkit-6fda3e621352a695b3b6a02c6008d372b7c6febc.tar.gz
external_webkit-6fda3e621352a695b3b6a02c6008d372b7c6febc.tar.bz2
Support beginTransparentLayer
Handle it the same as a save/restore, but split up the SkMatrix handling as beginTransparentLayer does not save the matrix Also, enable RecordingContext by default, as all major known issues should be fixed now. Change-Id: I414556f65d5de704e2ce18e44a87d932b937993b
Diffstat (limited to 'Source/WebCore/platform/graphics/android/context')
-rw-r--r--Source/WebCore/platform/graphics/android/context/GraphicsOperation.h49
-rw-r--r--Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp69
-rw-r--r--Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h8
3 files changed, 69 insertions, 57 deletions
diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h b/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h
index 9ecf5c5..fc3b8bc 100644
--- a/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h
+++ b/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h
@@ -51,10 +51,8 @@ class Operation {
public:
typedef enum { UndefinedOperation
// State management
- , BeginTransparencyLayerOperation
- , EndTransparencyLayerOperation
+ , TransparencyLayerOperation
, SaveOperation
- , RestoreOperation
// State setters
, SetAlphaOperation
, SetCompositeOpOperation
@@ -124,10 +122,8 @@ public:
switch (type()) {
TYPE_CASE(UndefinedOperation)
// State management
- TYPE_CASE(BeginTransparencyLayerOperation)
- TYPE_CASE(EndTransparencyLayerOperation)
+ TYPE_CASE(TransparencyLayerOperation)
TYPE_CASE(SaveOperation)
- TYPE_CASE(RestoreOperation)
// State setters
TYPE_CASE(SetAlphaOperation)
TYPE_CASE(SetCompositeOpOperation)
@@ -180,28 +176,9 @@ public:
// State management
//**************************************
-class BeginTransparencyLayer : public Operation {
-public:
- BeginTransparencyLayer(const float opacity) : m_opacity(opacity) {}
- virtual bool applyImpl(PlatformGraphicsContext* context) {
- context->beginTransparencyLayer(m_opacity);
- return true;
- }
- virtual OperationType type() { return BeginTransparencyLayerOperation; }
-private:
- float m_opacity;
-};
-class EndTransparencyLayer : public Operation {
-public:
- EndTransparencyLayer() {}
- virtual bool applyImpl(PlatformGraphicsContext* context) {
- context->endTransparencyLayer();
- return true;
- }
- virtual OperationType type() { return EndTransparencyLayerOperation; }
-};
class Save : public Operation {
public:
+ Save() : m_saveMatrix(true) {}
virtual bool applyImpl(PlatformGraphicsContext* context) {
context->save();
m_operations.apply(context);
@@ -210,9 +187,27 @@ public:
}
virtual OperationType type() { return SaveOperation; }
GraphicsOperationCollection* operations() { return &m_operations; }
+ bool saveMatrix() { return m_saveMatrix; }
FloatRect bounds;
-private:
+protected:
GraphicsOperationCollection m_operations;
+ bool m_saveMatrix : 1;
+};
+
+class TransparencyLayer : public Save {
+public:
+ TransparencyLayer(const float opacity) : m_opacity(opacity) {
+ m_saveMatrix = false;
+ }
+ virtual bool applyImpl(PlatformGraphicsContext* context) {
+ context->beginTransparencyLayer(m_opacity);
+ m_operations.apply(context);
+ context->endTransparencyLayer();
+ return true;
+ }
+ virtual OperationType type() { return TransparencyLayerOperation; }
+private:
+ float m_opacity;
};
//**************************************
diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp
index ba7f1a9..df0ffd6 100644
--- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp
+++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp
@@ -159,12 +159,11 @@ void Recording::setRecording(RecordingImpl* impl)
PlatformGraphicsContextRecording::PlatformGraphicsContextRecording(Recording* recording)
: PlatformGraphicsContext()
, mPicture(0)
- , mCurrentMatrix(&mRootMatrix)
, mRecording(recording)
, mOperationState(0)
, mOperationMatrix(0)
{
- mRootMatrix.setIdentity();
+ pushMatrix();
if (mRecording)
mRecording->setRecording(new RecordingImpl());
}
@@ -191,42 +190,30 @@ void PlatformGraphicsContextRecording::endRecording(const SkRect& bounds)
mPicture = 0;
}
-
//**************************************
// State management
//**************************************
void PlatformGraphicsContextRecording::beginTransparencyLayer(float opacity)
{
- appendStateOperation(new GraphicsOperation::BeginTransparencyLayer(opacity));
+ pushSaveOperation(new GraphicsOperation::TransparencyLayer(opacity));
}
void PlatformGraphicsContextRecording::endTransparencyLayer()
{
- appendStateOperation(new GraphicsOperation::EndTransparencyLayer());
+ popSaveOperation();
}
void PlatformGraphicsContextRecording::save()
{
PlatformGraphicsContext::save();
- mRecordingStateStack.append(new GraphicsOperation::Save());
- mCurrentMatrix = &(mRecordingStateStack.last().mMatrix);
- mCurrentMatrix->setIdentity();
+ pushSaveOperation(new GraphicsOperation::Save());
}
void PlatformGraphicsContextRecording::restore()
{
PlatformGraphicsContext::restore();
- RecordingState state = mRecordingStateStack.last();
- mRecordingStateStack.removeLast();
- if (mRecordingStateStack.size())
- mCurrentMatrix = &(mRecordingStateStack.last().mMatrix);
- else
- mCurrentMatrix = &mRootMatrix;
- if (state.mHasDrawing)
- appendDrawingOperation(state.mSaveOperation, state.mBounds);
- else
- delete state.mSaveOperation;
+ popSaveOperation();
}
//**************************************
@@ -366,13 +353,10 @@ void PlatformGraphicsContextRecording::translate(float x, float y)
const SkMatrix& PlatformGraphicsContextRecording::getTotalMatrix()
{
// Each RecordingState tracks the delta from its "parent" SkMatrix
- if (mRecordingStateStack.size()) {
- mTotalMatrix = mRootMatrix;
- for (size_t i = 0; i < mRecordingStateStack.size(); i++)
- mTotalMatrix.preConcat(mRecordingStateStack[i].mMatrix);
- return mTotalMatrix;
- }
- return mRootMatrix;
+ mTotalMatrix = mMatrixStack.first();
+ for (size_t i = 1; i < mMatrixStack.size(); i++)
+ mTotalMatrix.preConcat(mMatrixStack[i]);
+ return mTotalMatrix;
}
//**************************************
@@ -577,6 +561,37 @@ void PlatformGraphicsContextRecording::clipState(const FloatRect& clip)
}
}
+void PlatformGraphicsContextRecording::pushSaveOperation(GraphicsOperation::Save* saveOp)
+{
+ mRecordingStateStack.append(saveOp);
+ if (saveOp->saveMatrix())
+ pushMatrix();
+}
+
+void PlatformGraphicsContextRecording::popSaveOperation()
+{
+ RecordingState state = mRecordingStateStack.last();
+ mRecordingStateStack.removeLast();
+ if (state.mSaveOperation->saveMatrix())
+ popMatrix();
+ if (state.mHasDrawing)
+ appendDrawingOperation(state.mSaveOperation, state.mBounds);
+ else
+ delete state.mSaveOperation;
+}
+
+void PlatformGraphicsContextRecording::pushMatrix()
+{
+ mMatrixStack.append(SkMatrix::I());
+ mCurrentMatrix = &(mMatrixStack.last());
+}
+
+void PlatformGraphicsContextRecording::popMatrix()
+{
+ mMatrixStack.removeLast();
+ mCurrentMatrix = &(mMatrixStack.last());
+}
+
void PlatformGraphicsContextRecording::appendDrawingOperation(
GraphicsOperation::Operation* operation, const FloatRect& untranslatedBounds)
{
@@ -596,7 +611,7 @@ void PlatformGraphicsContextRecording::appendDrawingOperation(
if (!mOperationState)
mOperationState = mRecording->recording()->getState(m_state);
if (!mOperationMatrix)
- mOperationMatrix = mRecording->recording()->cloneMatrix(mRootMatrix);
+ mOperationMatrix = mRecording->recording()->cloneMatrix(mMatrixStack.first());
operation->m_state = mOperationState;
operation->m_matrix = mOperationMatrix;
RecordingData* data = new RecordingData(operation, mRecording->recording()->m_nodeCount++);
@@ -617,7 +632,7 @@ void PlatformGraphicsContextRecording::appendStateOperation(GraphicsOperation::O
void PlatformGraphicsContextRecording::onCurrentMatrixChanged()
{
- if (mCurrentMatrix == &mRootMatrix)
+ if (mCurrentMatrix == &(mMatrixStack.first()))
mOperationMatrix = 0;
}
diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h
index 3affff3..6c51852 100644
--- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h
+++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h
@@ -146,9 +146,12 @@ private:
void appendDrawingOperation(GraphicsOperation::Operation* operation, const FloatRect& bounds);
void appendStateOperation(GraphicsOperation::Operation* operation);
void onCurrentMatrixChanged();
+ void pushSaveOperation(GraphicsOperation::Save* saveOp);
+ void popSaveOperation();
+ void pushMatrix();
+ void popMatrix();
SkPicture* mPicture;
- SkMatrix mRootMatrix;
SkMatrix* mCurrentMatrix;
// Used for getTotalMatrix, is not valid elsewhere
SkMatrix mTotalMatrix;
@@ -167,7 +170,6 @@ private:
, mHasDrawing(other.mHasDrawing)
, mHasClip(other.mHasClip)
, mBounds(other.mBounds)
- , mMatrix(other.mMatrix)
{}
void addBounds(const FloatRect& bounds)
@@ -187,9 +189,9 @@ private:
bool mHasDrawing;
bool mHasClip;
FloatRect mBounds;
- SkMatrix mMatrix;
};
Vector<RecordingState> mRecordingStateStack;
+ Vector<SkMatrix> mMatrixStack;
State* mOperationState;
SkMatrix* mOperationMatrix;
};