Add skia to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16 0039d316-1c4b-4281-b951-d872f2087c98
Esse commit está contido em:
@@ -0,0 +1,23 @@
|
||||
This is a copy of the Skia source tree. In the original repository, the include
|
||||
directories and the "corecg" directories are separated out. On top of
|
||||
libs/graphics -> skia
|
||||
we have the following mappings from source repository to our tree:
|
||||
include/corecg -> skia/include/corecg
|
||||
include/graphics -> skia/include
|
||||
libs/corecg -> skia/corecg
|
||||
|
||||
platform/* are our own files that provide extra functionality we need our
|
||||
Skia to implement.
|
||||
|
||||
DO NOT CHANGE THE SKIA FILES IN OUR TREE. These will be overwritten when we
|
||||
sync to newer versions of Skia. The exception is platform/
|
||||
|
||||
THE EXCEPTION IS include/corecg/SkUserConfig.h which are the application's
|
||||
definition of its options and environment. This file must be manually merged
|
||||
with any changes in the Skia tree so that our options are preserved and we
|
||||
also pick up any important changes they make.
|
||||
|
||||
-- brettw@google.com, 28 December 2006
|
||||
|
||||
Patches we are tracking locally (until Skia is fixed upstream):
|
||||
fix_for_1186198.diff -- eseidel, 6/4/08, BUG=1186198
|
||||
@@ -0,0 +1,195 @@
|
||||
# Copyright 2008, Google Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Import('env')
|
||||
|
||||
env = env.Clone()
|
||||
|
||||
env.Prepend(
|
||||
CPPPATH = [
|
||||
'include',
|
||||
'include/corecg',
|
||||
'corecg',
|
||||
'sgl',
|
||||
'picture',
|
||||
'#..',
|
||||
],
|
||||
)
|
||||
|
||||
env.Append(
|
||||
CPPDEFINES = [
|
||||
'SKIA_DISABLE_SUPPORT_FOR_DECODERS',
|
||||
],
|
||||
|
||||
CCFLAGS = [
|
||||
'/TP',
|
||||
|
||||
'/wd4244',
|
||||
'/wd4267',
|
||||
'/wd4345',
|
||||
'/wd4390',
|
||||
'/wd4554',
|
||||
'/wd4800',
|
||||
'/wd4503',
|
||||
'/wd4819',
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
input_files = [
|
||||
'animator/SkTime.cpp',
|
||||
'corecg/Sk64.cpp',
|
||||
'corecg/SkBuffer.cpp',
|
||||
'corecg/SkChunkAlloc.cpp',
|
||||
'corecg/SkCordic.cpp',
|
||||
'corecg/SkDebug.cpp',
|
||||
'corecg/SkDebug_stdio.cpp',
|
||||
'corecg/SkFloat.cpp',
|
||||
'corecg/SkInterpolator.cpp',
|
||||
'corecg/SkMath.cpp',
|
||||
'corecg/SkMatrix.cpp',
|
||||
'corecg/SkMemory_stdlib.cpp',
|
||||
'corecg/SkPoint.cpp',
|
||||
'corecg/SkRect.cpp',
|
||||
'corecg/SkRegion.cpp',
|
||||
'effects/Sk1DPathEffect.cpp',
|
||||
'effects/Sk2DPathEffect.cpp',
|
||||
'effects/SkAvoidXfermode.cpp',
|
||||
'effects/SkBlurDrawLooper.cpp',
|
||||
'effects/SkBlurMask.cpp',
|
||||
'effects/SkBlurMaskFilter.cpp',
|
||||
'effects/SkCamera.cpp',
|
||||
'effects/SkColorFilters.cpp',
|
||||
'effects/SkColorMatrix.cpp',
|
||||
'effects/SkColorMatrixFilter.cpp',
|
||||
'effects/SkCornerPathEffect.cpp',
|
||||
'effects/SkCullPoints.cpp',
|
||||
'effects/SkDashPathEffect.cpp',
|
||||
'effects/SkDiscretePathEffect.cpp',
|
||||
'effects/SkEmbossMask.cpp',
|
||||
'effects/SkEmbossMaskFilter.cpp',
|
||||
'effects/SkGradientShader.cpp',
|
||||
'effects/SkKernel33MaskFilter.cpp',
|
||||
'effects/SkLayerRasterizer.cpp',
|
||||
'effects/SkPaintFlagsDrawFilter.cpp',
|
||||
'effects/SkPixelXorXfermode.cpp',
|
||||
'effects/SkShaderExtras.cpp',
|
||||
'effects/SkTransparentShader.cpp',
|
||||
'effects/SkUnitMappers.cpp',
|
||||
'images/SkImageDecoder.cpp',
|
||||
'images/SkImageRef.cpp',
|
||||
'images/SkStream.cpp',
|
||||
'images/SkStream.cpp',
|
||||
'picture/SkPictureFlat.cpp',
|
||||
'picture/SkPicturePlayback.cpp',
|
||||
'picture/SkPictureRecord.cpp',
|
||||
'ports/SkFontHost_none.cpp',
|
||||
'ports/SkGlobals_global.cpp',
|
||||
'ports/SkImageDecoder_Factory.cpp',
|
||||
'ports/SkOSFile_stdio.cpp',
|
||||
'ports/SkThread_win.cpp',
|
||||
'sgl/SkAlphaRuns.cpp',
|
||||
'sgl/SkBitmap.cpp',
|
||||
'sgl/SkBitmapProcShader.cpp',
|
||||
'sgl/SkBitmapProcState.cpp',
|
||||
'sgl/SkBitmapProcState_matrixProcs.cpp',
|
||||
'sgl/SkBitmapSampler.cpp',
|
||||
'sgl/SkBitmapShader.cpp',
|
||||
'sgl/SkBlitRow_D16.cpp',
|
||||
'sgl/SkBlitRow_D4444.cpp',
|
||||
'sgl/SkBlitter.cpp',
|
||||
'sgl/SkBlitter_4444.cpp',
|
||||
'sgl/SkBlitter_A1.cpp',
|
||||
'sgl/SkBlitter_A8.cpp',
|
||||
'sgl/SkBlitter_ARGB32.cpp',
|
||||
'sgl/SkBlitter_RGB16.cpp',
|
||||
'sgl/SkBlitter_Sprite.cpp',
|
||||
'sgl/SkCanvas.cpp',
|
||||
'sgl/SkColor.cpp',
|
||||
'sgl/SkColorFilter.cpp',
|
||||
'sgl/SkColorTable.cpp',
|
||||
'sgl/SkDeque.cpp',
|
||||
'sgl/SkDevice.cpp',
|
||||
'sgl/SkDither.cpp',
|
||||
'sgl/SkDraw.cpp',
|
||||
'sgl/SkEdge.cpp',
|
||||
'sgl/SkFilterProc.cpp',
|
||||
'sgl/SkFlattenable.cpp',
|
||||
'sgl/SkGeometry.cpp',
|
||||
'sgl/SkGlobals.cpp',
|
||||
'sgl/SkGlyphCache.cpp',
|
||||
'sgl/SkGraphics.cpp',
|
||||
'sgl/SkMask.cpp',
|
||||
'sgl/SkMaskFilter.cpp',
|
||||
'sgl/SkPackBits.cpp',
|
||||
'sgl/SkPaint.cpp',
|
||||
'sgl/SkPath.cpp',
|
||||
'sgl/SkPathEffect.cpp',
|
||||
'sgl/SkPathMeasure.cpp',
|
||||
'sgl/SkPicture.cpp',
|
||||
'sgl/SkPixelRef.cpp',
|
||||
'sgl/SkProcSpriteBlitter.cpp',
|
||||
'sgl/SkPtrRecorder.cpp',
|
||||
'sgl/SkRasterizer.cpp',
|
||||
'sgl/SkRefCnt.cpp',
|
||||
'sgl/SkRegion_path.cpp',
|
||||
'sgl/SkScalerContext.cpp',
|
||||
'sgl/SkScan.cpp',
|
||||
'sgl/SkScan_Antihair.cpp',
|
||||
'sgl/SkScan_AntiPath.cpp',
|
||||
'sgl/SkScan_Hairline.cpp',
|
||||
'sgl/SkScan_Path.cpp',
|
||||
'sgl/SkShader.cpp',
|
||||
'sgl/SkSpriteBlitter_ARGB32.cpp',
|
||||
'sgl/SkSpriteBlitter_RGB16.cpp',
|
||||
'sgl/SkString.cpp',
|
||||
'sgl/SkStroke.cpp',
|
||||
'sgl/SkStrokerPriv.cpp',
|
||||
'sgl/SkTSearch.cpp',
|
||||
'sgl/SkTypeface_fake.cpp',
|
||||
'sgl/SkUtils.cpp',
|
||||
'sgl/SkWriter32.cpp',
|
||||
'sgl/SkXfermode.cpp',
|
||||
]
|
||||
|
||||
env_p = env.Clone(
|
||||
PCHSTOP = 'SkTypes.h',
|
||||
PDB = 'vc80.pdb',
|
||||
)
|
||||
|
||||
# TODO(rspangler): This step forces -Zi, but doesn't actually use it. Need to
|
||||
# fix so it doesn't override our -Z7. -Zi also causes vc80.pdb to be created
|
||||
# in the skia directory.
|
||||
# TODO(bradnelson): This step creates a skia.pch.ib_tag file to be created.
|
||||
# It's a 0-length file so likely harmless. Is this a side effect of having
|
||||
# IncrediBuild installed on the build machine?
|
||||
pch, obj = env_p.PCH(['skia.pch', 'precompiled.obj'], 'precompiled.cc')
|
||||
env_p['PCH'] = pch
|
||||
|
||||
env.StaticLibrary('skia', input_files + [obj])
|
||||
@@ -0,0 +1,43 @@
|
||||
/* libs/graphics/animator/SkAnimate.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkAnimate_DEFINED
|
||||
#define SkAnimate_DEFINED
|
||||
|
||||
#include "SkAnimateBase.h"
|
||||
#include "SkDisplayType.h"
|
||||
#include "SkIntArray.h"
|
||||
#include "SkUtils.h"
|
||||
|
||||
class SkAnimate : public SkAnimateBase {
|
||||
DECLARE_MEMBER_INFO(Animate);
|
||||
SkAnimate();
|
||||
virtual ~SkAnimate();
|
||||
virtual int components();
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
virtual void onEndElement(SkAnimateMaker& maker);
|
||||
protected:
|
||||
bool resolveCommon(SkAnimateMaker& );
|
||||
int fComponents;
|
||||
private:
|
||||
typedef SkAnimateBase INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkAnimateField_DEFINED
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
|
||||
xmlns:Sk="http://www.skia.com/schema/SkAnimateSchema.xsd"
|
||||
|
||||
targetNamespace="urn:skia3D" xmlns:Sk3D="urn:skia3D">
|
||||
|
||||
|
||||
|
||||
<xs:simpleType name="Patch" >
|
||||
|
||||
<xs:restriction base="xs:string" >
|
||||
|
||||
</xs:restriction>
|
||||
|
||||
</xs:simpleType>
|
||||
|
||||
|
||||
|
||||
<xs:simpleType name="Point" >
|
||||
|
||||
<xs:restriction base="xs:string" >
|
||||
|
||||
<xs:pattern value="[+-]?([0-9]*\.[0-9]+|[0-9]+\.?)( *[ ,] *[+-]?([0-9]*\.[0-9]+|[0-9]+\.?)){2}" />
|
||||
|
||||
</xs:restriction>
|
||||
|
||||
</xs:simpleType>
|
||||
|
||||
|
||||
|
||||
<xs:element name="camera">
|
||||
|
||||
<xs:complexType >
|
||||
|
||||
<xs:attribute name="axis" type="Sk3D:Point" />
|
||||
|
||||
<xs:attribute name="hackHeight" type="Sk:Float" />
|
||||
|
||||
<xs:attribute name="hackWidth" type="Sk:Float" />
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--This file is auto-generated by the XML Schema Designer. It holds layout information for components on the designer surface.-->
|
||||
@@ -0,0 +1,509 @@
|
||||
/* libs/graphics/animator/SkAnimateActive.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkAnimateActive.h"
|
||||
#include "SkAnimateBase.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkAnimateSet.h"
|
||||
#include "SkDrawGroup.h"
|
||||
#ifdef SK_DEBUG
|
||||
#include "SkTime.h"
|
||||
#endif
|
||||
|
||||
// SkActive holds array of interpolators
|
||||
|
||||
SkActive::SkActive(SkApply& apply, SkAnimateMaker& maker) : fApply(apply),
|
||||
fMaxTime(0), fMaker(maker), fDrawIndex(0), fDrawMax(0) {
|
||||
}
|
||||
|
||||
void SkActive::init()
|
||||
{
|
||||
fAnimators = fApply.fAnimators;
|
||||
int animators = fAnimators.count();
|
||||
fInterpolators.setCount(animators);
|
||||
memset(fInterpolators.begin(), 0, animators * sizeof(SkOperandInterpolator*));
|
||||
fState.setCount(animators);
|
||||
int index;
|
||||
for (index = 0; index < animators; index++)
|
||||
fInterpolators[index] = SkNEW(SkOperandInterpolator);
|
||||
initState(&fApply, 0);
|
||||
// for (index = 0; index < animators; index++)
|
||||
// fState[index].bumpSave();
|
||||
SkASSERT(fInterpolators.count() == fAnimators.count());
|
||||
}
|
||||
|
||||
SkActive::~SkActive() {
|
||||
int index;
|
||||
for (index = 0; index < fSaveRestore.count(); index++)
|
||||
delete[] fSaveRestore[index];
|
||||
for (index = 0; index < fSaveInterpolators.count(); index++)
|
||||
delete[] fSaveInterpolators[index];
|
||||
for (index = 0; index < fInterpolators.count(); index++)
|
||||
delete fInterpolators[index];
|
||||
}
|
||||
|
||||
void SkActive::advance() {
|
||||
if (fDrawMax < fDrawIndex)
|
||||
fDrawMax = fDrawIndex;
|
||||
fDrawIndex += fAnimators.count();
|
||||
}
|
||||
|
||||
void SkActive::append(SkApply* apply) {
|
||||
int oldCount = fAnimators.count();
|
||||
SkTDAnimateArray& animates = apply->fAnimators;
|
||||
int newCount = animates.count();
|
||||
int index;
|
||||
int total = oldCount + newCount;
|
||||
if (total == 0)
|
||||
return;
|
||||
fInterpolators.setCount(total);
|
||||
memset(&fInterpolators.begin()[oldCount], 0, newCount * sizeof(SkOperandInterpolator*));
|
||||
for (index = oldCount; index < total; index++)
|
||||
fInterpolators[index] = SkNEW(SkOperandInterpolator);
|
||||
fAnimators.setCount(total);
|
||||
memcpy(&fAnimators[oldCount], animates.begin(), sizeof(fAnimators[0]) *
|
||||
newCount);
|
||||
fState.setCount(total);
|
||||
initState(apply, oldCount);
|
||||
SkASSERT(fApply.scope == apply->scope);
|
||||
for (index = 0; index < newCount; index++) {
|
||||
SkAnimateBase* test = animates[index];
|
||||
// SkASSERT(fApply.scope == test->fTarget || fApply.scope->contains(test->fTarget));
|
||||
SkActive::SkState& testState = fState[oldCount + index];
|
||||
for (int inner = 0; inner < oldCount; inner++) {
|
||||
SkAnimateBase* oldGuard = fAnimators[inner];
|
||||
SkActive::SkState& oldState = fState[inner];
|
||||
if (oldGuard->fTarget == test->fTarget && oldGuard->fFieldInfo == test->fFieldInfo &&
|
||||
testState.fBegin == oldState.fBegin) {
|
||||
delete fInterpolators[inner];
|
||||
fInterpolators.remove(inner);
|
||||
fAnimators.remove(inner);
|
||||
testState.fSave = oldState.fSave;
|
||||
if (oldState.fUnpostedEndEvent) {
|
||||
// SkDEBUGF(("%8x %8x active append: post on end\n", this, oldGuard));
|
||||
fMaker.postOnEnd(oldGuard, oldState.fBegin + oldState.fDuration);
|
||||
}
|
||||
fState.remove(inner);
|
||||
if (fApply.restore) {
|
||||
int saveIndex = fSaveRestore.count();
|
||||
SkASSERT(fSaveInterpolators.count() == saveIndex);
|
||||
saveIndex += inner;
|
||||
do {
|
||||
saveIndex -= oldCount;
|
||||
delete[] fSaveRestore[saveIndex];
|
||||
fSaveRestore.remove(saveIndex);
|
||||
delete[] fSaveInterpolators[saveIndex];
|
||||
fSaveInterpolators.remove(saveIndex);
|
||||
} while (saveIndex > 0);
|
||||
}
|
||||
oldCount--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// total = oldCount + newCount;
|
||||
// for (index = oldCount; index < total; index++)
|
||||
// fState[index].bumpSave();
|
||||
SkASSERT(fInterpolators.count() == fAnimators.count());
|
||||
}
|
||||
|
||||
void SkActive::appendSave(int oldCount) {
|
||||
SkASSERT(fDrawMax == 0); // if true, we can optimize below quite a bit
|
||||
int newCount = fAnimators.count();
|
||||
int saveIndex = fSaveRestore.count();
|
||||
SkASSERT(fSaveInterpolators.count() == saveIndex);
|
||||
int records = saveIndex / oldCount;
|
||||
int newTotal = records * newCount;
|
||||
fSaveRestore.setCount(newTotal);
|
||||
do {
|
||||
saveIndex -= oldCount;
|
||||
newTotal -= newCount;
|
||||
SkASSERT(saveIndex >= 0);
|
||||
SkASSERT(newTotal >= 0);
|
||||
memmove(&fSaveRestore[newTotal], &fSaveRestore[saveIndex], oldCount);
|
||||
memset(&fSaveRestore[newTotal + oldCount], 0,
|
||||
sizeof(fSaveRestore[0]) * (newCount - oldCount));
|
||||
memmove(&fSaveInterpolators[newTotal],
|
||||
&fSaveInterpolators[saveIndex], oldCount);
|
||||
memset(&fSaveInterpolators[newTotal + oldCount], 0,
|
||||
sizeof(fSaveRestore[0]) * (newCount - oldCount));
|
||||
} while (saveIndex > 0);
|
||||
SkASSERT(newTotal == 0);
|
||||
}
|
||||
|
||||
void SkActive::calcDurations(int index)
|
||||
{
|
||||
SkAnimateBase* animate = fAnimators[index];
|
||||
SkMSec duration = animate->dur;
|
||||
SkState& state = fState[index];
|
||||
if (state.fMode == SkApply::kMode_immediate || state.fMode == SkApply::kMode_create)
|
||||
duration = state.fSteps ? state.fSteps * SK_MSec1 : 1;
|
||||
// else if (state.fMode == SkApply::kMode_hold) {
|
||||
// int entries = animate->entries();
|
||||
// SkScriptValue value;
|
||||
// value.fOperand = animate->getValues()[entries - 1];
|
||||
// value.fType = animate->getValuesType();
|
||||
// bool result = SkScriptEngine::ConvertTo(NULL, SkType_Int, &value);
|
||||
// SkASSERT(result);
|
||||
// duration = value.fOperand.fS32 * SK_MSec1;
|
||||
// }
|
||||
state.fDuration = duration;
|
||||
SkMSec maxTime = state.fBegin + duration;
|
||||
if (fMaxTime < maxTime)
|
||||
fMaxTime = maxTime;
|
||||
}
|
||||
|
||||
void SkActive::create(SkDrawable* drawable, SkMSec time) {
|
||||
fApply.fLastTime = time;
|
||||
fApply.refresh(fMaker);
|
||||
for (int index = 0; index < fAnimators.count(); index++) {
|
||||
SkAnimateBase* animate = fAnimators[index];
|
||||
SkOperandInterpolator& interpolator = *fInterpolators[index];
|
||||
int count = animate->components();
|
||||
if (animate->formula.size() > 0) {
|
||||
SkTDOperandArray values;
|
||||
values.setCount(count);
|
||||
bool success = animate->fFieldInfo->setValue(fMaker, &values, 0, 0, NULL,
|
||||
animate->getValuesType(), animate->formula);
|
||||
SkASSERT(success);
|
||||
fApply.applyValues(index, values.begin(), count, animate->getValuesType(), time);
|
||||
} else {
|
||||
SkAutoSTMalloc<16, SkOperand> values(count);
|
||||
interpolator.timeToValues(time, values.get());
|
||||
fApply.applyValues(index, values.get(), count, animate->getValuesType(), time);
|
||||
}
|
||||
}
|
||||
drawable->enable(fMaker);
|
||||
SkASSERT(fAnimators.count() == fInterpolators.count());
|
||||
}
|
||||
|
||||
bool SkActive::immediate(bool enable) {
|
||||
SkMSec time = 0;
|
||||
bool result = false;
|
||||
SkDrawable* drawable = fApply.scope;
|
||||
SkMSec final = fMaxTime;
|
||||
do {
|
||||
bool applied = fAnimators.count() == 0;
|
||||
fApply.fLastTime = time;
|
||||
fApply.refresh(fMaker);
|
||||
for (int index = 0; index < fAnimators.count(); index++) {
|
||||
SkAnimateBase* animate = fAnimators[index];
|
||||
SkState& state = fState[index];
|
||||
if (state.fMode != SkApply::kMode_immediate)
|
||||
continue;
|
||||
if (state.fBegin > time)
|
||||
continue;
|
||||
if (time > state.fBegin + state.fDuration)
|
||||
continue;
|
||||
applied = true;
|
||||
SkOperandInterpolator& interpolator = *fInterpolators[index];
|
||||
int count = animate->components();
|
||||
if (animate->formula.size() > 0) {
|
||||
SkTDOperandArray values;
|
||||
values.setCount(count);
|
||||
bool success = animate->fFieldInfo->setValue(fMaker, &values, 0, 0, NULL,
|
||||
animate->getValuesType(), animate->formula);
|
||||
SkASSERT(success);
|
||||
fApply.applyValues(index, values.begin(), count, animate->getValuesType(), time);
|
||||
} else {
|
||||
SkAutoSTMalloc<16, SkOperand> values(count);
|
||||
interpolator.timeToValues(time, values.get());
|
||||
fApply.applyValues(index, values.get(), count, animate->getValuesType(), time);
|
||||
}
|
||||
}
|
||||
if (enable)
|
||||
drawable->enable(fMaker);
|
||||
else if (applied)
|
||||
result |= drawable->draw(fMaker);
|
||||
time += SK_MSec1;
|
||||
} while (time <= final);
|
||||
return result;
|
||||
}
|
||||
|
||||
void SkActive::fixInterpolator(SkBool save) {
|
||||
int animators = fAnimators.count();
|
||||
for (int index = 0; index < animators; index++) {
|
||||
SkAnimateBase* animate = fAnimators[index];
|
||||
if (save) { // saved slots increased
|
||||
animate->refresh(fMaker);
|
||||
SkOperand* values = animate->getValues();
|
||||
setInterpolator(index, values);
|
||||
saveInterpolatorValues(index);
|
||||
} else
|
||||
restoreInterpolatorValues(index);
|
||||
}
|
||||
}
|
||||
|
||||
SkMSec SkActive::getTime(SkMSec inTime, int animatorIndex) {
|
||||
fState[animatorIndex].fTicks = inTime;
|
||||
return inTime - fState[animatorIndex].fStartTime;
|
||||
}
|
||||
|
||||
bool SkActive::initializeSave() {
|
||||
int animators = fAnimators.count();
|
||||
int activeTotal = fDrawIndex + animators;
|
||||
int oldCount = fSaveRestore.count();
|
||||
if (oldCount < activeTotal) {
|
||||
fSaveRestore.setCount(activeTotal);
|
||||
memset(&fSaveRestore[oldCount], 0, sizeof(fSaveRestore[0]) * (activeTotal - oldCount));
|
||||
SkASSERT(fSaveInterpolators.count() == oldCount);
|
||||
fSaveInterpolators.setCount(activeTotal);
|
||||
memset(&fSaveInterpolators[oldCount], 0,
|
||||
sizeof(fSaveInterpolators[0]) * (activeTotal - oldCount));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkActive::initState(SkApply* apply, int offset) {
|
||||
int count = fState.count();
|
||||
for (int index = offset; index < count; index++) {
|
||||
SkState& state = fState[index];
|
||||
SkAnimateBase* animate = fAnimators[index];
|
||||
#if 0 // def SK_DEBUG
|
||||
if (animate->fHasEndEvent)
|
||||
SkDebugf("%8x %8x active initState:\n", this, animate);
|
||||
#endif
|
||||
SkOperand* from = animate->getValues();
|
||||
state.fStartTime = state.fBegin = apply->begin + animate->begin;
|
||||
state.fMode = apply->mode;
|
||||
state.fTransition = apply->transition;
|
||||
#if 0
|
||||
state.fPickup = (SkBool8) apply->pickup;
|
||||
#endif
|
||||
state.fRestore = (SkBool8) apply->restore;
|
||||
state.fSave = apply->begin;
|
||||
state.fStarted = false;
|
||||
state.fSteps = apply->steps;
|
||||
state.fTicks = 0;
|
||||
state.fUnpostedEndEvent = (SkBool8) animate->fHasEndEvent;
|
||||
calcDurations(index);
|
||||
setInterpolator(index, from);
|
||||
}
|
||||
if (count == 0 && (apply->mode == SkApply::kMode_immediate || apply->mode == SkApply::kMode_create))
|
||||
fMaxTime = apply->begin + apply->steps * SK_MSec1;
|
||||
}
|
||||
|
||||
void SkActive::pickUp(SkActive* existing) {
|
||||
SkTDOperandArray existingValues;
|
||||
for (int index = 0; index < fAnimators.count(); index++) {
|
||||
SkAnimateBase* animate = fAnimators[index];
|
||||
SkASSERT(animate->getValuesType() == SkType_Float);
|
||||
int components = animate->components();
|
||||
SkOperand* from = animate->getValues();
|
||||
SkOperand* to = &from[animate->components()];
|
||||
existingValues.setCount(components);
|
||||
existing->fInterpolators[index]->timeToValues(
|
||||
existing->fState[index].fTicks - existing->fState[index].fStartTime, existingValues.begin());
|
||||
SkScalar originalSum = 0;
|
||||
SkScalar workingSum = 0;
|
||||
for (int cIndex = 0; cIndex < components; cIndex++) {
|
||||
SkScalar delta = to[cIndex].fScalar - from[cIndex].fScalar;
|
||||
originalSum += SkScalarMul(delta, delta);
|
||||
delta = to[cIndex].fScalar - existingValues[cIndex].fScalar;
|
||||
workingSum += SkScalarMul(delta, delta);
|
||||
}
|
||||
if (workingSum < originalSum) {
|
||||
SkScalar originalDistance = SkScalarSqrt(originalSum);
|
||||
SkScalar workingDistance = SkScalarSqrt(workingSum);
|
||||
existing->fState[index].fDuration = (SkMSec) SkScalarMulDiv(fState[index].fDuration,
|
||||
workingDistance, originalDistance);
|
||||
}
|
||||
fInterpolators[index]->reset(components, 2, SkType_Float);
|
||||
fInterpolators[index]->setKeyFrame(0, 0, existingValues.begin(), animate->blend[0]);
|
||||
fInterpolators[index]->setKeyFrame(1, fState[index].fDuration, to, animate->blend[0]);
|
||||
}
|
||||
}
|
||||
|
||||
void SkActive::resetInterpolators() {
|
||||
int animators = fAnimators.count();
|
||||
for (int index = 0; index < animators; index++) {
|
||||
SkAnimateBase* animate = fAnimators[index];
|
||||
SkOperand* values = animate->getValues();
|
||||
setInterpolator(index, values);
|
||||
}
|
||||
}
|
||||
|
||||
void SkActive::resetState() {
|
||||
fDrawIndex = 0;
|
||||
int count = fState.count();
|
||||
for (int index = 0; index < count; index++) {
|
||||
SkState& state = fState[index];
|
||||
SkAnimateBase* animate = fAnimators[index];
|
||||
#if 0 // def SK_DEBUG
|
||||
if (animate->fHasEndEvent)
|
||||
SkDebugf("%8x %8x active resetState: has end event\n", this, animate);
|
||||
#endif
|
||||
state.fStartTime = state.fBegin = fApply.begin + animate->begin;
|
||||
state.fStarted = false;
|
||||
state.fTicks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SkActive::restoreInterpolatorValues(int index) {
|
||||
SkOperandInterpolator& interpolator = *fInterpolators[index];
|
||||
index += fDrawIndex ;
|
||||
int count = interpolator.getValuesCount();
|
||||
memcpy(interpolator.getValues(), fSaveInterpolators[index], count * sizeof(SkOperand));
|
||||
}
|
||||
|
||||
void SkActive::saveInterpolatorValues(int index) {
|
||||
SkOperandInterpolator& interpolator = *fInterpolators[index];
|
||||
index += fDrawIndex ;
|
||||
int count = interpolator.getValuesCount();
|
||||
SkOperand* cache = new SkOperand[count]; // this should use sk_malloc/sk_free since SkOperand does not have a constructor/destructor
|
||||
fSaveInterpolators[index] = cache;
|
||||
memcpy(cache, interpolator.getValues(), count * sizeof(SkOperand));
|
||||
}
|
||||
|
||||
void SkActive::setInterpolator(int index, SkOperand* from) {
|
||||
if (from == NULL) // legitimate for set string
|
||||
return;
|
||||
SkAnimateBase* animate = fAnimators[index];
|
||||
int entries = animate->entries();
|
||||
SkASSERT(entries > 0);
|
||||
SkMSec duration = fState[index].fDuration;
|
||||
int components = animate->components();
|
||||
SkOperandInterpolator& interpolator = *fInterpolators[index];
|
||||
interpolator.reset(components, entries == 1 ? 2 : entries, animate->getValuesType());
|
||||
interpolator.setMirror(SkToBool(animate->fMirror));
|
||||
interpolator.setReset(SkToBool(animate->fReset));
|
||||
interpolator.setRepeatCount(animate->repeat);
|
||||
if (entries == 1) {
|
||||
interpolator.setKeyFrame(0, 0, from, animate->blend[0]);
|
||||
interpolator.setKeyFrame(1, duration, from, animate->blend[0]);
|
||||
return;
|
||||
}
|
||||
for (int entry = 0; entry < entries; entry++) {
|
||||
int blendIndex = SkMin32(animate->blend.count() - 1, entry);
|
||||
interpolator.setKeyFrame(entry, entry * duration / (entries - 1), from,
|
||||
animate->blend[blendIndex]);
|
||||
from += components;
|
||||
}
|
||||
}
|
||||
|
||||
void SkActive::setSteps(int steps) {
|
||||
int count = fState.count();
|
||||
fMaxTime = 0;
|
||||
for (int index = 0; index < count; index++) {
|
||||
SkState& state = fState[index];
|
||||
state.fSteps = steps;
|
||||
calcDurations(index);
|
||||
}
|
||||
}
|
||||
|
||||
void SkActive::start() {
|
||||
int count = fState.count();
|
||||
SkASSERT(count == fAnimators.count());
|
||||
SkASSERT(count == fInterpolators.count());
|
||||
for (int index = 0; index < count; index++) {
|
||||
SkState& state = fState[index];
|
||||
if (state.fStarted)
|
||||
continue;
|
||||
state.fStarted = true;
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
SkString debugOut;
|
||||
SkMSec time = fMaker.getAppTime();
|
||||
debugOut.appendS32(time - fMaker.fDebugTimeBase);
|
||||
debugOut.append(" active start adjust delay id=");
|
||||
debugOut.append(fApply._id);
|
||||
debugOut.append("; ");
|
||||
debugOut.append(fAnimators[index]->_id);
|
||||
debugOut.append("=");
|
||||
debugOut.appendS32(fAnimators[index]->fStart - fMaker.fDebugTimeBase);
|
||||
debugOut.append(":");
|
||||
debugOut.appendS32(state.fStartTime);
|
||||
#endif
|
||||
if (state.fStartTime > 0) {
|
||||
SkMSec future = fAnimators[index]->fStart + state.fStartTime;
|
||||
if (future > fMaker.fEnableTime)
|
||||
fMaker.notifyInvalTime(future);
|
||||
else
|
||||
fMaker.notifyInval();
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
debugOut.append(":");
|
||||
debugOut.appendS32(future - fMaker.fDebugTimeBase);
|
||||
#endif
|
||||
}
|
||||
if (state.fStartTime >= fMaker.fAdjustedStart) {
|
||||
state.fStartTime -= fMaker.fAdjustedStart;
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
debugOut.append(" (less adjust = ");
|
||||
debugOut.appendS32(fMaker.fAdjustedStart);
|
||||
#endif
|
||||
}
|
||||
state.fStartTime += fAnimators[index]->fStart;
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
debugOut.append(") new start = ");
|
||||
debugOut.appendS32(state.fStartTime - fMaker.fDebugTimeBase);
|
||||
SkDebugf("%s\n", debugOut.c_str());
|
||||
// SkASSERT((int) (state.fStartTime - fMaker.fDebugTimeBase) >= 0);
|
||||
#endif
|
||||
}
|
||||
SkASSERT(fAnimators.count() == fInterpolators.count());
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void SkActive::validate() {
|
||||
int count = fState.count();
|
||||
SkASSERT(count == fAnimators.count());
|
||||
SkASSERT(count == fInterpolators.count());
|
||||
for (int index = 0; index < count; index++) {
|
||||
SkASSERT(fAnimators[index]);
|
||||
SkASSERT(fInterpolators[index]);
|
||||
// SkAnimateBase* test = fAnimators[index];
|
||||
// SkASSERT(fApply.scope == test->fTarget || fApply.scope->contains(test->fTarget));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// think about this
|
||||
// there should only be one animate object, not two, to go up and down
|
||||
// when the apply with reverse came into play, it needs to pick up the value
|
||||
// of the existing animate object then remove it from the list
|
||||
// the code below should only be bumping fSave, and there shouldn't be anything
|
||||
// it needs to be synchronized with
|
||||
|
||||
// however, if there are two animates both operating on the same field, then
|
||||
// when one replaces the other, it may make sense to pick up the old value as a starting
|
||||
// value for the new one somehow.
|
||||
|
||||
//void SkActive::SkState::bumpSave() {
|
||||
// if (fMode != SkApply::kMode_hold)
|
||||
// return;
|
||||
// if (fTransition == SkApply::kTransition_reverse) {
|
||||
// if (fSave > 0)
|
||||
// fSave -= SK_MSec1;
|
||||
// } else if (fSave < fDuration)
|
||||
// fSave += SK_MSec1;
|
||||
//}
|
||||
|
||||
SkMSec SkActive::SkState::getRelativeTime(SkMSec time) {
|
||||
SkMSec result = time;
|
||||
// if (fMode == SkApply::kMode_hold)
|
||||
// result = fSave;
|
||||
// else
|
||||
if (fTransition == SkApply::kTransition_reverse) {
|
||||
if (SkMSec_LT(fDuration, time))
|
||||
result = 0;
|
||||
else
|
||||
result = fDuration - time;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/* libs/graphics/animator/SkAnimateActive.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkAnimateActive_DEFINED
|
||||
#define SkAnimateActive_DEFINED
|
||||
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkOperandInterpolator.h"
|
||||
#include "SkIntArray.h"
|
||||
|
||||
class SkAnimateMaker;
|
||||
|
||||
class SkActive {
|
||||
public:
|
||||
SkActive(SkApply& , SkAnimateMaker& );
|
||||
~SkActive();
|
||||
void advance();
|
||||
void append(SkApply* );
|
||||
void calcDurations(int index);
|
||||
void create(SkDrawable* scope, SkMSec time);
|
||||
bool draw() { return immediate(false); }
|
||||
bool enable() { return immediate(true); }
|
||||
void init( );
|
||||
SkMSec getTime(SkMSec inTime, int animatorIndex);
|
||||
void pickUp(SkActive* existing);
|
||||
void reset() { fDrawIndex = 0; }
|
||||
void setInterpolator(int index, SkOperand* from);
|
||||
void start();
|
||||
#ifdef SK_DEBUG
|
||||
void validate();
|
||||
#endif
|
||||
private:
|
||||
void appendSave(int oldCount);
|
||||
void fixInterpolator(SkBool save);
|
||||
bool immediate(bool enable);
|
||||
bool initializeSave();
|
||||
void initState(SkApply* , int offset);
|
||||
void resetInterpolators();
|
||||
void resetState();
|
||||
void restoreInterpolatorValues(int index);
|
||||
void saveInterpolatorValues(int index);
|
||||
void setSteps(int steps);
|
||||
struct SkState {
|
||||
// void bumpSave();
|
||||
SkMSec getRelativeTime(SkMSec time);
|
||||
SkApply::Mode fMode;
|
||||
SkApply::Transition fTransition;
|
||||
SkBool8 fPickup;
|
||||
SkBool8 fRestore;
|
||||
SkBool8 fStarted;
|
||||
SkBool8 fUnpostedEndEvent;
|
||||
int32_t fSteps;
|
||||
SkMSec fBegin;
|
||||
SkMSec fStartTime;
|
||||
SkMSec fDuration;
|
||||
SkMSec fSave;
|
||||
SkMSec fTicks;
|
||||
};
|
||||
SkActive& operator= (const SkActive& );
|
||||
SkTDArray<SkOperandInterpolator*> fInterpolators;
|
||||
SkApply& fApply;
|
||||
SkTDArray<SkState> fState; // one per animator
|
||||
SkTDOperandPtrArray fSaveRestore; // if apply has restore="true"
|
||||
SkTDOperandPtrArray fSaveInterpolators;
|
||||
SkTDAnimateArray fAnimators;
|
||||
SkMSec fMaxTime; // greatest of all animation durations; only used by immediate mode
|
||||
SkAnimateMaker& fMaker;
|
||||
int fDrawIndex;
|
||||
int fDrawMax;
|
||||
friend class SkApply;
|
||||
};
|
||||
|
||||
#endif // SkAnimateActive_DEFINED
|
||||
@@ -0,0 +1,247 @@
|
||||
/* libs/graphics/animator/SkAnimateBase.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkAnimateBase.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkAnimateProperties.h"
|
||||
#include "SkAnimatorScript.h"
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkDrawable.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkAnimateBase::fInfo[] = {
|
||||
SK_MEMBER(begin, MSec),
|
||||
SK_MEMBER_ARRAY(blend, Float),
|
||||
SK_MEMBER(dur, MSec),
|
||||
SK_MEMBER_PROPERTY(dynamic, Boolean),
|
||||
SK_MEMBER(field, String), // name of member info in target
|
||||
SK_MEMBER(formula, DynamicString),
|
||||
SK_MEMBER(from, DynamicString),
|
||||
SK_MEMBER(lval, DynamicString),
|
||||
SK_MEMBER_PROPERTY(mirror, Boolean),
|
||||
SK_MEMBER(repeat, Float),
|
||||
SK_MEMBER_PROPERTY(reset, Boolean),
|
||||
SK_MEMBER_PROPERTY(step, Int),
|
||||
SK_MEMBER(target, DynamicString),
|
||||
SK_MEMBER(to, DynamicString),
|
||||
SK_MEMBER_PROPERTY(values, DynamicString)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkAnimateBase);
|
||||
|
||||
SkAnimateBase::SkAnimateBase() : begin(0), dur(1), repeat(SK_Scalar1),
|
||||
fApply(NULL), fFieldInfo(NULL), fFieldOffset(0), fStart((SkMSec) -1), fTarget(NULL),
|
||||
fChanged(0), fDelayed(0), fDynamic(0), fHasEndEvent(0), fHasValues(0),
|
||||
fMirror(0), fReset(0), fResetPending(0), fTargetIsScope(0) {
|
||||
blend.setCount(1);
|
||||
blend[0] = SK_Scalar1;
|
||||
}
|
||||
|
||||
SkAnimateBase::~SkAnimateBase() {
|
||||
SkDisplayTypes type = fValues.getType();
|
||||
if (type == SkType_String || type == SkType_DynamicString) {
|
||||
SkASSERT(fValues.count() == 1);
|
||||
delete fValues[0].fString;
|
||||
}
|
||||
}
|
||||
|
||||
int SkAnimateBase::components() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
SkDisplayable* SkAnimateBase::deepCopy(SkAnimateMaker* maker) {
|
||||
SkAnimateBase* result = (SkAnimateBase*) INHERITED::deepCopy(maker);
|
||||
result->fApply = fApply;
|
||||
result->fFieldInfo =fFieldInfo;
|
||||
result->fHasValues = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
void SkAnimateBase::dirty() {
|
||||
fChanged = true;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkAnimateBase::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
if (target.size() > 0)
|
||||
SkDebugf("target=\"%s\" ", target.c_str());
|
||||
else if (fTarget && strcmp(fTarget->id, ""))
|
||||
SkDebugf("target=\"%s\" ", fTarget->id);
|
||||
if (lval.size() > 0)
|
||||
SkDebugf("lval=\"%s\" ", lval.c_str());
|
||||
if (field.size() > 0)
|
||||
SkDebugf("field=\"%s\" ", field.c_str());
|
||||
else if (fFieldInfo)
|
||||
SkDebugf("field=\"%s\" ", fFieldInfo->fName);
|
||||
if (formula.size() > 0)
|
||||
SkDebugf("formula=\"%s\" ", formula.c_str());
|
||||
else {
|
||||
if (from.size() > 0)
|
||||
SkDebugf("from=\"%s\" ", from.c_str());
|
||||
SkDebugf("to=\"%s\" ", to.c_str());
|
||||
}
|
||||
if (begin != 0) {
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf("begin=\"%g\" ", SkScalarToFloat(SkScalarDiv(begin,1000)));
|
||||
#else
|
||||
SkDebugf("begin=\"%x\" ", SkScalarDiv(begin,1000));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SkDisplayable* SkAnimateBase::getParent() const {
|
||||
return (SkDisplayable*) fApply;
|
||||
}
|
||||
|
||||
bool SkAnimateBase::getProperty(int index, SkScriptValue* value) const {
|
||||
int boolResult;
|
||||
switch (index) {
|
||||
case SK_PROPERTY(dynamic):
|
||||
boolResult = fDynamic;
|
||||
goto returnBool;
|
||||
case SK_PROPERTY(mirror):
|
||||
boolResult = fMirror;
|
||||
goto returnBool;
|
||||
case SK_PROPERTY(reset):
|
||||
boolResult = fReset;
|
||||
returnBool:
|
||||
value->fOperand.fS32 = SkToBool(boolResult);
|
||||
value->fType = SkType_Boolean;
|
||||
break;
|
||||
case SK_PROPERTY(step):
|
||||
if (fApply == NULL)
|
||||
return false; // !!! notify there's an error?
|
||||
fApply->getStep(value);
|
||||
break;
|
||||
case SK_PROPERTY(values):
|
||||
value->fOperand.fString = (SkString*) &to;
|
||||
value->fType = SkType_String;
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkAnimateBase::hasExecute() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkAnimateBase::onEndElement(SkAnimateMaker& maker) {
|
||||
fChanged = false;
|
||||
setTarget(maker);
|
||||
if (field.size()) {
|
||||
SkASSERT(fTarget);
|
||||
fFieldInfo = fTarget->getMember(field.c_str());
|
||||
field.reset();
|
||||
}
|
||||
if (lval.size()) {
|
||||
// lval must be of the form x[y]
|
||||
const char* lvalStr = lval.c_str();
|
||||
const char* arrayEnd = strchr(lvalStr, '[');
|
||||
if (arrayEnd == NULL)
|
||||
return; //should this return an error?
|
||||
size_t arrayNameLen = arrayEnd - lvalStr;
|
||||
SkString arrayStr(lvalStr, arrayNameLen);
|
||||
SkASSERT(fTarget); //this return an error?
|
||||
fFieldInfo = fTarget->getMember(arrayStr.c_str());
|
||||
SkString scriptStr(arrayEnd + 1, lval.size() - arrayNameLen - 2);
|
||||
SkAnimatorScript::EvaluateInt(maker, this, scriptStr.c_str(), &fFieldOffset);
|
||||
}
|
||||
}
|
||||
|
||||
void SkAnimateBase::packARGB(SkScalar array[], int count, SkTDOperandArray* converted)
|
||||
{
|
||||
SkASSERT(count == 4);
|
||||
converted->setCount(1);
|
||||
SkColor color = SkColorSetARGB(SkScalarRound(array[0]), SkScalarRound(array[1]),
|
||||
SkScalarRound(array[2]), SkScalarRound(array[3]));
|
||||
(*converted)[0].fS32 = color;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SkAnimateBase::refresh(SkAnimateMaker& ) {
|
||||
}
|
||||
|
||||
bool SkAnimateBase::setParent(SkDisplayable* apply) {
|
||||
SkASSERT(apply->isApply());
|
||||
fApply = (SkApply*) apply;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkAnimateBase::setProperty(int index, SkScriptValue& value) {
|
||||
bool boolValue = SkToBool(value.fOperand.fS32);
|
||||
switch (index) {
|
||||
case SK_PROPERTY(dynamic):
|
||||
fDynamic = boolValue;
|
||||
goto checkForBool;
|
||||
case SK_PROPERTY(values):
|
||||
fHasValues = true;
|
||||
SkASSERT(value.fType == SkType_String);
|
||||
to = *value.fOperand.fString;
|
||||
break;
|
||||
case SK_PROPERTY(mirror):
|
||||
fMirror = boolValue;
|
||||
goto checkForBool;
|
||||
case SK_PROPERTY(reset):
|
||||
fReset = boolValue;
|
||||
checkForBool:
|
||||
SkASSERT(value.fType == SkType_Boolean);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkAnimateBase::setTarget(SkAnimateMaker& maker) {
|
||||
if (target.size()) {
|
||||
SkAnimatorScript engine(maker, this, SkType_Displayable);
|
||||
const char* script = target.c_str();
|
||||
SkScriptValue scriptValue;
|
||||
bool success = engine.evaluateScript(&script, &scriptValue);
|
||||
if (success && scriptValue.fType == SkType_Displayable)
|
||||
fTarget = scriptValue.fOperand.fDrawable;
|
||||
else if (maker.find(target.c_str(), (SkDisplayable**) &fTarget) == false) {
|
||||
if (fApply->getMode() == SkApply::kMode_create)
|
||||
return; // may not be an error
|
||||
if (engine.getError() != SkScriptEngine::kNoError)
|
||||
maker.setScriptError(engine);
|
||||
else {
|
||||
maker.setErrorNoun(target);
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kTargetIDNotFound);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (fApply && fApply->getMode() != SkApply::kMode_create)
|
||||
target.reset();
|
||||
}
|
||||
}
|
||||
|
||||
bool SkAnimateBase::targetNeedsInitialization() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/* libs/graphics/animator/SkAnimateBase.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkAnimateBase_DEFINED
|
||||
#define SkAnimateBase_DEFINED
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkMath.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkTypedArray.h"
|
||||
|
||||
class SkApply;
|
||||
class SkDrawable;
|
||||
|
||||
class SkAnimateBase : public SkDisplayable {
|
||||
public:
|
||||
DECLARE_MEMBER_INFO(AnimateBase);
|
||||
SkAnimateBase();
|
||||
virtual ~SkAnimateBase();
|
||||
virtual int components();
|
||||
virtual SkDisplayable* deepCopy(SkAnimateMaker* );
|
||||
virtual void dirty();
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
int entries() { return fValues.count() / components(); }
|
||||
virtual bool hasExecute() const;
|
||||
bool isDynamic() const { return SkToBool(fDynamic); }
|
||||
virtual SkDisplayable* getParent() const;
|
||||
virtual bool getProperty(int index, SkScriptValue* value) const;
|
||||
SkMSec getStart() const { return fStart; }
|
||||
SkOperand* getValues() { return fValues.begin(); }
|
||||
SkDisplayTypes getValuesType() { return fValues.getType(); }
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
void packARGB(SkScalar [], int count, SkTDOperandArray* );
|
||||
virtual void refresh(SkAnimateMaker& );
|
||||
void setChanged(bool changed) { fChanged = changed; }
|
||||
void setHasEndEvent() { fHasEndEvent = true; }
|
||||
virtual bool setParent(SkDisplayable* );
|
||||
virtual bool setProperty(int index, SkScriptValue& value);
|
||||
void setTarget(SkAnimateMaker& );
|
||||
virtual bool targetNeedsInitialization() const;
|
||||
protected:
|
||||
SkMSec begin;
|
||||
SkTDScalarArray blend;
|
||||
SkMSec dur;
|
||||
// !!! make field part of a union with fFieldInfo, or fValues, something known later?
|
||||
SkString field; // temporary; once target is known, this is reset
|
||||
SkString formula;
|
||||
SkString from;
|
||||
SkString lval;
|
||||
SkScalar repeat;
|
||||
SkString target; // temporary; once target is known, this is reset
|
||||
SkString to;
|
||||
SkApply* fApply;
|
||||
const SkMemberInfo* fFieldInfo;
|
||||
int fFieldOffset;
|
||||
SkMSec fStart; // corrected time when this apply was enabled
|
||||
SkDrawable* fTarget;
|
||||
SkTypedArray fValues;
|
||||
unsigned fChanged : 1; // true when value referenced by script has changed
|
||||
unsigned fDelayed : 1; // enabled, but undrawn pending delay
|
||||
unsigned fDynamic : 1;
|
||||
unsigned fHasEndEvent : 1;
|
||||
unsigned fHasValues : 1; // set if 'values' passed instead of 'to'
|
||||
unsigned fMirror : 1;
|
||||
unsigned fReset : 1;
|
||||
unsigned fResetPending : 1;
|
||||
unsigned fTargetIsScope : 1;
|
||||
private:
|
||||
typedef SkDisplayable INHERITED;
|
||||
friend class SkActive;
|
||||
friend class SkApply;
|
||||
friend class SkDisplayList;
|
||||
};
|
||||
|
||||
#endif // SkAnimateBase_DEFINED
|
||||
@@ -0,0 +1,130 @@
|
||||
/* libs/graphics/animator/SkAnimateField.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkAnimate.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkDrawable.h"
|
||||
#include "SkParse.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkAnimate::fInfo[] = {
|
||||
SK_MEMBER_INHERITED
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkAnimate);
|
||||
|
||||
SkAnimate::SkAnimate() : fComponents(0) {
|
||||
}
|
||||
|
||||
SkAnimate::~SkAnimate() {
|
||||
}
|
||||
|
||||
int SkAnimate::components() {
|
||||
return fComponents;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkAnimate::dump(SkAnimateMaker* maker) {
|
||||
INHERITED::dump(maker); //from animateBase
|
||||
//SkSet inherits from this class
|
||||
if (getType() != SkType_Set) {
|
||||
if (fMirror)
|
||||
SkDebugf("mirror=\"true\" ");
|
||||
if (fReset)
|
||||
SkDebugf("reset=\"true\" ");
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000)));
|
||||
if (repeat != SK_Scalar1)
|
||||
SkDebugf("repeat=\"%g\" ", SkScalarToFloat(repeat));
|
||||
#else
|
||||
SkDebugf("dur=\"%x\" ", SkScalarDiv(dur,1000));
|
||||
if (repeat != SK_Scalar1)
|
||||
SkDebugf("repeat=\"%x\" ", repeat);
|
||||
#endif
|
||||
//if (fHasValues)
|
||||
// SkDebugf("values=\"%s\" ", values);
|
||||
if (blend.count() != 1 || blend[0] != SK_Scalar1) {
|
||||
SkDebugf("blend=\"[");
|
||||
bool firstElem = true;
|
||||
for (int i = 0; i < blend.count(); i++) {
|
||||
if (!firstElem)
|
||||
SkDebugf(",");
|
||||
firstElem = false;
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf("%g", SkScalarToFloat(blend[i]));
|
||||
#else
|
||||
SkDebugf("%x", blend[i]);
|
||||
#endif
|
||||
}
|
||||
SkDebugf("]\" ");
|
||||
}
|
||||
SkDebugf("/>\n");//i assume that if it IS, we will do it separately
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkAnimate::resolveCommon(SkAnimateMaker& maker) {
|
||||
if (fTarget == NULL) // if NULL, recall onEndElement after apply closes and sets target to scope
|
||||
return false;
|
||||
INHERITED::onEndElement(maker);
|
||||
return maker.hasError() == false;
|
||||
}
|
||||
|
||||
void SkAnimate::onEndElement(SkAnimateMaker& maker) {
|
||||
bool resolved = resolveCommon(maker);
|
||||
if (resolved && fFieldInfo == NULL) {
|
||||
maker.setErrorNoun(field);
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kFieldNotInTarget);
|
||||
}
|
||||
if (resolved == false || fFieldInfo == NULL)
|
||||
return;
|
||||
SkDisplayTypes outType = fFieldInfo->getType();
|
||||
if (fHasValues) {
|
||||
SkASSERT(to.size() > 0);
|
||||
fFieldInfo->setValue(maker, &fValues, 0, 0, NULL, outType, to);
|
||||
SkASSERT(0);
|
||||
// !!! this needs to set fComponents
|
||||
return;
|
||||
}
|
||||
fComponents = fFieldInfo->getCount();
|
||||
if (fFieldInfo->fType == SkType_Array) {
|
||||
SkTypedArray* array = (SkTypedArray*) fFieldInfo->memberData(fTarget);
|
||||
int count = array->count();
|
||||
if (count > 0)
|
||||
fComponents = count;
|
||||
}
|
||||
if (outType == SkType_ARGB) {
|
||||
fComponents <<= 2; // four color components
|
||||
outType = SkType_Float;
|
||||
}
|
||||
fValues.setType(outType);
|
||||
if (formula.size() > 0){
|
||||
fComponents = 1;
|
||||
from.set("0");
|
||||
to.set("dur");
|
||||
outType = SkType_MSec;
|
||||
}
|
||||
int max = fComponents * 2;
|
||||
fValues.setCount(max);
|
||||
memset(fValues.begin(), 0, max * sizeof(fValues.begin()[0]));
|
||||
fFieldInfo->setValue(maker, &fValues, fFieldOffset, max, this, outType, from);
|
||||
fFieldInfo->setValue(maker, &fValues, fComponents + fFieldOffset, max, this, outType, to);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,376 @@
|
||||
/* libs/graphics/animator/SkAnimateMaker.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkAnimator.h"
|
||||
#include "SkAnimatorScript.h"
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkDisplayList.h"
|
||||
#include "SkDisplayMovie.h"
|
||||
#include "SkDisplayType.h"
|
||||
#include "SkExtras.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkSystemEventTypes.h"
|
||||
#include "SkTime.h"
|
||||
|
||||
class DefaultTimeline : public SkAnimator::Timeline {
|
||||
virtual SkMSec getMSecs() const {
|
||||
return SkTime::GetMSecs();
|
||||
}
|
||||
} gDefaultTimeline;
|
||||
|
||||
SkAnimateMaker::SkAnimateMaker(SkAnimator* animator, SkCanvas* canvas, SkPaint* paint)
|
||||
: fActiveEvent(NULL), fAdjustedStart(0), fCanvas(canvas), fEnableTime(0),
|
||||
fHostEventSinkID(0), fMinimumInterval((SkMSec) -1), fPaint(paint), fParentMaker(NULL),
|
||||
fTimeline(&gDefaultTimeline), fInInclude(false), fInMovie(false),
|
||||
fFirstScriptError(false), fLoaded(false), fIDs(256), fAnimator(animator)
|
||||
{
|
||||
fScreenplay.time = 0;
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
fDebugTimeBase = (SkMSec) -1;
|
||||
#endif
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
fDumpEvents = fDumpGConditions = fDumpPosts = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
SkAnimateMaker::~SkAnimateMaker() {
|
||||
deleteMembers();
|
||||
}
|
||||
|
||||
#if 0
|
||||
SkMSec SkAnimateMaker::adjustDelay(SkMSec expectedBase, SkMSec delay) {
|
||||
SkMSec appTime = (*fTimeCallBack)();
|
||||
if (appTime)
|
||||
delay -= appTime - expectedBase;
|
||||
if (delay < 0)
|
||||
delay = 0;
|
||||
return delay;
|
||||
}
|
||||
#endif
|
||||
|
||||
void SkAnimateMaker::appendActive(SkActive* active) {
|
||||
fDisplayList.append(active);
|
||||
}
|
||||
|
||||
void SkAnimateMaker::clearExtraPropertyCallBack(SkDisplayTypes type) {
|
||||
SkExtras** end = fExtras.end();
|
||||
for (SkExtras** extraPtr = fExtras.begin(); extraPtr < end; extraPtr++) {
|
||||
SkExtras* extra = *extraPtr;
|
||||
if (extra->definesType(type)) {
|
||||
extra->fExtraCallBack = NULL;
|
||||
extra->fExtraStorage = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SkAnimateMaker::computeID(SkDisplayable* displayable, SkDisplayable* parent, SkString* newID) {
|
||||
const char* script;
|
||||
if (findKey(displayable, &script) == false)
|
||||
return true;
|
||||
return SkAnimatorScript::EvaluateString(*this, displayable, parent, script, newID);
|
||||
}
|
||||
|
||||
SkDisplayable* SkAnimateMaker::createInstance(const char name[], size_t len) {
|
||||
SkDisplayTypes type = SkDisplayType::GetType(this, name, len );
|
||||
if ((int)type >= 0)
|
||||
return SkDisplayType::CreateInstance(this, type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// differs from SkAnimator::decodeStream in that it does not reset error state
|
||||
bool SkAnimateMaker::decodeStream(SkStream* stream)
|
||||
{
|
||||
SkDisplayXMLParser parser(*this);
|
||||
return parser.parse(*stream);
|
||||
}
|
||||
|
||||
// differs from SkAnimator::decodeURI in that it does not set URI base
|
||||
bool SkAnimateMaker::decodeURI(const char uri[]) {
|
||||
// SkDebugf("animator decode %s\n", uri);
|
||||
|
||||
// SkStream* stream = SkStream::GetURIStream(fPrefix.c_str(), uri);
|
||||
SkStream* stream = new SkFILEStream(uri);
|
||||
|
||||
SkAutoTDelete<SkStream> autoDel(stream);
|
||||
bool success = decodeStream(stream);
|
||||
if (hasError() && fError.hasNoun() == false)
|
||||
fError.setNoun(uri);
|
||||
return success;
|
||||
}
|
||||
|
||||
#if defined SK_DEBUG && 0
|
||||
//used for the if'd out section of deleteMembers
|
||||
#include "SkTSearch.h"
|
||||
|
||||
extern "C" {
|
||||
int compare_disp(const void* a, const void* b) {
|
||||
return *(const SkDisplayable**)a - *(const SkDisplayable**)b;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void SkAnimateMaker::delayEnable(SkApply* apply, SkMSec time) {
|
||||
int index = fDelayed.find(apply);
|
||||
if (index < 0)
|
||||
*fDelayed.append() = apply;
|
||||
(new SkEvent(SK_EventType_Delay))->postTime(fAnimator->getSinkID(), time);
|
||||
}
|
||||
|
||||
void SkAnimateMaker::deleteMembers() {
|
||||
int index;
|
||||
#if defined SK_DEBUG && 0
|
||||
//this code checks to see if helpers are among the children, but it is not complete -
|
||||
//it should check the children of the children
|
||||
int result;
|
||||
SkTDArray<SkDisplayable*> children(fChildren.begin(), fChildren.count());
|
||||
SkQSort(children.begin(), children.count(), sizeof(SkDisplayable*),compare_disp);
|
||||
for (index = 0; index < fHelpers.count(); index++) {
|
||||
SkDisplayable* helper = fHelpers[index];
|
||||
result = SkTSearch(children.begin(), children.count(), helper, sizeof(SkDisplayable*));
|
||||
SkASSERT(result < 0);
|
||||
}
|
||||
#endif
|
||||
for (index = 0; index < fChildren.count(); index++) {
|
||||
SkDisplayable* child = fChildren[index];
|
||||
delete child;
|
||||
}
|
||||
for (index = 0; index < fHelpers.count(); index++) {
|
||||
SkDisplayable* helper = fHelpers[index];
|
||||
delete helper;
|
||||
}
|
||||
for (index = 0; index < fExtras.count(); index++) {
|
||||
SkExtras* extras = fExtras[index];
|
||||
delete extras;
|
||||
}
|
||||
}
|
||||
|
||||
void SkAnimateMaker::doDelayedEvent() {
|
||||
fEnableTime = getAppTime();
|
||||
for (int index = 0; index < fDelayed.count(); ) {
|
||||
SkDisplayable* child = fDelayed[index];
|
||||
SkASSERT(child->isApply());
|
||||
SkApply* apply = (SkApply*) child;
|
||||
apply->interpolate(*this, fEnableTime);
|
||||
if (apply->hasDelayedAnimator())
|
||||
index++;
|
||||
else
|
||||
fDelayed.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
bool SkAnimateMaker::doEvent(const SkEvent& event) {
|
||||
return (!fInMovie || fLoaded) && fAnimator->doEvent(event);
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkAnimateMaker::dump(const char* match) {
|
||||
SkTDict<SkDisplayable*>::Iter iter(fIDs);
|
||||
const char* name;
|
||||
SkDisplayable* result;
|
||||
while ((name = iter.next(&result)) != NULL) {
|
||||
if (strcmp(match,name) == 0)
|
||||
result->dump(this);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int SkAnimateMaker::dynamicProperty(SkString& nameStr, SkDisplayable** displayablePtr ) {
|
||||
const char* name = nameStr.c_str();
|
||||
const char* dot = strchr(name, '.');
|
||||
SkASSERT(dot);
|
||||
SkDisplayable* displayable;
|
||||
if (find(name, dot - name, &displayable) == false) {
|
||||
SkASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
const char* fieldName = dot + 1;
|
||||
const SkMemberInfo* memberInfo = displayable->getMember(fieldName);
|
||||
*displayablePtr = displayable;
|
||||
return (int) memberInfo->fOffset;
|
||||
}
|
||||
|
||||
SkMSec SkAnimateMaker::getAppTime() const {
|
||||
return fTimeline->getMSecs();
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
SkAnimator* SkAnimateMaker::getRoot()
|
||||
{
|
||||
SkAnimateMaker* maker = this;
|
||||
while (maker->fParentMaker)
|
||||
maker = maker->fParentMaker;
|
||||
return maker == this ? NULL : maker->fAnimator;
|
||||
}
|
||||
#endif
|
||||
|
||||
void SkAnimateMaker::helperAdd(SkDisplayable* trackMe) {
|
||||
SkASSERT(fHelpers.find(trackMe) < 0);
|
||||
*fHelpers.append() = trackMe;
|
||||
}
|
||||
|
||||
void SkAnimateMaker::helperRemove(SkDisplayable* alreadyTracked) {
|
||||
int helperIndex = fHelpers.find(alreadyTracked);
|
||||
if (helperIndex >= 0)
|
||||
fHelpers.remove(helperIndex);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void SkAnimateMaker::loadMovies() {
|
||||
for (SkDisplayable** dispPtr = fMovies.begin(); dispPtr < fMovies.end(); dispPtr++) {
|
||||
SkDisplayable* displayable = *dispPtr;
|
||||
SkASSERT(displayable->getType() == SkType_Movie);
|
||||
SkDisplayMovie* movie = (SkDisplayMovie*) displayable;
|
||||
SkAnimateMaker* movieMaker = movie->fMovie.fMaker;
|
||||
movieMaker->fEvents.doEvent(*movieMaker, SkDisplayEvent::kOnload, NULL);
|
||||
movieMaker->fEvents.removeEvent(SkDisplayEvent::kOnload, NULL);
|
||||
movieMaker->loadMovies();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void SkAnimateMaker::notifyInval() {
|
||||
if (fHostEventSinkID)
|
||||
fAnimator->onEventPost(new SkEvent(SK_EventType_Inval), fHostEventSinkID);
|
||||
}
|
||||
|
||||
void SkAnimateMaker::notifyInvalTime(SkMSec time) {
|
||||
if (fHostEventSinkID)
|
||||
fAnimator->onEventPostTime(new SkEvent(SK_EventType_Inval), fHostEventSinkID, time);
|
||||
}
|
||||
|
||||
void SkAnimateMaker::postOnEnd(SkAnimateBase* animate, SkMSec end) {
|
||||
SkEvent evt;
|
||||
evt.setS32("time", animate->getStart() + end);
|
||||
evt.setPtr("anim", animate);
|
||||
evt.setType(SK_EventType_OnEnd);
|
||||
SkEventSinkID sinkID = fAnimator->getSinkID();
|
||||
fAnimator->onEventPost(new SkEvent(evt), sinkID);
|
||||
}
|
||||
|
||||
void SkAnimateMaker::reset() {
|
||||
deleteMembers();
|
||||
fChildren.reset();
|
||||
fHelpers.reset();
|
||||
fIDs.reset();
|
||||
fEvents.reset();
|
||||
fDisplayList.hardReset();
|
||||
}
|
||||
|
||||
void SkAnimateMaker::removeActive(SkActive* active) {
|
||||
if (active == NULL)
|
||||
return;
|
||||
fDisplayList.remove(active);
|
||||
}
|
||||
|
||||
bool SkAnimateMaker::resolveID(SkDisplayable* displayable, SkDisplayable* original) {
|
||||
SkString newID;
|
||||
bool success = computeID(original, NULL, &newID);
|
||||
if (success)
|
||||
setID(displayable, newID);
|
||||
return success;
|
||||
}
|
||||
|
||||
void SkAnimateMaker::setErrorString() {
|
||||
fErrorString.reset();
|
||||
if (fError.hasError()) {
|
||||
SkString err;
|
||||
if (fFileName.size() > 0)
|
||||
fErrorString.set(fFileName.c_str());
|
||||
else
|
||||
fErrorString.set("screenplay error");
|
||||
int line = fError.getLineNumber();
|
||||
if (line >= 0) {
|
||||
fErrorString.append(", ");
|
||||
fErrorString.append("line ");
|
||||
fErrorString.appendS32(line);
|
||||
}
|
||||
fErrorString.append(": ");
|
||||
fError.getErrorString(&err);
|
||||
fErrorString.append(err);
|
||||
#if defined SK_DEBUG
|
||||
SkDebugf("%s\n", fErrorString.c_str());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void SkAnimateMaker::setEnableTime(SkMSec appTime, SkMSec expectedTime) {
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
SkString debugOut;
|
||||
SkMSec time = getAppTime();
|
||||
debugOut.appendS32(time - fDebugTimeBase);
|
||||
debugOut.append(" set enable old enable=");
|
||||
debugOut.appendS32(fEnableTime - fDebugTimeBase);
|
||||
debugOut.append(" old adjust=");
|
||||
debugOut.appendS32(fAdjustedStart);
|
||||
debugOut.append(" new enable=");
|
||||
debugOut.appendS32(expectedTime - fDebugTimeBase);
|
||||
debugOut.append(" new adjust=");
|
||||
debugOut.appendS32(appTime - expectedTime);
|
||||
SkDebugf("%s\n", debugOut.c_str());
|
||||
#endif
|
||||
fAdjustedStart = appTime - expectedTime;
|
||||
fEnableTime = expectedTime;
|
||||
SkDisplayable** firstMovie = fMovies.begin();
|
||||
SkDisplayable** endMovie = fMovies.end();
|
||||
for (SkDisplayable** ptr = firstMovie; ptr < endMovie; ptr++) {
|
||||
SkDisplayMovie* movie = (SkDisplayMovie*) *ptr;
|
||||
movie->fMovie.fMaker->setEnableTime(appTime, expectedTime);
|
||||
}
|
||||
}
|
||||
|
||||
void SkAnimateMaker::setExtraPropertyCallBack(SkDisplayTypes type,
|
||||
SkScriptEngine::_propertyCallBack callBack, void* userStorage) {
|
||||
SkExtras** end = fExtras.end();
|
||||
for (SkExtras** extraPtr = fExtras.begin(); extraPtr < end; extraPtr++) {
|
||||
SkExtras* extra = *extraPtr;
|
||||
if (extra->definesType(type)) {
|
||||
extra->fExtraCallBack = callBack;
|
||||
extra->fExtraStorage = userStorage;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SkAnimateMaker::setID(SkDisplayable* displayable, const SkString& newID) {
|
||||
fIDs.set(newID.c_str(), displayable);
|
||||
#ifdef SK_DEBUG
|
||||
displayable->_id.set(newID);
|
||||
displayable->id = displayable->_id.c_str();
|
||||
#endif
|
||||
}
|
||||
|
||||
void SkAnimateMaker::setScriptError(const SkScriptEngine& engine) {
|
||||
SkString errorString;
|
||||
#ifdef SK_DEBUG
|
||||
engine.getErrorString(&errorString);
|
||||
#endif
|
||||
setErrorNoun(errorString);
|
||||
setErrorCode(SkDisplayXMLParserError::kErrorInScript);
|
||||
}
|
||||
|
||||
bool SkAnimateMaker::GetStep(const char* token, size_t len, void* stepPtr, SkScriptValue* value) {
|
||||
if (SK_LITERAL_STR_EQUAL("step", token, len)) {
|
||||
value->fOperand.fS32 = *(int32_t*) stepPtr;
|
||||
value->fType = SkType_Int;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/* libs/graphics/animator/SkAnimateMaker.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkAnimateMaker_DEFINED
|
||||
#define SkAnimateMaker_DEFINED
|
||||
|
||||
// #define SK_DEBUG_ANIMATION_TIMING
|
||||
|
||||
#include "SkAnimator.h"
|
||||
#include "SkBitmap.h"
|
||||
#include "SkIntArray.h"
|
||||
#include "SkDisplayEvents.h"
|
||||
#include "SkDisplayList.h"
|
||||
#include "SkDisplayScreenplay.h"
|
||||
#include "SkDisplayXMLParser.h"
|
||||
#include "SkScript.h"
|
||||
#include "SkString.h"
|
||||
#include "SkTDict.h"
|
||||
|
||||
// not sure where this little helper macro should go
|
||||
|
||||
|
||||
class SkActive;
|
||||
class SkAnimate;
|
||||
class SkCanvas;
|
||||
class SkDisplayable;
|
||||
class SkDrawable;
|
||||
class SkDump;
|
||||
class SkEvent;
|
||||
class SkEventSink;
|
||||
class SkExtras;
|
||||
class SkGroup;
|
||||
class SkPaint;
|
||||
class SkStream;
|
||||
|
||||
class SkAnimateMaker {
|
||||
public:
|
||||
SkAnimateMaker(SkAnimator* animator, SkCanvas* canvas, SkPaint* paint);
|
||||
~SkAnimateMaker();
|
||||
void appendActive(SkActive* );
|
||||
void childrenAdd(SkDisplayable* child) { *fChildren.append() = child; }
|
||||
void clearExtraPropertyCallBack(SkDisplayTypes type);
|
||||
bool computeID(SkDisplayable* displayable, SkDisplayable* parent, SkString* newID);
|
||||
SkDisplayable* createInstance(const char name[], size_t len);
|
||||
bool decodeStream(SkStream* stream);
|
||||
bool decodeURI(const char uri[]);
|
||||
void delayEnable(SkApply* apply, SkMSec time);
|
||||
void doDelayedEvent();
|
||||
bool doEvent(const SkEvent& event);
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void dump(const char* match);
|
||||
#endif
|
||||
int dynamicProperty(SkString& nameStr, SkDisplayable** );
|
||||
bool find(const char* str, SkDisplayable** displayablePtr) const {
|
||||
return fIDs.find(str, displayablePtr);
|
||||
}
|
||||
bool find(const char* str, size_t len, SkDisplayable** displayablePtr) const {
|
||||
return fIDs.find(str, len, displayablePtr);
|
||||
}
|
||||
bool findKey(SkDisplayable* displayable, const char** string) const {
|
||||
return fIDs.findKey(displayable, string);
|
||||
}
|
||||
// bool find(SkString& string, SkDisplayable** displayablePtr) {
|
||||
// return fIDs.find(string.c_str(), displayablePtr);
|
||||
// }
|
||||
SkAnimator* getAnimator() { return fAnimator; }
|
||||
SkMSec getAppTime() const; // call caller to get current time
|
||||
#ifdef SK_DEBUG
|
||||
SkAnimator* getRoot();
|
||||
#endif
|
||||
SkXMLParserError::ErrorCode getErrorCode() const { return fError.getErrorCode(); }
|
||||
SkMSec getInTime() { return fDisplayList.getTime(); }
|
||||
int getNativeCode() const { return fError.getNativeCode(); }
|
||||
bool hasError() { return fError.hasError(); }
|
||||
void helperAdd(SkDisplayable* trackMe);
|
||||
void helperRemove(SkDisplayable* alreadyTracked);
|
||||
void idsSet(const char* attrValue, size_t len, SkDisplayable* displayable) {
|
||||
fIDs.set(attrValue, len, displayable); }
|
||||
// void loadMovies();
|
||||
void notifyInval();
|
||||
void notifyInvalTime(SkMSec time);
|
||||
void postOnEnd(SkAnimateBase* animate, SkMSec end);
|
||||
void removeActive(SkActive* );
|
||||
void reset();
|
||||
bool resolveID(SkDisplayable* displayable, SkDisplayable* original);
|
||||
void setEnableTime(SkMSec appTime, SkMSec expectedTime);
|
||||
void setErrorCode(SkXMLParserError::ErrorCode err) { if (fError.hasError() == false) fError.INHERITED::setCode(err); }
|
||||
void setErrorCode(SkDisplayXMLParserError::ErrorCode err) { if (fError.hasError() == false) fError.setCode(err); }
|
||||
void setErrorNoun(const SkString& str) { if (fError.hasError() == false) fError.setNoun(str); }
|
||||
void setErrorString();
|
||||
void setExtraPropertyCallBack(SkDisplayTypes type, SkScriptEngine::_propertyCallBack , void* userStorage);
|
||||
void setID(SkDisplayable* displayable, const SkString& newID);
|
||||
void setInnerError(SkAnimateMaker* maker, const SkString& str) { fError.setInnerError(maker, str); }
|
||||
void setScriptError(const SkScriptEngine& );
|
||||
#ifdef SK_DEBUG
|
||||
void validate() { fDisplayList.validate(); }
|
||||
#else
|
||||
void validate() {}
|
||||
#endif
|
||||
SkDisplayEvent* fActiveEvent;
|
||||
SkMSec fAdjustedStart;
|
||||
SkCanvas* fCanvas;
|
||||
SkMSec fEnableTime;
|
||||
int fEndDepth; // passed parameter to onEndElement
|
||||
SkEvents fEvents;
|
||||
SkDisplayList fDisplayList;
|
||||
SkEventSinkID fHostEventSinkID;
|
||||
SkMSec fMinimumInterval;
|
||||
SkPaint* fPaint;
|
||||
SkAnimateMaker* fParentMaker;
|
||||
SkString fPrefix;
|
||||
SkDisplayScreenplay fScreenplay;
|
||||
const SkAnimator::Timeline* fTimeline;
|
||||
SkBool8 fInInclude;
|
||||
SkBool8 fInMovie;
|
||||
SkBool8 fFirstScriptError;
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
SkMSec fDebugTimeBase;
|
||||
#endif
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
SkString fDumpAnimated;
|
||||
SkBool8 fDumpEvents;
|
||||
SkBool8 fDumpGConditions;
|
||||
SkBool8 fDumpPosts;
|
||||
#endif
|
||||
private:
|
||||
void deleteMembers();
|
||||
static bool GetStep(const char* token, size_t len, void* stepPtr, SkScriptValue* );
|
||||
SkAnimateMaker& operator=(SkAnimateMaker& );
|
||||
SkTDDisplayableArray fChildren;
|
||||
SkTDDisplayableArray fDelayed; // SkApply that contain delayed enable events
|
||||
SkDisplayXMLParserError fError;
|
||||
SkString fErrorString;
|
||||
SkTDArray<SkExtras*> fExtras;
|
||||
SkString fFileName;
|
||||
SkTDDisplayableArray fHelpers; // helper displayables
|
||||
SkBool8 fLoaded;
|
||||
SkTDDisplayableArray fMovies;
|
||||
SkTDict<SkDisplayable*> fIDs;
|
||||
SkAnimator* fAnimator;
|
||||
friend class SkAdd;
|
||||
friend class SkAnimateBase;
|
||||
friend class SkDisplayXMLParser;
|
||||
friend class SkAnimator;
|
||||
friend class SkAnimatorScript;
|
||||
friend class SkApply;
|
||||
friend class SkDisplayMovie;
|
||||
friend class SkDisplayType;
|
||||
friend class SkEvents;
|
||||
friend class SkGroup;
|
||||
friend struct SkMemberInfo;
|
||||
};
|
||||
|
||||
#endif // SkAnimateMaker_DEFINED
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/* libs/graphics/animator/SkAnimateProperties.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkAnimateProperties_DEFINED
|
||||
#define SkAnimateProperties_DEFINED
|
||||
|
||||
enum SkAnimateBase_Properties {
|
||||
SK_PROPERTY(dynamic),
|
||||
SK_PROPERTY(mirror),
|
||||
SK_PROPERTY(reset),
|
||||
SK_PROPERTY(step),
|
||||
SK_PROPERTY(values)
|
||||
};
|
||||
|
||||
#endif // SkAnimateProperties_DEFINED
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--This file is auto-generated by the XML Schema Designer. It holds layout information for components on the designer surface.-->
|
||||
@@ -0,0 +1,98 @@
|
||||
/* libs/graphics/animator/SkAnimateSet.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkAnimateSet.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkAnimateProperties.h"
|
||||
#include "SkParse.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkSet::fInfo[] = {
|
||||
SK_MEMBER(begin, MSec),
|
||||
SK_MEMBER(dur, MSec),
|
||||
SK_MEMBER_PROPERTY(dynamic, Boolean),
|
||||
SK_MEMBER(field, String),
|
||||
// SK_MEMBER(formula, DynamicString),
|
||||
SK_MEMBER(lval, DynamicString),
|
||||
// SK_MEMBER_PROPERTY(reset, Boolean),
|
||||
SK_MEMBER_PROPERTY(step, Int),
|
||||
SK_MEMBER(target, DynamicString),
|
||||
SK_MEMBER(to, DynamicString)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkSet);
|
||||
|
||||
SkSet::SkSet() {
|
||||
dur = 1;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkSet::dump(SkAnimateMaker* maker) {
|
||||
INHERITED::dump(maker);
|
||||
if (dur != 1) {
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf("dur=\"%g\" ", SkScalarToFloat(SkScalarDiv(dur,1000)));
|
||||
#else
|
||||
SkDebugf("dur=\"%x\" ", SkScalarDiv(dur,1000));
|
||||
#endif
|
||||
}
|
||||
//don't want double />\n's
|
||||
SkDebugf("/>\n");
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
void SkSet::refresh(SkAnimateMaker& maker) {
|
||||
fFieldInfo->setValue(maker, &fValues, 0, fFieldInfo->fCount, NULL,
|
||||
fFieldInfo->getType(), to);
|
||||
}
|
||||
|
||||
void SkSet::onEndElement(SkAnimateMaker& maker) {
|
||||
if (resolveCommon(maker) == false)
|
||||
return;
|
||||
if (fFieldInfo == NULL) {
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kFieldNotInTarget);
|
||||
return;
|
||||
}
|
||||
fReset = dur != 1;
|
||||
SkDisplayTypes outType = fFieldInfo->getType();
|
||||
int comps = outType == SkType_String || outType == SkType_DynamicString ? 1 :
|
||||
fFieldInfo->getSize((const SkDisplayable*) fTarget) / sizeof(int);
|
||||
if (fValues.getType() == SkType_Unknown) {
|
||||
fValues.setType(outType);
|
||||
fValues.setCount(comps);
|
||||
if (outType == SkType_String || outType == SkType_DynamicString)
|
||||
fValues[0].fString = SkNEW(SkString);
|
||||
else
|
||||
memset(fValues.begin(), 0, fValues.count() * sizeof(fValues.begin()[0]));
|
||||
} else {
|
||||
SkASSERT(fValues.getType() == outType);
|
||||
if (fFieldInfo->fType == SkType_Array)
|
||||
comps = fValues.count();
|
||||
else
|
||||
SkASSERT(fValues.count() == comps);
|
||||
}
|
||||
if (formula.size() > 0) {
|
||||
comps = 1;
|
||||
outType = SkType_MSec;
|
||||
}
|
||||
fFieldInfo->setValue(maker, &fValues, fFieldOffset, comps, this, outType, formula.size() > 0 ? formula : to);
|
||||
fComponents = fValues.count();
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/* libs/graphics/animator/SkAnimateSet.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkAnimateSet_DEFINED
|
||||
#define SkAnimateSet_DEFINED
|
||||
|
||||
#include "SkAnimate.h"
|
||||
|
||||
class SkSet : public SkAnimate {
|
||||
DECLARE_MEMBER_INFO(Set);
|
||||
SkSet();
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
virtual void refresh(SkAnimateMaker& );
|
||||
private:
|
||||
typedef SkAnimate INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkAnimateSet_DEFINED
|
||||
|
||||
@@ -0,0 +1,724 @@
|
||||
/* libs/graphics/animator/SkAnimator.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkAnimator.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkDisplayMovie.h"
|
||||
#include "SkDisplayTypes.h"
|
||||
#include "SkDisplayXMLParser.h"
|
||||
#include "SkStream.h"
|
||||
#include "SkScript.h"
|
||||
#include "SkScript2.h" // compiled script experiment
|
||||
#include "SkSystemEventTypes.h"
|
||||
#include "SkTypedArray.h"
|
||||
#ifdef ANDROID
|
||||
#include "SkDrawExtraPathEffect.h"
|
||||
#endif
|
||||
#ifdef SK_DEBUG
|
||||
#include "SkTime.h"
|
||||
#endif
|
||||
|
||||
#if defined SK_BUILD_FOR_WIN32 && defined SK_DEBUG
|
||||
#define _static
|
||||
extern const char gMathPrimerText[];
|
||||
extern const char gMathPrimerBinary[];
|
||||
#else
|
||||
#define _static static
|
||||
#endif
|
||||
|
||||
#if !defined SK_BUILD_FOR_BREW || defined SK_DEBUG
|
||||
_static const char gMathPrimerText[] =
|
||||
"<screenplay>"
|
||||
"<Math id=\"Math\"/>"
|
||||
"<Number id=\"Number\"/>"
|
||||
"</screenplay>";
|
||||
#endif
|
||||
|
||||
#if defined SK_BUILD_FOR_BREW || defined SK_DEBUG
|
||||
_static const char gMathPrimerBinary[] =
|
||||
"\x0Ascreenplay\x04Mathbid\x04Math@@"; // !!! now out of date -- does not include Number
|
||||
#endif
|
||||
|
||||
#if defined SK_BUILD_FOR_BREW
|
||||
#define gMathPrimer gMathPrimerBinary
|
||||
#else
|
||||
#define gMathPrimer gMathPrimerText
|
||||
#endif
|
||||
|
||||
SkAnimator::SkAnimator() : fMaker(NULL) {
|
||||
initialize();
|
||||
}
|
||||
|
||||
SkAnimator::~SkAnimator() {
|
||||
SkDELETE(fMaker);
|
||||
}
|
||||
|
||||
void SkAnimator::addExtras(SkExtras* extras) {
|
||||
*fMaker->fExtras.append() = extras;
|
||||
}
|
||||
|
||||
bool SkAnimator::appendStream(SkStream* stream) {
|
||||
return decodeStream(stream);
|
||||
}
|
||||
|
||||
bool SkAnimator::decodeMemory(const void* buffer, size_t size)
|
||||
{
|
||||
fMaker->fFileName.reset();
|
||||
SkDisplayXMLParser parser(*fMaker);
|
||||
return parser.parse((const char*)buffer, size);
|
||||
}
|
||||
|
||||
bool SkAnimator::decodeStream(SkStream* stream)
|
||||
{
|
||||
SkDisplayXMLParser parser(*fMaker);
|
||||
bool result = parser.parse(*stream);
|
||||
fMaker->setErrorString();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SkAnimator::decodeDOM(const SkDOM& dom, const SkDOMNode* node)
|
||||
{
|
||||
fMaker->fFileName.reset();
|
||||
SkDisplayXMLParser parser(*fMaker);
|
||||
return parser.parse(dom, node);
|
||||
}
|
||||
|
||||
bool SkAnimator::decodeURI(const char uri[]) {
|
||||
// SkDebugf("animator decode %s\n", uri);
|
||||
|
||||
// SkStream* stream = SkStream::GetURIStream(fMaker->fPrefix.c_str(), uri);
|
||||
SkStream* stream = new SkFILEStream(uri);
|
||||
|
||||
SkAutoTDelete<SkStream> autoDel(stream);
|
||||
setURIBase(uri);
|
||||
return decodeStream(stream);
|
||||
}
|
||||
|
||||
bool SkAnimator::doCharEvent(SkUnichar code) {
|
||||
if (code == 0)
|
||||
return false;
|
||||
struct SkEventState state;
|
||||
state.fCode = code;
|
||||
fMaker->fEnableTime = fMaker->getAppTime();
|
||||
bool result = fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kKeyChar, &state);
|
||||
fMaker->notifyInval();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SkAnimator::doClickEvent(int clickState, SkScalar x, SkScalar y) {
|
||||
SkASSERT(clickState >= 0 && clickState <= 2);
|
||||
struct SkEventState state;
|
||||
state.fX = x;
|
||||
state.fY = y;
|
||||
fMaker->fEnableTime = fMaker->getAppTime();
|
||||
bool result = fMaker->fEvents.doEvent(*fMaker,
|
||||
clickState == 0 ? SkDisplayEvent::kMouseDown :
|
||||
clickState == 1 ? SkDisplayEvent::kMouseDrag :
|
||||
SkDisplayEvent::kMouseUp, &state);
|
||||
fMaker->notifyInval();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SkAnimator::doKeyEvent(SkKey code) {
|
||||
if (code == 0)
|
||||
return false;
|
||||
struct SkEventState state;
|
||||
state.fCode = code;
|
||||
fMaker->fEnableTime = fMaker->getAppTime();
|
||||
bool result = fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kKeyPress, &state);
|
||||
fMaker->notifyInval();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SkAnimator::doKeyUpEvent(SkKey code) {
|
||||
if (code == 0)
|
||||
return false;
|
||||
struct SkEventState state;
|
||||
state.fCode = code;
|
||||
fMaker->fEnableTime = fMaker->getAppTime();
|
||||
bool result = fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kKeyPressUp, &state);
|
||||
fMaker->notifyInval();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SkAnimator::doUserEvent(const SkEvent& evt) {
|
||||
fMaker->fEnableTime = fMaker->getAppTime();
|
||||
return onEvent(evt);
|
||||
}
|
||||
|
||||
SkAnimator::DifferenceType SkAnimator::draw(SkCanvas* canvas, SkPaint* paint, SkMSec time) {
|
||||
if (paint == NULL)
|
||||
return draw(canvas, time);
|
||||
fMaker->fScreenplay.time = time;
|
||||
fMaker->fCanvas = canvas;
|
||||
fMaker->fPaint = paint;
|
||||
fMaker->fDisplayList.fHasUnion = false;
|
||||
int result = fMaker->fDisplayList.draw(*fMaker, time);
|
||||
if (result)
|
||||
result += fMaker->fDisplayList.fHasUnion;
|
||||
return (DifferenceType) result;
|
||||
}
|
||||
|
||||
SkAnimator::DifferenceType SkAnimator::draw(SkCanvas* canvas, SkMSec time) {
|
||||
SkPaint paint;
|
||||
return draw(canvas, &paint, time);
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void SkAnimator::eventDone(const SkEvent& ) {
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkAnimator::findClickEvent(SkScalar x, SkScalar y) {
|
||||
struct SkEventState state;
|
||||
state.fDisable = true;
|
||||
state.fX = x;
|
||||
state.fY = y;
|
||||
fMaker->fEnableTime = fMaker->getAppTime();
|
||||
bool result = fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kMouseDown, &state);
|
||||
fMaker->notifyInval();
|
||||
return result;
|
||||
}
|
||||
|
||||
const SkAnimator* SkAnimator::getAnimator(const SkDisplayable* displayable) const {
|
||||
if (displayable->getType() != SkType_Movie)
|
||||
return NULL;
|
||||
const SkDisplayMovie* movie = (const SkDisplayMovie*) displayable;
|
||||
return movie->getAnimator();
|
||||
}
|
||||
|
||||
const SkDisplayable* SkAnimator::getElement(const char* id) {
|
||||
SkDisplayable* element;
|
||||
if (fMaker->find(id, &element) == false)
|
||||
return NULL;
|
||||
return (const SkDisplayable*) element;
|
||||
}
|
||||
|
||||
SkElementType SkAnimator::getElementType(const SkDisplayable* ae) {
|
||||
SkDisplayable* element = (SkDisplayable*) ae;
|
||||
const SkMemberInfo* info = SkDisplayType::GetMembers(fMaker, element->getType(), NULL);
|
||||
return (SkElementType) SkDisplayType::Find(fMaker, info);
|
||||
}
|
||||
|
||||
SkElementType SkAnimator::getElementType(const char* id) {
|
||||
const SkDisplayable* element = getElement(id);
|
||||
return getElementType(element);
|
||||
}
|
||||
|
||||
const SkMemberInfo* SkAnimator::getField(const SkDisplayable* ae, const char* field) {
|
||||
SkDisplayable* element = (SkDisplayable*) ae;
|
||||
const SkMemberInfo* info = element->getMember(field);
|
||||
return (const SkMemberInfo*) info;
|
||||
}
|
||||
|
||||
const SkMemberInfo* SkAnimator::getField(const char* elementID, const char* field) {
|
||||
const SkDisplayable* element = getElement(elementID);
|
||||
return getField(element, field);
|
||||
}
|
||||
|
||||
SkFieldType SkAnimator::getFieldType(const SkMemberInfo* ai) {
|
||||
const SkMemberInfo* info = (const SkMemberInfo*) ai;
|
||||
return (SkFieldType) info->getType();
|
||||
}
|
||||
|
||||
SkFieldType SkAnimator::getFieldType(const char* id, const char* fieldID) {
|
||||
const SkMemberInfo* field = getField(id, fieldID);
|
||||
return getFieldType(field);
|
||||
}
|
||||
|
||||
static bool getArrayCommon(const SkDisplayable* ae, const SkMemberInfo* ai,
|
||||
int index, SkOperand* operand, SkDisplayTypes type) {
|
||||
const SkDisplayable* element = (const SkDisplayable*) ae;
|
||||
const SkMemberInfo* info = (const SkMemberInfo*) ai;
|
||||
SkASSERT(info->fType == SkType_Array);
|
||||
return info->getArrayValue(element, index, operand);
|
||||
}
|
||||
|
||||
int32_t SkAnimator::getArrayInt(const SkDisplayable* ae,
|
||||
const SkMemberInfo* ai, int index) {
|
||||
SkOperand operand;
|
||||
bool result = getArrayCommon(ae, ai, index, &operand, SkType_Int);
|
||||
return result ? operand.fS32 : SK_NaN32;
|
||||
}
|
||||
|
||||
int32_t SkAnimator::getArrayInt(const char* id, const char* fieldID, int index) {
|
||||
const SkDisplayable* element = getElement(id);
|
||||
if (element == NULL)
|
||||
return SK_NaN32;
|
||||
const SkMemberInfo* field = getField(element, fieldID);
|
||||
if (field == NULL)
|
||||
return SK_NaN32;
|
||||
return getArrayInt(element, field, index);
|
||||
}
|
||||
|
||||
SkScalar SkAnimator::getArrayScalar(const SkDisplayable* ae,
|
||||
const SkMemberInfo* ai, int index) {
|
||||
SkOperand operand;
|
||||
bool result = getArrayCommon(ae, ai, index, &operand, SkType_Float);
|
||||
return result ? operand.fScalar : SK_ScalarNaN;
|
||||
}
|
||||
|
||||
SkScalar SkAnimator::getArrayScalar(const char* id, const char* fieldID, int index) {
|
||||
const SkDisplayable* element = getElement(id);
|
||||
if (element == NULL)
|
||||
return SK_ScalarNaN;
|
||||
const SkMemberInfo* field = getField(element, fieldID);
|
||||
if (field == NULL)
|
||||
return SK_ScalarNaN;
|
||||
return getArrayScalar(element, field, index);
|
||||
}
|
||||
|
||||
const char* SkAnimator::getArrayString(const SkDisplayable* ae,
|
||||
const SkMemberInfo* ai, int index) {
|
||||
SkOperand operand;
|
||||
bool result = getArrayCommon(ae, ai, index, &operand, SkType_String);
|
||||
return result ? operand.fString->c_str() : NULL;
|
||||
}
|
||||
|
||||
const char* SkAnimator::getArrayString(const char* id, const char* fieldID, int index) {
|
||||
const SkDisplayable* element = getElement(id);
|
||||
if (element == NULL)
|
||||
return NULL;
|
||||
const SkMemberInfo* field = getField(element, fieldID);
|
||||
if (field == NULL)
|
||||
return NULL;
|
||||
return getArrayString(element, field, index);
|
||||
}
|
||||
|
||||
SkMSec SkAnimator::getInterval() {
|
||||
return fMaker->fMinimumInterval == (SkMSec) -1 ? 0 : fMaker->fMinimumInterval;
|
||||
}
|
||||
|
||||
void SkAnimator::getInvalBounds(SkRect* inval) {
|
||||
if (fMaker->fDisplayList.fHasUnion) {
|
||||
inval->fLeft = SkIntToScalar(fMaker->fDisplayList.fInvalBounds.fLeft);
|
||||
inval->fTop = SkIntToScalar(fMaker->fDisplayList.fInvalBounds.fTop);
|
||||
inval->fRight = SkIntToScalar(fMaker->fDisplayList.fInvalBounds.fRight);
|
||||
inval->fBottom = SkIntToScalar(fMaker->fDisplayList.fInvalBounds.fBottom);
|
||||
} else {
|
||||
inval->fLeft = inval->fTop = -SK_ScalarMax;
|
||||
inval->fRight = inval->fBottom = SK_ScalarMax;
|
||||
}
|
||||
}
|
||||
|
||||
const SkXMLParserError* SkAnimator::getParserError() {
|
||||
return &fMaker->fError;
|
||||
}
|
||||
|
||||
const char* SkAnimator::getParserErrorString() {
|
||||
if (fMaker->fErrorString.size() == 0 && fMaker->fError.hasError())
|
||||
fMaker->setErrorString();
|
||||
return fMaker->fErrorString.c_str();
|
||||
}
|
||||
|
||||
int32_t SkAnimator::getInt(const SkDisplayable* element, const SkMemberInfo* info) {
|
||||
if (info->fType != SkType_MemberProperty) {
|
||||
SkOperand operand;
|
||||
if (info->getType() == SkType_Int) {
|
||||
info->getValue(element, &operand, 1);
|
||||
return operand.fS32;
|
||||
}
|
||||
return SK_NaN32;
|
||||
}
|
||||
SkScriptValue scriptValue;
|
||||
bool success = element->getProperty(info->propertyIndex(), &scriptValue);
|
||||
if (success && scriptValue.fType == SkType_Int)
|
||||
return scriptValue.fOperand.fS32;
|
||||
return SK_NaN32;
|
||||
}
|
||||
|
||||
int32_t SkAnimator::getInt(const char* id, const char* fieldID) {
|
||||
const SkDisplayable* element = getElement(id);
|
||||
if (element == NULL)
|
||||
return SK_NaN32;
|
||||
const SkMemberInfo* field = getField(element, fieldID);
|
||||
if (field == NULL)
|
||||
return SK_NaN32;
|
||||
return getInt(element, field);
|
||||
}
|
||||
|
||||
SkScalar SkAnimator::getScalar(const SkDisplayable* element, const SkMemberInfo* info) {
|
||||
if (info->fType != SkType_MemberProperty) {
|
||||
SkOperand operand;
|
||||
if (info->getType() == SkType_Float) {
|
||||
info->getValue(element, &operand, 1);
|
||||
return operand.fScalar;
|
||||
}
|
||||
return SK_ScalarNaN;
|
||||
}
|
||||
SkScriptValue scriptValue;
|
||||
bool success = element->getProperty(info->propertyIndex(), &scriptValue);
|
||||
if (success && scriptValue.fType == SkType_Float)
|
||||
return scriptValue.fOperand.fScalar;
|
||||
return SK_ScalarNaN;
|
||||
}
|
||||
|
||||
SkScalar SkAnimator::getScalar(const char* id, const char* fieldID) {
|
||||
const SkDisplayable* element = getElement(id);
|
||||
if (element == NULL)
|
||||
return SK_ScalarNaN;
|
||||
const SkMemberInfo* field = getField(element, fieldID);
|
||||
if (field == NULL)
|
||||
return SK_ScalarNaN;
|
||||
return getScalar(element, field);
|
||||
}
|
||||
|
||||
const char* SkAnimator::getString(const SkDisplayable* ae,
|
||||
const SkMemberInfo* ai) {
|
||||
const SkDisplayable* element = (const SkDisplayable*) ae;
|
||||
const SkMemberInfo* info = (const SkMemberInfo*) ai;
|
||||
SkString* temp;
|
||||
info->getString(element, &temp);
|
||||
return temp->c_str();
|
||||
}
|
||||
|
||||
const char* SkAnimator::getString(const char* id, const char* fieldID) {
|
||||
const SkDisplayable* element = getElement(id);
|
||||
if (element == NULL)
|
||||
return NULL;
|
||||
const SkMemberInfo* field = getField(element, fieldID);
|
||||
if (field == NULL)
|
||||
return NULL;
|
||||
return getString(element, field);
|
||||
}
|
||||
|
||||
const char* SkAnimator::getURIBase() {
|
||||
return fMaker->fPrefix.c_str();
|
||||
}
|
||||
|
||||
void SkAnimator::initialize() {
|
||||
SkDELETE(fMaker);
|
||||
fMaker = SkNEW_ARGS(SkAnimateMaker, (this, NULL, NULL));
|
||||
decodeMemory(gMathPrimer, sizeof(gMathPrimer)-1);
|
||||
#ifdef ANDROID
|
||||
InitializeSkExtraPathEffects(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
bool SkAnimator::isTrackingEvents() {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkAnimator::onEvent(const SkEvent& evt) {
|
||||
#ifdef SK_DEBUG
|
||||
SkAnimator* root = fMaker->getRoot();
|
||||
if (root == NULL)
|
||||
root = this;
|
||||
if (root->isTrackingEvents())
|
||||
root->eventDone(evt);
|
||||
#endif
|
||||
if (evt.isType(SK_EventType_OnEnd)) {
|
||||
SkEventState eventState;
|
||||
bool success = evt.findPtr("anim", (void**) &eventState.fDisplayable);
|
||||
SkASSERT(success);
|
||||
success = evt.findS32("time", (int32_t*) &fMaker->fEnableTime);
|
||||
SkASSERT(success);
|
||||
fMaker->fAdjustedStart = fMaker->getAppTime() - fMaker->fEnableTime;
|
||||
fMaker->fEvents.doEvent(*fMaker, SkDisplayEvent::kOnEnd, &eventState);
|
||||
fMaker->fAdjustedStart = 0;
|
||||
goto inval;
|
||||
}
|
||||
if (evt.isType(SK_EventType_Delay)) {
|
||||
fMaker->doDelayedEvent();
|
||||
goto inval;
|
||||
}
|
||||
{
|
||||
const char* id = evt.findString("id");
|
||||
if (id == NULL)
|
||||
return false;
|
||||
SkDisplayable** firstMovie = fMaker->fMovies.begin();
|
||||
SkDisplayable** endMovie = fMaker->fMovies.end();
|
||||
for (SkDisplayable** ptr = firstMovie; ptr < endMovie; ptr++) {
|
||||
SkDisplayMovie* movie = (SkDisplayMovie*) *ptr;
|
||||
movie->doEvent(evt);
|
||||
}
|
||||
{
|
||||
SkDisplayable* event;
|
||||
if (fMaker->find(id, &event) == false)
|
||||
return false;
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
SkString debugOut;
|
||||
SkMSec realTime = fMaker->getAppTime();
|
||||
debugOut.appendS32(realTime - fMaker->fDebugTimeBase);
|
||||
debugOut.append(" onEvent id=");
|
||||
debugOut.append(id);
|
||||
#endif
|
||||
SkMSec time = evt.getFast32();
|
||||
if (time != 0) {
|
||||
SkMSec app = fMaker->getAppTime();
|
||||
fMaker->setEnableTime(app, time);
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
debugOut.append(" time=");
|
||||
debugOut.appendS32(time - fMaker->fDebugTimeBase);
|
||||
debugOut.append(" adjust=");
|
||||
debugOut.appendS32(fMaker->fAdjustedStart);
|
||||
#endif
|
||||
}
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
SkDebugf("%s\n", debugOut.c_str());
|
||||
#endif
|
||||
SkASSERT(event->isEvent());
|
||||
SkDisplayEvent* displayEvent = (SkDisplayEvent*) event;
|
||||
displayEvent->populateInput(*fMaker, evt);
|
||||
displayEvent->enableEvent(*fMaker);
|
||||
}
|
||||
}
|
||||
inval:
|
||||
fMaker->notifyInval();
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkAnimator::onEventPost(SkEvent* evt, SkEventSinkID sinkID)
|
||||
{
|
||||
#ifdef SK_DEBUG
|
||||
SkAnimator* root = fMaker->getRoot();
|
||||
if (root) {
|
||||
root->onEventPost(evt, sinkID);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
SkASSERT(sinkID == this->getSinkID() || this->getHostEventSinkID() == sinkID);
|
||||
#endif
|
||||
SkEvent::Post(evt, sinkID);
|
||||
}
|
||||
|
||||
void SkAnimator::onEventPostTime(SkEvent* evt, SkEventSinkID sinkID, SkMSec time)
|
||||
{
|
||||
#ifdef SK_DEBUG
|
||||
SkAnimator* root = fMaker->getRoot();
|
||||
if (root) {
|
||||
root->onEventPostTime(evt, sinkID, time);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
SkASSERT(sinkID == this->getSinkID() || this->getHostEventSinkID() == sinkID);
|
||||
#endif
|
||||
SkEvent::PostTime(evt, sinkID, time);
|
||||
}
|
||||
|
||||
void SkAnimator::reset() {
|
||||
fMaker->fDisplayList.reset();
|
||||
}
|
||||
|
||||
SkEventSinkID SkAnimator::getHostEventSinkID() const {
|
||||
return fMaker->fHostEventSinkID;
|
||||
}
|
||||
|
||||
void SkAnimator::setHostEventSinkID(SkEventSinkID target) {
|
||||
fMaker->fHostEventSinkID = target;
|
||||
}
|
||||
|
||||
void SkAnimator::onSetHostHandler(Handler ) {
|
||||
}
|
||||
|
||||
void SkAnimator::setJavaOwner(Handler ) {
|
||||
}
|
||||
|
||||
bool SkAnimator::setArrayString(const char* id, const char* fieldID, const char** array, int num)
|
||||
{
|
||||
SkTypedArray tArray(SkType_String);
|
||||
tArray.setCount(num);
|
||||
for (int i = 0; i < num; i++) {
|
||||
SkOperand op;
|
||||
op.fString = new SkString(array[i]);
|
||||
tArray[i] = op;
|
||||
}
|
||||
return setArray(id, fieldID, tArray);
|
||||
}
|
||||
bool SkAnimator::setArrayInt(const char* id, const char* fieldID, const int* array, int num)
|
||||
{
|
||||
SkTypedArray tArray(SkType_Int);
|
||||
tArray.setCount(num);
|
||||
for (int i = 0; i < num; i++) {
|
||||
SkOperand op;
|
||||
op.fS32 = array[i];
|
||||
tArray[i] = op;
|
||||
}
|
||||
return setArray(id, fieldID, tArray);
|
||||
}
|
||||
|
||||
bool SkAnimator::setArray(SkDisplayable* element, const SkMemberInfo* info, SkTypedArray array) {
|
||||
if (info->fType != SkType_Array)
|
||||
return false; //the field is not an array
|
||||
//i think we can handle the case where the displayable itself is an array differently from the
|
||||
//case where it has an array - for one thing, if it is an array, i think we can change its type
|
||||
//if it's not, we cannot
|
||||
SkDisplayTypes type = element->getType();
|
||||
if (type == SkType_Array) {
|
||||
SkDisplayArray* dispArray = (SkDisplayArray*) element;
|
||||
dispArray->values = array;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false; //currently i don't care about this case
|
||||
}
|
||||
|
||||
bool SkAnimator::setArray(const char* id, const char* fieldID, SkTypedArray array) {
|
||||
SkDisplayable* element = (SkDisplayable*) getElement(id);
|
||||
//should I go ahead and change all 'NULL's to 'NULL'?
|
||||
if (element == NULL)
|
||||
return false;
|
||||
const SkMemberInfo* field = getField(element, fieldID);
|
||||
if (field == NULL)
|
||||
return false;
|
||||
return setArray(element, field, array);
|
||||
}
|
||||
|
||||
bool SkAnimator::setInt(SkDisplayable* element, const SkMemberInfo* info, int32_t s32) {
|
||||
if (info->fType != SkType_MemberProperty) {
|
||||
SkOperand operand;
|
||||
operand.fS32 = s32;
|
||||
SkASSERT(info->getType() == SkType_Int);
|
||||
info->setValue(element, &operand, 1);
|
||||
} else {
|
||||
SkScriptValue scriptValue;
|
||||
scriptValue.fType = SkType_Int;
|
||||
scriptValue.fOperand.fS32 = s32;
|
||||
element->setProperty(info->propertyIndex(), scriptValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkAnimator::setInt(const char* id, const char* fieldID, int32_t s32) {
|
||||
SkDisplayable* element = (SkDisplayable*) getElement(id);
|
||||
if (element == NULL)
|
||||
return false;
|
||||
const SkMemberInfo* field = getField(element, fieldID);
|
||||
if (field == NULL)
|
||||
return false;
|
||||
return setInt(element, field, s32);
|
||||
}
|
||||
|
||||
bool SkAnimator::setScalar(SkDisplayable* element, const SkMemberInfo* info, SkScalar scalar) {
|
||||
if (info->fType != SkType_MemberProperty) {
|
||||
SkOperand operand;
|
||||
operand.fScalar = scalar;
|
||||
SkASSERT(info->getType() == SkType_Float);
|
||||
info->setValue(element, &operand, 1);
|
||||
} else {
|
||||
SkScriptValue scriptValue;
|
||||
scriptValue.fType = SkType_Float;
|
||||
scriptValue.fOperand.fScalar = scalar;
|
||||
element->setProperty(info->propertyIndex(), scriptValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkAnimator::setScalar(const char* id, const char* fieldID, SkScalar scalar) {
|
||||
SkDisplayable* element = (SkDisplayable*) getElement(id);
|
||||
if (element == NULL)
|
||||
return false;
|
||||
const SkMemberInfo* field = getField(element, fieldID);
|
||||
if (field == NULL)
|
||||
return false;
|
||||
return setScalar(element, field, scalar);
|
||||
}
|
||||
|
||||
bool SkAnimator::setString(SkDisplayable* element,
|
||||
const SkMemberInfo* info, const char* str) {
|
||||
// !!! until this is fixed, can't call script with global references from here
|
||||
info->setValue(*fMaker, NULL, 0, info->fCount, element, info->getType(), str, strlen(str));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkAnimator::setString(const char* id, const char* fieldID, const char* str) {
|
||||
SkDisplayable* element = (SkDisplayable*) getElement(id);
|
||||
if (element == NULL)
|
||||
return false;
|
||||
const SkMemberInfo* field = getField(element, fieldID);
|
||||
if (field == NULL)
|
||||
return false;
|
||||
return setString(element, field, str);
|
||||
}
|
||||
|
||||
void SkAnimator::setTimeline(const Timeline& timeline) {
|
||||
fMaker->fTimeline = &timeline;
|
||||
}
|
||||
|
||||
void SkAnimator::setURIBase(const char* uri) {
|
||||
if (uri)
|
||||
{
|
||||
const char* tail = strrchr(uri, '/');
|
||||
if (tail) {
|
||||
SkString prefix(uri, tail - uri + 1);
|
||||
if (uri[0] != '.' /*SkStream::IsAbsoluteURI(uri)*/)
|
||||
fMaker->fPrefix.reset();
|
||||
fMaker->fPrefix.append(prefix);
|
||||
fMaker->fFileName.set(tail + 1);
|
||||
} else
|
||||
fMaker->fFileName.set(uri);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
bool SkAnimator::NoLeaks() {
|
||||
#ifdef SK_BUILD_FOR_MAC
|
||||
if (SkDisplayable::fAllocations.count() == 0)
|
||||
return true;
|
||||
// return SkDisplayable::fAllocationCount == 0;
|
||||
SkDebugf("!!! leaked %d displayables:\n", SkDisplayable::fAllocations.count());
|
||||
for (SkDisplayable** leak = SkDisplayable::fAllocations.begin(); leak < SkDisplayable::fAllocations.end(); leak++)
|
||||
SkDebugf("%08x %s\n", *leak, (*leak)->id);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SK_SUPPORT_UNITTEST
|
||||
#include "SkAnimatorScript.h"
|
||||
#include "SkBase64.h"
|
||||
#include "SkParse.h"
|
||||
#include "SkMemberInfo.h"
|
||||
|
||||
#define unittestline(type) { #type , type::UnitTest }
|
||||
#endif
|
||||
|
||||
|
||||
void SkAnimator::Init(bool runUnitTests) {
|
||||
#ifdef SK_SUPPORT_UNITTEST
|
||||
if (runUnitTests == false)
|
||||
return;
|
||||
static const struct {
|
||||
const char* fTypeName;
|
||||
void (*fUnitTest)( );
|
||||
} gUnitTests[] = {
|
||||
unittestline(SkBase64),
|
||||
unittestline(SkDisplayType),
|
||||
unittestline(SkParse),
|
||||
unittestline(SkScriptEngine),
|
||||
// unittestline(SkScriptEngine2), // compiled script experiment
|
||||
unittestline(SkAnimatorScript)
|
||||
};
|
||||
for (int i = 0; i < (int)SK_ARRAY_COUNT(gUnitTests); i++)
|
||||
{
|
||||
SkDebugf("SkAnimator: Running UnitTest for %s\n", gUnitTests[i].fTypeName);
|
||||
gUnitTests[i].fUnitTest();
|
||||
SkDebugf("SkAnimator: End UnitTest for %s\n", gUnitTests[i].fTypeName);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SkAnimator::Term() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,607 @@
|
||||
/* libs/graphics/animator/SkAnimatorScript.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkAnimatorScript.h"
|
||||
#include "SkAnimateBase.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkDisplayTypes.h"
|
||||
#include "SkExtras.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkParse.h"
|
||||
|
||||
static const SkDisplayEnumMap gEnumMaps[] = {
|
||||
{ SkType_AddMode, "indirect|immediate" },
|
||||
{ SkType_Align, "left|center|right" },
|
||||
{ SkType_ApplyMode, "create|immediate|once" },
|
||||
{ SkType_ApplyTransition, "normal|reverse" },
|
||||
{ SkType_BitmapEncoding, "jpeg|png" },
|
||||
{ SkType_BitmapFormat, "none|A1|A8|Index8|RGB16|RGB32" },
|
||||
{ SkType_Boolean, "false|true" },
|
||||
{ SkType_Cap, "butt|round|square" },
|
||||
{ SkType_EventCode, "none|leftSoftKey|rightSoftKey|home|back|send|end|key0|key1|key2|key3|key4|key5|key6|key7|key8|key9|star|hash|up|down|left|right|OK|volUp|volDown|camera" },
|
||||
{ SkType_EventKind, "none|keyChar|keyPress|keyPressUp|mouseDown|mouseDrag|mouseMove|mouseUp|onEnd|onLoad|user" },
|
||||
{ SkType_EventMode, "deferred|immediate" },
|
||||
{ SkType_FillType, "winding|evenOdd" },
|
||||
{ SkType_FilterType, "none|bilinear" },
|
||||
{ SkType_FontStyle, "normal|bold|italic|boldItalic" },
|
||||
{ SkType_FromPathMode, "normal|angle|position" },
|
||||
{ SkType_Join, "miter|round|blunt" },
|
||||
{ SkType_MaskFilterBlurStyle, "normal|solid|outer|inner" },
|
||||
{ SkType_PathDirection, "cw|ccw" },
|
||||
{ SkType_Style, "fill|stroke|strokeAndFill" },
|
||||
{ SkType_TextBoxAlign, "start|center|end" },
|
||||
{ SkType_TextBoxMode, "oneLine|lineBreak" },
|
||||
{ SkType_TileMode, "clamp|repeat|mirror" },
|
||||
{ SkType_Xfermode, "clear|src|dst|srcOver|dstOver|srcIn|dstIn|srcOut|dstOut|"
|
||||
"srcATop|dstATop|xor|darken|lighten" },
|
||||
};
|
||||
|
||||
static int gEnumMapCount = SK_ARRAY_COUNT(gEnumMaps);
|
||||
|
||||
SkAnimatorScript::SkAnimatorScript(SkAnimateMaker& maker, SkDisplayable* working, SkDisplayTypes type)
|
||||
: SkScriptEngine(SkScriptEngine::ToOpType(type)), fMaker(maker), fParent(NULL), fWorking(working)
|
||||
{
|
||||
memberCallBack(EvalMember, (void*) this);
|
||||
memberFunctionCallBack(EvalMemberFunction, (void*) this);
|
||||
boxCallBack(Box, (void*) this);
|
||||
unboxCallBack(Unbox, (void*) &maker);
|
||||
propertyCallBack(EvalID, (void*) this); // must be first (entries are prepended, will be last), since it never fails
|
||||
propertyCallBack(Infinity, (void*) this);
|
||||
propertyCallBack(NaN, (void*) this);
|
||||
functionCallBack(Eval, (void*) this);
|
||||
functionCallBack(IsFinite, (void*) this);
|
||||
functionCallBack(IsNaN, (void*) this);
|
||||
if (type == SkType_ARGB) {
|
||||
functionCallBack(EvalRGB, (void*) this);
|
||||
propertyCallBack(EvalNamedColor, (void*) &maker.fIDs);
|
||||
}
|
||||
if (SkDisplayType::IsEnum(&maker, type)) {
|
||||
// !!! for SpiderMonkey, iterate through the enum values, and map them to globals
|
||||
const SkDisplayEnumMap& map = GetEnumValues(type);
|
||||
propertyCallBack(EvalEnum, (void*) map.fValues);
|
||||
}
|
||||
for (SkExtras** extraPtr = maker.fExtras.begin(); extraPtr < maker.fExtras.end(); extraPtr++) {
|
||||
SkExtras* extra = *extraPtr;
|
||||
if (extra->fExtraCallBack)
|
||||
propertyCallBack(extra->fExtraCallBack, extra->fExtraStorage);
|
||||
}
|
||||
}
|
||||
|
||||
SkAnimatorScript::~SkAnimatorScript() {
|
||||
for (SkDisplayable** dispPtr = fTrackDisplayable.begin(); dispPtr < fTrackDisplayable.end(); dispPtr++)
|
||||
delete *dispPtr;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::evaluate(const char* original, SkScriptValue* result, SkDisplayTypes type) {
|
||||
const char* script = original;
|
||||
bool success = evaluateScript(&script, result);
|
||||
if (success == false || result->fType != type) {
|
||||
fMaker.setScriptError(*this);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::Box(void* user, SkScriptValue* scriptValue) {
|
||||
SkAnimatorScript* engine = (SkAnimatorScript*) user;
|
||||
SkDisplayTypes type = scriptValue->fType;
|
||||
SkDisplayable* displayable;
|
||||
switch (type) {
|
||||
case SkType_Array: {
|
||||
SkDisplayArray* boxedValue = new SkDisplayArray(*scriptValue->fOperand.fArray);
|
||||
displayable = boxedValue;
|
||||
} break;
|
||||
case SkType_Boolean: {
|
||||
SkDisplayBoolean* boxedValue = new SkDisplayBoolean;
|
||||
displayable = boxedValue;
|
||||
boxedValue->value = !! scriptValue->fOperand.fS32;
|
||||
} break;
|
||||
case SkType_Int: {
|
||||
SkDisplayInt* boxedValue = new SkDisplayInt;
|
||||
displayable = boxedValue;
|
||||
boxedValue->value = scriptValue->fOperand.fS32;
|
||||
} break;
|
||||
case SkType_Float: {
|
||||
SkDisplayFloat* boxedValue = new SkDisplayFloat;
|
||||
displayable = boxedValue;
|
||||
boxedValue->value = scriptValue->fOperand.fScalar;
|
||||
} break;
|
||||
case SkType_String: {
|
||||
SkDisplayString* boxedValue = new SkDisplayString(*scriptValue->fOperand.fString);
|
||||
displayable = boxedValue;
|
||||
} break;
|
||||
case SkType_Displayable:
|
||||
scriptValue->fOperand.fObject = scriptValue->fOperand.fDisplayable;
|
||||
scriptValue->fType = SkType_Displayable;
|
||||
return true;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
engine->track(displayable);
|
||||
scriptValue->fOperand.fObject = displayable;
|
||||
scriptValue->fType = SkType_Displayable;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::Eval(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
|
||||
void* eng, SkScriptValue* value) {
|
||||
if (SK_LITERAL_STR_EQUAL("eval", function, len) == false)
|
||||
return false;
|
||||
if (params.count() != 1)
|
||||
return false;
|
||||
SkAnimatorScript* host = (SkAnimatorScript*) eng;
|
||||
SkAnimatorScript engine(host->fMaker, host->fWorking, SkScriptEngine::ToDisplayType(host->fReturnType));
|
||||
SkScriptValue* scriptValue = params.begin();
|
||||
bool success = true;
|
||||
if (scriptValue->fType == SkType_String) {
|
||||
const char* script = scriptValue->fOperand.fString->c_str();
|
||||
success = engine.evaluateScript(&script, value);
|
||||
} else
|
||||
*value = *scriptValue;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::EvalEnum(const char* token, size_t len, void* callBack, SkScriptValue* value) {
|
||||
const char* tokens = (const char*) callBack;
|
||||
value->fType = SkType_Int;
|
||||
if (MapEnums(tokens, token, len, (int*)&value->fOperand.fS32))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::EvalID(const char* token, size_t len, void* user, SkScriptValue* value) {
|
||||
SkAnimatorScript* engine = (SkAnimatorScript*) user;
|
||||
SkTDict<SkDisplayable*>* ids = &engine->fMaker.fIDs;
|
||||
SkDisplayable* displayable;
|
||||
bool success = ids->find(token, len, &displayable);
|
||||
if (success == false) {
|
||||
displayable = engine->fWorking;
|
||||
if (SK_LITERAL_STR_EQUAL("parent", token, len)) {
|
||||
SkDisplayable* parent = displayable->getParent();
|
||||
if (parent == false)
|
||||
parent = engine->fParent;
|
||||
if (parent) {
|
||||
value->fOperand.fDisplayable = parent;
|
||||
value->fType = SkType_Displayable;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (displayable && EvalMember(token, len, displayable, engine, value))
|
||||
return true;
|
||||
value->fOperand.fString = NULL;
|
||||
value->fType = SkType_String;
|
||||
} else {
|
||||
SkDisplayable* working = engine->fWorking;
|
||||
value->fOperand.fDisplayable = displayable;
|
||||
value->fType = SkType_Displayable;
|
||||
if (displayable->canContainDependents() && working && working->isAnimate()) {
|
||||
SkAnimateBase* animator = (SkAnimateBase*) working;
|
||||
if (animator->isDynamic()) {
|
||||
SkDisplayDepend* depend = (SkDisplayDepend* ) displayable;
|
||||
depend->addDependent(working);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::EvalNamedColor(const char* token, size_t len, void* callback, SkScriptValue* value) {
|
||||
value->fType = SkType_Int;
|
||||
if (SkParse::FindNamedColor(token, len, (SkColor*) &value->fOperand.fS32) != NULL)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::EvalRGB(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
|
||||
void* eng, SkScriptValue* value) {
|
||||
if (SK_LITERAL_STR_EQUAL("rgb", function, len) == false)
|
||||
return false;
|
||||
if (params.count() != 3)
|
||||
return false;
|
||||
SkScriptEngine* engine = (SkScriptEngine*) eng;
|
||||
unsigned result = 0xFF000000;
|
||||
int shift = 16;
|
||||
for (SkScriptValue* valuePtr = params.begin(); valuePtr < params.end(); valuePtr++) {
|
||||
engine->convertTo(SkType_Int, valuePtr);
|
||||
result |= SkClampMax(valuePtr->fOperand.fS32, 255) << shift;
|
||||
shift -= 8;
|
||||
}
|
||||
value->fOperand.fS32 = result;
|
||||
value->fType = SkType_Int;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::EvalMemberCommon(SkScriptEngine* engine, const SkMemberInfo* info,
|
||||
SkDisplayable* displayable, SkScriptValue* value) {
|
||||
SkDisplayTypes original;
|
||||
SkDisplayTypes type = original = (SkDisplayTypes) info->getType();
|
||||
if (info->fType == SkType_Array)
|
||||
type = SkType_Array;
|
||||
switch (type) {
|
||||
case SkType_ARGB:
|
||||
type = SkType_Int;
|
||||
case SkType_Boolean:
|
||||
case SkType_Int:
|
||||
case SkType_MSec:
|
||||
case SkType_Float:
|
||||
SkASSERT(info->getCount() == 1);
|
||||
if (info->fType != SkType_MemberProperty && info->fType != SkType_MemberFunction)
|
||||
value->fOperand.fS32 = *(int32_t*) info->memberData(displayable); // OK for SkScalar too
|
||||
if (type == SkType_MSec) {
|
||||
value->fOperand.fScalar = SkScalarDiv((SkScalar) value->fOperand.fS32, 1000); // dividing two ints is the same as dividing two scalars
|
||||
type = SkType_Float;
|
||||
}
|
||||
break;
|
||||
case SkType_String: {
|
||||
SkString* displayableString;
|
||||
if (info->fType != SkType_MemberProperty && info->fType != SkType_MemberFunction) {
|
||||
info->getString(displayable, &displayableString);
|
||||
value->fOperand.fString = new SkString(*displayableString);
|
||||
}
|
||||
} break;
|
||||
case SkType_Array: {
|
||||
SkASSERT(info->fType != SkType_MemberProperty); // !!! incomplete
|
||||
SkTDOperandArray* displayableArray = (SkTDOperandArray*) info->memberData(displayable);
|
||||
if (displayable->getType() == SkType_Array) {
|
||||
SkDisplayArray* typedArray = (SkDisplayArray*) displayable;
|
||||
original = typedArray->values.getType();
|
||||
}
|
||||
SkASSERT(original != SkType_Unknown);
|
||||
SkTypedArray* array = value->fOperand.fArray = new SkTypedArray(original);
|
||||
engine->track(array);
|
||||
int count = displayableArray->count();
|
||||
if (count > 0) {
|
||||
array->setCount(count);
|
||||
memcpy(array->begin(), displayableArray->begin(), count * sizeof(SkOperand));
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
SkASSERT(0); // unimplemented
|
||||
}
|
||||
value->fType = type;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::EvalMember(const char* member, size_t len, void* object, void* eng,
|
||||
SkScriptValue* value) {
|
||||
SkScriptEngine* engine = (SkScriptEngine*) eng;
|
||||
SkDisplayable* displayable = (SkDisplayable*) object;
|
||||
SkString name(member, len);
|
||||
SkDisplayable* named = displayable->contains(name);
|
||||
if (named) {
|
||||
value->fOperand.fDisplayable = named;
|
||||
value->fType = SkType_Displayable;
|
||||
return true;
|
||||
}
|
||||
const SkMemberInfo* info = displayable->getMember(name.c_str());
|
||||
if (info == NULL)
|
||||
return false;
|
||||
if (info->fType == SkType_MemberProperty) {
|
||||
if (displayable->getProperty(info->propertyIndex(), value) == false) {
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return EvalMemberCommon(engine, info, displayable, value);
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::EvalMemberFunction(const char* member, size_t len, void* object,
|
||||
SkTDArray<SkScriptValue>& params, void* eng, SkScriptValue* value) {
|
||||
SkScriptEngine* engine = (SkScriptEngine*) eng;
|
||||
SkDisplayable* displayable = (SkDisplayable*) object;
|
||||
SkString name(member, len);
|
||||
const SkMemberInfo* info = displayable->getMember(name.c_str());
|
||||
SkASSERT(info != NULL); /* !!! error handling unimplemented */
|
||||
if (info->fType != SkType_MemberFunction) {
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
displayable->executeFunction(displayable, info->functionIndex(), params, info->getType(),
|
||||
value);
|
||||
return EvalMemberCommon(engine, info, displayable, value);
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::EvaluateDisplayable(SkAnimateMaker& maker, SkDisplayable* displayable, const char* script, SkDisplayable** result) {
|
||||
SkAnimatorScript engine(maker, displayable, SkType_Displayable);
|
||||
SkScriptValue value;
|
||||
bool success = engine.evaluate(script, &value, SkType_Displayable);
|
||||
if (success)
|
||||
*result = value.fOperand.fDisplayable;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::EvaluateInt(SkAnimateMaker& maker, SkDisplayable* displayable, const char* script, int32_t* result) {
|
||||
SkAnimatorScript engine(maker, displayable, SkType_Int);
|
||||
SkScriptValue value;
|
||||
bool success = engine.evaluate(script, &value, SkType_Int);
|
||||
if (success)
|
||||
*result = value.fOperand.fS32;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::EvaluateFloat(SkAnimateMaker& maker, SkDisplayable* displayable, const char* script, SkScalar* result) {
|
||||
SkAnimatorScript engine(maker, displayable, SkType_Float);
|
||||
SkScriptValue value;
|
||||
bool success = engine.evaluate(script, &value, SkType_Float);
|
||||
if (success)
|
||||
*result = value.fOperand.fScalar;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::EvaluateString(SkAnimateMaker& maker, SkDisplayable* displayable, const char* script, SkString* result) {
|
||||
SkAnimatorScript engine(maker, displayable, SkType_String);
|
||||
SkScriptValue value;
|
||||
bool success = engine.evaluate(script, &value, SkType_String);
|
||||
if (success)
|
||||
result->set(*(value.fOperand.fString));
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::EvaluateString(SkAnimateMaker& maker, SkDisplayable* displayable, SkDisplayable* parent, const char* script, SkString* result) {
|
||||
SkAnimatorScript engine(maker, displayable, SkType_String);
|
||||
engine.fParent = parent;
|
||||
SkScriptValue value;
|
||||
bool success = engine.evaluate(script, &value, SkType_String);
|
||||
if (success)
|
||||
result->set(*(value.fOperand.fString));
|
||||
return success;
|
||||
}
|
||||
|
||||
const SkDisplayEnumMap& SkAnimatorScript::GetEnumValues(SkDisplayTypes type) {
|
||||
int index = SkTSearch<SkDisplayTypes>(&gEnumMaps[0].fType, gEnumMapCount, type,
|
||||
sizeof(SkDisplayEnumMap));
|
||||
SkASSERT(index >= 0);
|
||||
return gEnumMaps[index];
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::Infinity(const char* token, size_t len, void* user, SkScriptValue* value) {
|
||||
if (SK_LITERAL_STR_EQUAL("Infinity", token, len) == false)
|
||||
return false;
|
||||
value->fType = SkType_Float;
|
||||
value->fOperand.fScalar = SK_ScalarInfinity;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::IsFinite(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
|
||||
void* eng, SkScriptValue* value) {
|
||||
if (SK_LITERAL_STR_EQUAL(function, "isFinite", len) == false)
|
||||
return false;
|
||||
if (params.count() != 1)
|
||||
return false;
|
||||
SkScriptValue* scriptValue = params.begin();
|
||||
SkDisplayTypes type = scriptValue->fType;
|
||||
SkScalar scalar = scriptValue->fOperand.fScalar;
|
||||
value->fType = SkType_Int;
|
||||
value->fOperand.fS32 = type == SkType_Float ? SkScalarIsNaN(scalar) == false &&
|
||||
SkScalarAbs(scalar) != SK_ScalarInfinity : type == SkType_Int;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::IsNaN(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
|
||||
void* eng, SkScriptValue* value) {
|
||||
if (SK_LITERAL_STR_EQUAL("isNaN", function, len) == false)
|
||||
return false;
|
||||
if (params.count() != 1)
|
||||
return false;
|
||||
SkScriptValue* scriptValue = params.begin();
|
||||
value->fType = SkType_Int;
|
||||
value->fOperand.fS32 = scriptValue->fType == SkType_Float ? SkScalarIsNaN(scriptValue->fOperand.fScalar) : 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::MapEnums(const char* ptr, const char* match, size_t len, int* value) {
|
||||
int index = 0;
|
||||
bool more = true;
|
||||
do {
|
||||
const char* last = strchr(ptr, '|');
|
||||
if (last == NULL) {
|
||||
last = &ptr[strlen(ptr)];
|
||||
more = false;
|
||||
}
|
||||
size_t length = last - ptr;
|
||||
if (len == length && strncmp(ptr, match, length) == 0) {
|
||||
*value = index;
|
||||
return true;
|
||||
}
|
||||
index++;
|
||||
ptr = last + 1;
|
||||
} while (more);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript::NaN(const char* token, size_t len, void* user, SkScriptValue* value) {
|
||||
if (SK_LITERAL_STR_EQUAL("NaN", token, len) == false)
|
||||
return false;
|
||||
value->fType = SkType_Float;
|
||||
value->fOperand.fScalar = SK_ScalarNaN;
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool SkAnimatorScript::ObjectToString(void* object, void* user, SkScriptValue* value) {
|
||||
SkTDict<SkDisplayable*>* ids = (SkTDict<SkDisplayable*>*) user;
|
||||
SkDisplayable* displayable = (SkDisplayable*) object;
|
||||
const char* key;
|
||||
bool success = ids->findKey(displayable, &key);
|
||||
if (success == false)
|
||||
return false;
|
||||
value->fOperand.fString = new SkString(key);
|
||||
value->fType = SkType_String;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkAnimatorScript::Unbox(void* m, SkScriptValue* scriptValue) {
|
||||
SkAnimateMaker* maker = (SkAnimateMaker*) m;
|
||||
SkASSERT((unsigned) scriptValue->fType == (unsigned) SkType_Displayable);
|
||||
SkDisplayable* displayable = (SkDisplayable*) scriptValue->fOperand.fObject;
|
||||
SkDisplayTypes type = displayable->getType();
|
||||
switch (displayable->getType()) {
|
||||
case SkType_Array: {
|
||||
SkDisplayArray* boxedValue = (SkDisplayArray*) displayable;
|
||||
scriptValue->fOperand.fArray = &boxedValue->values;
|
||||
} break;
|
||||
case SkType_Boolean: {
|
||||
SkDisplayBoolean* boxedValue = (SkDisplayBoolean*) displayable;
|
||||
scriptValue->fOperand.fS32 = boxedValue->value;
|
||||
} break;
|
||||
case SkType_Int: {
|
||||
SkDisplayInt* boxedValue = (SkDisplayInt*) displayable;
|
||||
scriptValue->fOperand.fS32 = boxedValue->value;
|
||||
} break;
|
||||
case SkType_Float: {
|
||||
SkDisplayFloat* boxedValue = (SkDisplayFloat*) displayable;
|
||||
scriptValue->fOperand.fScalar = boxedValue->value;
|
||||
} break;
|
||||
case SkType_String: {
|
||||
SkDisplayString* boxedValue = (SkDisplayString*) displayable;
|
||||
scriptValue->fOperand.fString = SkNEW_ARGS(SkString, (boxedValue->value));
|
||||
} break;
|
||||
default: {
|
||||
const char* id;
|
||||
bool success = maker->findKey(displayable, &id);
|
||||
SkASSERT(success);
|
||||
scriptValue->fOperand.fString = SkNEW_ARGS(SkString, (id));
|
||||
type = SkType_String;
|
||||
}
|
||||
}
|
||||
scriptValue->fType = type;
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined SK_SUPPORT_UNITTEST
|
||||
|
||||
#include "SkAnimator.h"
|
||||
|
||||
static const char scriptTestSetup[] =
|
||||
"<screenplay>\n"
|
||||
"<text id='label' text='defg'/>\n"
|
||||
"<add id='addLabel' use='label'/>\n"
|
||||
"<text id='text1' text='test'/>\n"
|
||||
"<apply scope='addLabel'>\n"
|
||||
"<set target='label' field='text' to='#script:text1.text'/>\n"
|
||||
"</apply>\n"
|
||||
"<apply>\n"
|
||||
"<paint id='labelPaint'>\n"
|
||||
"<emboss id='emboss' direction='[1,1,1]' />\n"
|
||||
"</paint>\n"
|
||||
"<animate id='animation' field='direction' target='emboss' from='[1,1,1]' to='[-1,1,1]' dur='1'/>\n"
|
||||
"<set lval='direction[0]' target='emboss' to='-1' />\n"
|
||||
"</apply>\n"
|
||||
"<color id='testColor' color='0 ? rgb(0,0,0) : rgb(255,255,255)' />\n"
|
||||
"<color id='xColor' color='rgb(12,34,56)' />\n"
|
||||
"<array id='emptyArray' />\n"
|
||||
"<array id='intArray' values='[1, 4, 6]' />\n"
|
||||
"<int id='idx' value='2' />\n"
|
||||
"<int id='idy' value='2' />\n"
|
||||
"<string id='alpha' value='abc' />\n"
|
||||
"<rect id='testRect' left='Math.cos(0)' top='2' right='12' bottom='5' />\n"
|
||||
"<event id='evt'>\n"
|
||||
"<input name='x' />\n"
|
||||
"<apply scope='idy'>\n"
|
||||
"<set field='value' to='evt.x.int' />\n"
|
||||
"</apply>\n"
|
||||
"</event>\n"
|
||||
"</screenplay>";
|
||||
|
||||
#if !defined(SK_BUILD_FOR_BREW)
|
||||
|
||||
#define DEFAULT_ANSWER , 0
|
||||
|
||||
static const SkScriptNAnswer scriptTests[] = {
|
||||
{ "label.text.length == 4", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
// { "labelPaint.measureText(label.text) > 0 ? labelPaint.measureText(label.text)+10 : 40", SkType_Float, 0, SkIntToScalar(0x23) },
|
||||
{ "Number.POSITIVE_INFINITY >= Number.MAX_VALUE ? 1 : 0", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "Infinity >= Number.MAX_VALUE ? 1 : 0", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "Number.NEGATIVE_INFINITY <= -Number.MAX_VALUE ? 1 : 0", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "Number.MIN_VALUE > 0 ? 1 : 0", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "isNaN(Number.NaN)", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "isNaN(NaN)", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "Math.sin(0)", SkType_Float, 0, SkIntToScalar(0) DEFAULT_ANSWER },
|
||||
{ "alpha+alpha", SkType_String, 0, 0, "abcabc" },
|
||||
{ "intArray[4]", SkType_Unknown DEFAULT_ANSWER DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "emptyArray[4]", SkType_Unknown DEFAULT_ANSWER DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "idx", SkType_Int, 2 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "intArray.length", SkType_Int, 3 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "intArray.values[0]", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "intArray[0]", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "idx.value", SkType_Int, 2 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "alpha.value", SkType_String, 0, 0, "abc" },
|
||||
{ "alpha", SkType_String, 0, 0, "abc" },
|
||||
{ "alpha.value+alpha.value", SkType_String, 0, 0, "abcabc" },
|
||||
{ "alpha+idx", SkType_String, 0, 0, "abc2" },
|
||||
{ "idx+alpha", SkType_String, 0, 0, "2abc" },
|
||||
{ "intArray[idx]", SkType_Int, 6 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "alpha.slice(1,2)", SkType_String, 0, 0, "b" },
|
||||
{ "alpha.value.slice(1,2)", SkType_String, 0, 0, "b" },
|
||||
{ "testRect.left+2", SkType_Float, 0, SkIntToScalar(3) DEFAULT_ANSWER },
|
||||
{ "0 ? Math.sin(0) : 1", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "0 ? intArray[0] : 1", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "0 ? intArray.values[0] : 1", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "0 ? idx : 1", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "0 ? idx.value : 1", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "0 ? alpha.slice(1,2) : 1", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "0 ? alpha.value.slice(1,2) : 1", SkType_Int, 1 DEFAULT_ANSWER DEFAULT_ANSWER },
|
||||
{ "idy", SkType_Int, 3 DEFAULT_ANSWER DEFAULT_ANSWER }
|
||||
};
|
||||
#endif
|
||||
|
||||
#define SkScriptNAnswer_testCount SK_ARRAY_COUNT(scriptTests)
|
||||
|
||||
void SkAnimatorScript::UnitTest() {
|
||||
#if !defined(SK_BUILD_FOR_BREW) && defined(SK_SUPPORT_UNITTEST)
|
||||
SkAnimator animator;
|
||||
SkASSERT(animator.decodeMemory(scriptTestSetup, sizeof(scriptTestSetup)-1));
|
||||
SkEvent evt;
|
||||
evt.setString("id", "evt");
|
||||
evt.setS32("x", 3);
|
||||
animator.doUserEvent(evt);
|
||||
// set up animator with memory script above, then run value tests
|
||||
for (unsigned index = 0; index < SkScriptNAnswer_testCount; index++) {
|
||||
SkAnimatorScript engine(*animator.fMaker, NULL, scriptTests[index].fType);
|
||||
SkScriptValue value;
|
||||
const char* script = scriptTests[index].fScript;
|
||||
bool success = engine.evaluateScript(&script, &value);
|
||||
if (success == false) {
|
||||
SkDebugf("script failed: %s\n", scriptTests[index].fScript);
|
||||
SkASSERT(scriptTests[index].fType == SkType_Unknown);
|
||||
continue;
|
||||
}
|
||||
SkASSERT(value.fType == scriptTests[index].fType);
|
||||
SkScalar error;
|
||||
switch (value.fType) {
|
||||
case SkType_Int:
|
||||
SkASSERT(value.fOperand.fS32 == scriptTests[index].fIntAnswer);
|
||||
break;
|
||||
case SkType_Float:
|
||||
error = SkScalarAbs(value.fOperand.fScalar - scriptTests[index].fScalarAnswer);
|
||||
SkASSERT(error < SK_Scalar1 / 10000);
|
||||
break;
|
||||
case SkType_String:
|
||||
SkASSERT(strcmp(value.fOperand.fString->c_str(), scriptTests[index].fStringAnswer) == 0);
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/* libs/graphics/animator/SkAnimatorScript.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkAnimatorScript_DEFINED
|
||||
#define SkAnimatorScript_DEFINED
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkScript.h"
|
||||
#include "SkTypedArray.h"
|
||||
|
||||
class SkAnimateMaker;
|
||||
struct SkMemberInfo;
|
||||
|
||||
struct SkDisplayEnumMap {
|
||||
SkDisplayTypes fType;
|
||||
const char* fValues;
|
||||
};
|
||||
|
||||
class SkAnimatorScript : public SkScriptEngine {
|
||||
public:
|
||||
SkAnimatorScript(SkAnimateMaker& , SkDisplayable* , SkDisplayTypes type);
|
||||
~SkAnimatorScript();
|
||||
bool evaluate(const char* script, SkScriptValue* , SkDisplayTypes type);
|
||||
void track(SkDisplayable* displayable) {
|
||||
SkASSERT(fTrackDisplayable.find(displayable) < 0);
|
||||
*fTrackDisplayable.append() = displayable; }
|
||||
static bool EvaluateDisplayable(SkAnimateMaker& , SkDisplayable* , const char* script, SkDisplayable** );
|
||||
static bool EvaluateFloat(SkAnimateMaker& , SkDisplayable* , const char* script, SkScalar* );
|
||||
static bool EvaluateInt(SkAnimateMaker& , SkDisplayable* , const char* script, int32_t* );
|
||||
static bool EvaluateString(SkAnimateMaker& , SkDisplayable* , const char* script, SkString* );
|
||||
static bool EvaluateString(SkAnimateMaker& , SkDisplayable* , SkDisplayable* parent, const char* script, SkString* );
|
||||
static bool MapEnums(const char* ptr, const char* match, size_t len, int* value);
|
||||
protected:
|
||||
static bool Box(void* user, SkScriptValue* );
|
||||
static bool Eval(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
|
||||
void* callBack, SkScriptValue* );
|
||||
static bool EvalEnum(const char* token, size_t len, void* callBack, SkScriptValue* );
|
||||
static bool EvalID(const char* token, size_t len, void* callBack, SkScriptValue* );
|
||||
static bool EvalMember(const char* member, size_t len, void* object, void* eng,
|
||||
SkScriptValue* value);
|
||||
static bool EvalMemberCommon(SkScriptEngine* , const SkMemberInfo* info,
|
||||
SkDisplayable* displayable, SkScriptValue* value);
|
||||
static bool EvalMemberFunction(const char* member, size_t len, void* object,
|
||||
SkTDArray<SkScriptValue>& params, void* user, SkScriptValue* value);
|
||||
static bool EvalNamedColor(const char* token, size_t len, void* callBack, SkScriptValue* );
|
||||
static bool EvalRGB(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
|
||||
void* callBack, SkScriptValue* );
|
||||
static const SkDisplayEnumMap& GetEnumValues(SkDisplayTypes type);
|
||||
static bool Infinity(const char* token, size_t len, void* callBack, SkScriptValue* );
|
||||
static bool IsFinite(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
|
||||
void* callBack, SkScriptValue* );
|
||||
static bool IsNaN(const char* function, size_t len, SkTDArray<SkScriptValue>& params,
|
||||
void* callBack, SkScriptValue* );
|
||||
static bool NaN(const char* token, size_t len, void* callBack, SkScriptValue* );
|
||||
static bool Unbox(void* , SkScriptValue* scriptValue);
|
||||
SkTDDisplayableArray fTrackDisplayable;
|
||||
SkAnimateMaker& fMaker;
|
||||
SkDisplayable* fParent;
|
||||
SkDisplayable* fWorking;
|
||||
private:
|
||||
friend class SkDump;
|
||||
friend struct SkScriptNAnswer;
|
||||
#ifdef SK_SUPPORT_UNITTEST
|
||||
public:
|
||||
static void UnitTest();
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // SkAnimatorScript_DEFINED
|
||||
|
||||
@@ -0,0 +1,618 @@
|
||||
#include "SkAnimatorScript2.h"
|
||||
#include "SkAnimateBase.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkDisplayTypes.h"
|
||||
#include "SkExtras.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkOpArray.h"
|
||||
#include "SkParse.h"
|
||||
#include "SkScript2.h"
|
||||
#include "SkScriptCallBack.h"
|
||||
|
||||
static const SkDisplayEnumMap gEnumMaps[] = {
|
||||
{ SkType_AddMode, "indirect|immediate" },
|
||||
{ SkType_Align, "left|center|right" },
|
||||
{ SkType_ApplyMode, "immediate|once" },
|
||||
{ SkType_ApplyTransition, "reverse" },
|
||||
{ SkType_BitmapEncoding, "jpeg|png" },
|
||||
{ SkType_BitmapFormat, "none|A1|A8|Index8|RGB16|RGB32" },
|
||||
{ SkType_Boolean, "false|true" },
|
||||
{ SkType_Cap, "butt|round|square" },
|
||||
{ SkType_EventCode, "none|up|down|left|right|back|end|OK|send|leftSoftKey|rightSoftKey|key0|key1|key2|key3|key4|key5|key6|key7|key8|key9|star|hash" },
|
||||
{ SkType_EventKind, "none|keyChar|keyPress|mouseDown|mouseDrag|mouseMove|mouseUp|onEnd|onLoad|user" },
|
||||
{ SkType_EventMode, "deferred|immediate" },
|
||||
{ SkType_FillType, "winding|evenOdd" },
|
||||
{ SkType_FilterType, "none|bilinear" },
|
||||
{ SkType_FromPathMode, "normal|angle|position" },
|
||||
{ SkType_Join, "miter|round|blunt" },
|
||||
{ SkType_MaskFilterBlurStyle, "normal|solid|outer|inner" },
|
||||
{ SkType_PathDirection, "cw|ccw" },
|
||||
{ SkType_Style, "fill|stroke|strokeAndFill" },
|
||||
{ SkType_TextBoxAlign, "start|center|end" },
|
||||
{ SkType_TextBoxMode, "oneLine|lineBreak" },
|
||||
{ SkType_TileMode, "clamp|repeat|mirror" },
|
||||
{ SkType_Xfermode, "clear|src|dst|srcOver|dstOver|srcIn|dstIn|srcOut|dstOut|"
|
||||
"srcATop|dstATop|xor|darken|lighten" },
|
||||
};
|
||||
|
||||
static int gEnumMapCount = SK_ARRAY_COUNT(gEnumMaps);
|
||||
|
||||
|
||||
class SkAnimatorScript_Box : public SkScriptCallBackConvert {
|
||||
public:
|
||||
SkAnimatorScript_Box() {}
|
||||
|
||||
~SkAnimatorScript_Box() {
|
||||
for (SkDisplayable** dispPtr = fTrackDisplayable.begin(); dispPtr < fTrackDisplayable.end(); dispPtr++)
|
||||
delete *dispPtr;
|
||||
}
|
||||
|
||||
virtual bool convert(SkOperand2::OpType type, SkOperand2* operand) {
|
||||
SkDisplayable* displayable;
|
||||
switch (type) {
|
||||
case SkOperand2::kArray: {
|
||||
SkDisplayArray* boxedValue = new SkDisplayArray(*operand->fArray);
|
||||
displayable = boxedValue;
|
||||
} break;
|
||||
case SkOperand2::kS32: {
|
||||
SkDisplayInt* boxedValue = new SkDisplayInt;
|
||||
displayable = boxedValue;
|
||||
boxedValue->value = operand->fS32;
|
||||
} break;
|
||||
case SkOperand2::kScalar: {
|
||||
SkDisplayFloat* boxedValue = new SkDisplayFloat;
|
||||
displayable = boxedValue;
|
||||
boxedValue->value = operand->fScalar;
|
||||
} break;
|
||||
case SkOperand2::kString: {
|
||||
SkDisplayString* boxedValue = new SkDisplayString(*operand->fString);
|
||||
displayable = boxedValue;
|
||||
} break;
|
||||
case SkOperand2::kObject:
|
||||
return true;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
track(displayable);
|
||||
operand->fObject = (void*) displayable;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual SkOperand2::OpType getReturnType(int index) {
|
||||
return SkOperand2::kObject;
|
||||
}
|
||||
|
||||
virtual Type getType() const {
|
||||
return kBox;
|
||||
}
|
||||
|
||||
void track(SkDisplayable* displayable) {
|
||||
SkASSERT(fTrackDisplayable.find(displayable) < 0);
|
||||
*fTrackDisplayable.append() = displayable;
|
||||
}
|
||||
|
||||
SkTDDisplayableArray fTrackDisplayable;
|
||||
};
|
||||
|
||||
|
||||
class SkAnimatorScript_Enum : public SkScriptCallBackProperty {
|
||||
public:
|
||||
SkAnimatorScript_Enum(const char* tokens) : fTokens(tokens) {}
|
||||
|
||||
virtual bool getConstValue(const char* name, int len, SkOperand2* value) {
|
||||
return SkAnimatorScript2::MapEnums(fTokens, name, len, &value->fS32);
|
||||
}
|
||||
|
||||
private:
|
||||
const char* fTokens;
|
||||
};
|
||||
|
||||
// !!! if type is string, call invoke
|
||||
// if any other type, return original value
|
||||
// distinction is undone: could do this by returning index == 0 only if param is string
|
||||
// still, caller of getParamTypes will attempt to convert param to string (I guess)
|
||||
class SkAnimatorScript_Eval : public SkScriptCallBackFunction {
|
||||
public:
|
||||
SkAnimatorScript_Eval(SkAnimatorScript2* engine) : fEngine(engine) {}
|
||||
|
||||
virtual bool getIndex(const char* name, int len, size_t* result) {
|
||||
if (SK_LITERAL_STR_EQUAL("eval", name, len) != 0)
|
||||
return false;
|
||||
*result = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void getParamTypes(SkIntArray(SkOperand2::OpType)* types) {
|
||||
types->setCount(1);
|
||||
SkOperand2::OpType* type = types->begin();
|
||||
type[0] = SkOperand2::kString;
|
||||
}
|
||||
|
||||
virtual bool invoke(size_t index, SkOpArray* params, SkOperand2* answer) {
|
||||
SkAnimatorScript2 engine(fEngine->getMaker(), fEngine->getWorking(),
|
||||
SkAnimatorScript2::ToDisplayType(fEngine->getReturnType()));
|
||||
SkOperand2* op = params->begin();
|
||||
const char* script = op->fString->c_str();
|
||||
SkScriptValue2 value;
|
||||
return engine.evaluateScript(&script, &value);
|
||||
SkASSERT(value.fType == fEngine->getReturnType());
|
||||
*answer = value.fOperand;
|
||||
// !!! incomplete ?
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
SkAnimatorScript2* fEngine;
|
||||
};
|
||||
|
||||
class SkAnimatorScript_ID : public SkScriptCallBackProperty {
|
||||
public:
|
||||
SkAnimatorScript_ID(SkAnimatorScript2* engine) : fEngine(engine) {}
|
||||
|
||||
virtual bool getIndex(const char* token, int len, size_t* result) {
|
||||
SkDisplayable* displayable;
|
||||
bool success = fEngine->getMaker().find(token, len, &displayable);
|
||||
if (success == false) {
|
||||
*result = 0;
|
||||
} else {
|
||||
*result = (size_t) displayable;
|
||||
SkDisplayable* working = fEngine->getWorking();
|
||||
if (displayable->canContainDependents() && working && working->isAnimate()) {
|
||||
SkAnimateBase* animator = (SkAnimateBase*) working;
|
||||
if (animator->isDynamic()) {
|
||||
SkDisplayDepend* depend = (SkDisplayDepend* ) displayable;
|
||||
depend->addDependent(working);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool getResult(size_t ref, SkOperand2* answer) {
|
||||
answer->fObject = (void*) ref;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual SkOperand2::OpType getReturnType(size_t index) {
|
||||
return index == 0 ? SkOperand2::kString : SkOperand2::kObject;
|
||||
}
|
||||
|
||||
private:
|
||||
SkAnimatorScript2* fEngine;
|
||||
};
|
||||
|
||||
|
||||
class SkAnimatorScript_Member : public SkScriptCallBackMember {
|
||||
public:
|
||||
|
||||
SkAnimatorScript_Member(SkAnimatorScript2* engine) : fEngine(engine) {}
|
||||
|
||||
bool getMemberReference(const char* member, size_t len, void* object, SkScriptValue2* ref) {
|
||||
SkDisplayable* displayable = (SkDisplayable*) object;
|
||||
SkString name(member, len);
|
||||
SkDisplayable* named = displayable->contains(name);
|
||||
if (named) {
|
||||
ref->fType = SkOperand2::kObject;
|
||||
ref->fOperand.fObject = named;
|
||||
return true;
|
||||
}
|
||||
const SkMemberInfo* info = displayable->getMember(name.c_str());
|
||||
if (info == NULL)
|
||||
return false; // !!! add additional error info?
|
||||
ref->fType = SkAnimatorScript2::ToOpType(info->getType());
|
||||
ref->fOperand.fObject = (void*) info;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool invoke(size_t ref, void* object, SkOperand2* value) {
|
||||
const SkMemberInfo* info = (const SkMemberInfo* ) ref;
|
||||
SkDisplayable* displayable = (SkDisplayable*) object;
|
||||
if (info->fType == SkType_MemberProperty) {
|
||||
if (displayable->getProperty2(info->propertyIndex(), value) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return fEngine->evalMemberCommon(info, displayable, value);
|
||||
}
|
||||
|
||||
SkAnimatorScript2* fEngine;
|
||||
};
|
||||
|
||||
|
||||
class SkAnimatorScript_MemberFunction : public SkScriptCallBackMemberFunction {
|
||||
public:
|
||||
SkAnimatorScript_MemberFunction(SkAnimatorScript2* engine) : fEngine(engine) {}
|
||||
|
||||
bool getMemberReference(const char* member, size_t len, void* object, SkScriptValue2* ref) {
|
||||
SkDisplayable* displayable = (SkDisplayable*) object;
|
||||
SkString name(member, len);
|
||||
const SkMemberInfo* info = displayable->getMember(name.c_str());
|
||||
if (info == NULL || info->fType != SkType_MemberFunction)
|
||||
return false; // !!! add additional error info?
|
||||
ref->fType = SkAnimatorScript2::ToOpType(info->getType());
|
||||
ref->fOperand.fObject = (void*) info;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void getParamTypes(SkIntArray(SkOperand2::OpType)* types) {
|
||||
types->setCount(3);
|
||||
SkOperand2::OpType* type = types->begin();
|
||||
type[0] = type[1] = type[2] = SkOperand2::kS32;
|
||||
}
|
||||
|
||||
bool invoke(size_t ref, void* object, SkOpArray* params, SkOperand2* value)
|
||||
{
|
||||
const SkMemberInfo* info = (const SkMemberInfo* ) ref;
|
||||
SkDisplayable* displayable = (SkDisplayable*) object;
|
||||
displayable->executeFunction2(displayable, info->functionIndex(), params, info->getType(),
|
||||
value);
|
||||
return fEngine->evalMemberCommon(info, displayable, value);
|
||||
}
|
||||
|
||||
SkAnimatorScript2* fEngine;
|
||||
};
|
||||
|
||||
|
||||
class SkAnimatorScript_NamedColor : public SkScriptCallBackProperty {
|
||||
public:
|
||||
virtual bool getConstValue(const char* name, int len, SkOperand2* value) {
|
||||
return SkParse::FindNamedColor(name, len, (SkColor*) &value->fS32) != NULL;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class SkAnimatorScript_RGB : public SkScriptCallBackFunction {
|
||||
public:
|
||||
virtual bool getIndex(const char* name, int len, size_t* result) {
|
||||
if (SK_LITERAL_STR_EQUAL("rgb", name, len) != 0)
|
||||
return false;
|
||||
*result = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void getParamTypes(SkIntArray(SkOperand2::OpType)* types) {
|
||||
types->setCount(3);
|
||||
SkOperand2::OpType* type = types->begin();
|
||||
type[0] = type[1] = type[2] = SkOperand2::kS32;
|
||||
}
|
||||
|
||||
virtual bool invoke(size_t index, SkOpArray* params, SkOperand2* answer) {
|
||||
SkASSERT(index == 0);
|
||||
unsigned result = 0xFF000000;
|
||||
int shift = 16;
|
||||
for (int index = 0; index < 3; index++) {
|
||||
result |= SkClampMax(params->begin()[index].fS32, 255) << shift;
|
||||
shift -= 8;
|
||||
}
|
||||
answer->fS32 = result;
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class SkAnimatorScript_Unbox : public SkScriptCallBackConvert {
|
||||
public:
|
||||
SkAnimatorScript_Unbox(SkAnimatorScript2* engine) : fEngine(engine) {}
|
||||
|
||||
virtual bool convert(SkOperand2::OpType type, SkOperand2* operand) {
|
||||
SkASSERT(type == SkOperand2::kObject);
|
||||
SkDisplayable* displayable = (SkDisplayable*) operand->fObject;
|
||||
switch (displayable->getType()) {
|
||||
case SkType_Array: {
|
||||
SkDisplayArray* boxedValue = (SkDisplayArray*) displayable;
|
||||
operand->fArray = new SkOpArray(SkAnimatorScript2::ToOpType(boxedValue->values.getType()));
|
||||
int count = boxedValue->values.count();
|
||||
operand->fArray->setCount(count);
|
||||
memcpy(operand->fArray->begin(), boxedValue->values.begin(), count * sizeof(SkOperand2));
|
||||
fEngine->track(operand->fArray);
|
||||
} break;
|
||||
case SkType_Boolean: {
|
||||
SkDisplayBoolean* boxedValue = (SkDisplayBoolean*) displayable;
|
||||
operand->fS32 = boxedValue->value;
|
||||
} break;
|
||||
case SkType_Int: {
|
||||
SkDisplayInt* boxedValue = (SkDisplayInt*) displayable;
|
||||
operand->fS32 = boxedValue->value;
|
||||
} break;
|
||||
case SkType_Float: {
|
||||
SkDisplayFloat* boxedValue = (SkDisplayFloat*) displayable;
|
||||
operand->fScalar = boxedValue->value;
|
||||
} break;
|
||||
case SkType_String: {
|
||||
SkDisplayString* boxedValue = (SkDisplayString*) displayable;
|
||||
operand->fString = SkNEW_ARGS(SkString, (boxedValue->value));
|
||||
} break;
|
||||
default: {
|
||||
const char* id;
|
||||
bool success = fEngine->getMaker().findKey(displayable, &id);
|
||||
SkASSERT(success);
|
||||
operand->fString = SkNEW_ARGS(SkString, (id));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual SkOperand2::OpType getReturnType(int /*index*/, SkOperand2* operand) {
|
||||
SkDisplayable* displayable = (SkDisplayable*) operand->fObject;
|
||||
switch (displayable->getType()) {
|
||||
case SkType_Array:
|
||||
return SkOperand2::kArray;
|
||||
case SkType_Int:
|
||||
return SkOperand2::kS32;
|
||||
case SkType_Float:
|
||||
return SkOperand2::kScalar;
|
||||
case SkType_String:
|
||||
default:
|
||||
return SkOperand2::kString;
|
||||
}
|
||||
}
|
||||
|
||||
virtual Type getType() const {
|
||||
return kUnbox;
|
||||
}
|
||||
|
||||
SkAnimatorScript2* fEngine;
|
||||
};
|
||||
|
||||
SkAnimatorScript2::SkAnimatorScript2(SkAnimateMaker& maker, SkDisplayable* working, SkDisplayTypes type) :
|
||||
SkScriptEngine2(ToOpType(type)), fMaker(maker), fWorking(working) {
|
||||
*fCallBackArray.append() = new SkAnimatorScript_Member(this);
|
||||
*fCallBackArray.append() = new SkAnimatorScript_MemberFunction(this);
|
||||
*fCallBackArray.append() = new SkAnimatorScript_Box();
|
||||
*fCallBackArray.append() = new SkAnimatorScript_Unbox(this);
|
||||
*fCallBackArray.append() = new SkAnimatorScript_ID(this);
|
||||
if (type == SkType_ARGB) {
|
||||
*fCallBackArray.append() = new SkAnimatorScript_RGB();
|
||||
*fCallBackArray.append() = new SkAnimatorScript_NamedColor();
|
||||
}
|
||||
if (SkDisplayType::IsEnum(&maker, type)) {
|
||||
// !!! for SpiderMonkey, iterate through the enum values, and map them to globals
|
||||
const SkDisplayEnumMap& map = GetEnumValues(type);
|
||||
*fCallBackArray.append() = new SkAnimatorScript_Enum(map.fValues);
|
||||
}
|
||||
*fCallBackArray.append() = new SkAnimatorScript_Eval(this);
|
||||
#if 0 // !!! no extra support for now
|
||||
for (SkExtras** extraPtr = maker.fExtras.begin(); extraPtr < maker.fExtras.end(); extraPtr++) {
|
||||
SkExtras* extra = *extraPtr;
|
||||
if (extra->fExtraCallBack)
|
||||
*fCallBackArray.append() = new propertyCallBack(extra->fExtraCallBack, extra->fExtraStorage);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
SkAnimatorScript2::~SkAnimatorScript2() {
|
||||
SkScriptCallBack** end = fCallBackArray.end();
|
||||
for (SkScriptCallBack** ptr = fCallBackArray.begin(); ptr < end; ptr++)
|
||||
delete *ptr;
|
||||
}
|
||||
|
||||
bool SkAnimatorScript2::evalMemberCommon(const SkMemberInfo* info,
|
||||
SkDisplayable* displayable, SkOperand2* value) {
|
||||
SkDisplayTypes original;
|
||||
SkDisplayTypes type = original = (SkDisplayTypes) info->getType();
|
||||
if (info->fType == SkType_Array)
|
||||
type = SkType_Array;
|
||||
switch (type) {
|
||||
case SkType_ARGB:
|
||||
type = SkType_Int;
|
||||
case SkType_Boolean:
|
||||
case SkType_Int:
|
||||
case SkType_MSec:
|
||||
case SkType_Float:
|
||||
SkASSERT(info->getCount() == 1);
|
||||
if (info->fType != SkType_MemberProperty && info->fType != SkType_MemberFunction)
|
||||
value->fS32 = *(int32_t*) info->memberData(displayable); // OK for SkScalar too
|
||||
if (type == SkType_MSec) {
|
||||
value->fScalar = SkScalarDiv((SkScalar) value->fS32, 1000); // dividing two ints is the same as dividing two scalars
|
||||
type = SkType_Float;
|
||||
}
|
||||
break;
|
||||
case SkType_String: {
|
||||
SkString* displayableString;
|
||||
if (info->fType != SkType_MemberProperty && info->fType != SkType_MemberFunction) {
|
||||
info->getString(displayable, &displayableString);
|
||||
value->fString = new SkString(*displayableString);
|
||||
}
|
||||
} break;
|
||||
case SkType_Array: {
|
||||
SkASSERT(info->fType != SkType_MemberProperty); // !!! incomplete
|
||||
SkTDOperandArray* displayableArray = (SkTDOperandArray*) info->memberData(displayable);
|
||||
if (displayable->getType() == SkType_Array) {
|
||||
SkDisplayArray* typedArray = (SkDisplayArray*) displayable;
|
||||
original = typedArray->values.getType();
|
||||
}
|
||||
SkASSERT(original != SkType_Unknown);
|
||||
SkOpArray* array = value->fArray = new SkOpArray(ToOpType(original));
|
||||
track(array);
|
||||
int count = displayableArray->count();
|
||||
if (count > 0) {
|
||||
array->setCount(count);
|
||||
memcpy(array->begin(), displayableArray->begin(), count * sizeof(SkOperand2));
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
SkASSERT(0); // unimplemented
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const SkDisplayEnumMap& SkAnimatorScript2::GetEnumValues(SkDisplayTypes type) {
|
||||
int index = SkTSearch<SkDisplayTypes>(&gEnumMaps[0].fType, gEnumMapCount, type,
|
||||
sizeof(SkDisplayEnumMap));
|
||||
SkASSERT(index >= 0);
|
||||
return gEnumMaps[index];
|
||||
}
|
||||
|
||||
SkDisplayTypes SkAnimatorScript2::ToDisplayType(SkOperand2::OpType type) {
|
||||
int val = type;
|
||||
switch (val) {
|
||||
case SkOperand2::kNoType:
|
||||
return SkType_Unknown;
|
||||
case SkOperand2::kS32:
|
||||
return SkType_Int;
|
||||
case SkOperand2::kScalar:
|
||||
return SkType_Float;
|
||||
case SkOperand2::kString:
|
||||
return SkType_String;
|
||||
case SkOperand2::kArray:
|
||||
return SkType_Array;
|
||||
case SkOperand2::kObject:
|
||||
return SkType_Displayable;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return SkType_Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
SkOperand2::OpType SkAnimatorScript2::ToOpType(SkDisplayTypes type) {
|
||||
if (SkDisplayType::IsDisplayable(NULL /* fMaker */, type))
|
||||
return SkOperand2::kObject;
|
||||
if (SkDisplayType::IsEnum(NULL /* fMaker */, type))
|
||||
return SkOperand2::kS32;
|
||||
switch (type) {
|
||||
case SkType_ARGB:
|
||||
case SkType_MSec:
|
||||
case SkType_Int:
|
||||
return SkOperand2::kS32;
|
||||
case SkType_Float:
|
||||
case SkType_Point:
|
||||
case SkType_3D_Point:
|
||||
return SkOperand2::kScalar;
|
||||
case SkType_Base64:
|
||||
case SkType_DynamicString:
|
||||
case SkType_String:
|
||||
return SkOperand2::kString;
|
||||
case SkType_Array:
|
||||
return SkOperand2::kArray;
|
||||
case SkType_Unknown:
|
||||
return SkOperand2::kNoType;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return SkOperand2::kNoType;
|
||||
}
|
||||
}
|
||||
|
||||
bool SkAnimatorScript2::MapEnums(const char* ptr, const char* match, size_t len, int* value) {
|
||||
int index = 0;
|
||||
bool more = true;
|
||||
do {
|
||||
const char* last = strchr(ptr, '|');
|
||||
if (last == NULL) {
|
||||
last = &ptr[strlen(ptr)];
|
||||
more = false;
|
||||
}
|
||||
size_t length = last - ptr;
|
||||
if (len == length && strncmp(ptr, match, length) == 0) {
|
||||
*value = index;
|
||||
return true;
|
||||
}
|
||||
index++;
|
||||
ptr = last + 1;
|
||||
} while (more);
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined SK_DEBUG
|
||||
|
||||
#include "SkAnimator.h"
|
||||
|
||||
static const char scriptTestSetup[] =
|
||||
"<screenplay>"
|
||||
"<apply>"
|
||||
"<paint>"
|
||||
"<emboss id='emboss' direction='[1,1,1]' />"
|
||||
"</paint>"
|
||||
"<animateField id='animation' field='direction' target='emboss' from='[1,1,1]' to='[-1,1,1]' dur='1'/>"
|
||||
"<set lval='direction[0]' target='emboss' to='-1' />"
|
||||
"</apply>"
|
||||
"<color id='testColor' color='0 ? rgb(0,0,0) : rgb(255,255,255)' />"
|
||||
"<color id='xColor' color='rgb(12,34,56)' />"
|
||||
"<typedArray id='emptyArray' />"
|
||||
"<typedArray id='intArray' values='[1, 4, 6]' />"
|
||||
"<s32 id='idx' value='2' />"
|
||||
"<s32 id='idy' value='2' />"
|
||||
"<string id='alpha' value='abc' />"
|
||||
"<rectangle id='testRect' left='Math.cos(0)' top='2' right='12' bottom='5' />"
|
||||
"<event id='evt'>"
|
||||
"<input name='x' />"
|
||||
"<apply scope='idy'>"
|
||||
"<set field='value' to='evt.x.s32' />"
|
||||
"</apply>"
|
||||
"</event>"
|
||||
"</screenplay>";
|
||||
|
||||
#if !defined(SK_BUILD_FOR_BREW)
|
||||
static const SkScriptNAnswer scriptTests[] = {
|
||||
{ "alpha+alpha", SkType_String, 0, 0, "abcabc" },
|
||||
{ "0 ? Math.sin(0) : 1", SkType_Int, 1 },
|
||||
{ "intArray[4]", SkType_Unknown },
|
||||
{ "emptyArray[4]", SkType_Unknown },
|
||||
{ "idx", SkType_Int, 2 },
|
||||
{ "intArray.length", SkType_Int, 3 },
|
||||
{ "intArray.values[0]", SkType_Int, 1 },
|
||||
{ "intArray[0]", SkType_Int, 1 },
|
||||
{ "idx.value", SkType_Int, 2 },
|
||||
{ "alpha.value", SkType_String, 0, 0, "abc" },
|
||||
{ "alpha", SkType_String, 0, 0, "abc" },
|
||||
{ "alpha.value+alpha.value", SkType_String, 0, 0, "abcabc" },
|
||||
{ "alpha+idx", SkType_String, 0, 0, "abc2" },
|
||||
{ "idx+alpha", SkType_String, 0, 0, "2abc" },
|
||||
{ "intArray[idx]", SkType_Int, 6 },
|
||||
{ "alpha.slice(1,2)", SkType_String, 0, 0, "b" },
|
||||
{ "alpha.value.slice(1,2)", SkType_String, 0, 0, "b" },
|
||||
{ "Math.sin(0)", SkType_Float, 0, SkIntToScalar(0) },
|
||||
{ "testRect.left+2", SkType_Float, 0, SkIntToScalar(3) },
|
||||
{ "0 ? intArray[0] : 1", SkType_Int, 1 },
|
||||
{ "0 ? intArray.values[0] : 1", SkType_Int, 1 },
|
||||
{ "0 ? idx : 1", SkType_Int, 1 },
|
||||
{ "0 ? idx.value : 1", SkType_Int, 1 },
|
||||
{ "0 ? alpha.slice(1,2) : 1", SkType_Int, 1 },
|
||||
{ "0 ? alpha.value.slice(1,2) : 1", SkType_Int, 1 },
|
||||
{ "idy", SkType_Int, 3 }
|
||||
};
|
||||
#endif
|
||||
|
||||
#define SkScriptNAnswer_testCount SK_ARRAY_COUNT(scriptTests)
|
||||
|
||||
void SkAnimatorScript2::UnitTest() {
|
||||
#if !defined(SK_BUILD_FOR_BREW) && defined(SK_SUPPORT_UNITTEST)
|
||||
SkAnimator animator;
|
||||
SkASSERT(animator.decodeMemory(scriptTestSetup, sizeof(scriptTestSetup)-1));
|
||||
SkEvent evt;
|
||||
evt.setString("id", "evt");
|
||||
evt.setS32("x", 3);
|
||||
animator.doUserEvent(evt);
|
||||
// set up animator with memory script above, then run value tests
|
||||
for (int index = 0; index < SkScriptNAnswer_testCount; index++) {
|
||||
SkAnimatorScript2 engine(*animator.fMaker, NULL, scriptTests[index].fType);
|
||||
SkScriptValue2 value;
|
||||
const char* script = scriptTests[index].fScript;
|
||||
bool success = engine.evaluateScript(&script, &value);
|
||||
if (success == false) {
|
||||
SkASSERT(scriptTests[index].fType == SkType_Unknown);
|
||||
continue;
|
||||
}
|
||||
SkASSERT(value.fType == ToOpType(scriptTests[index].fType));
|
||||
SkScalar error;
|
||||
switch (value.fType) {
|
||||
case SkOperand2::kS32:
|
||||
SkASSERT(value.fOperand.fS32 == scriptTests[index].fIntAnswer);
|
||||
break;
|
||||
case SkOperand2::kScalar:
|
||||
error = SkScalarAbs(value.fOperand.fScalar - scriptTests[index].fScalarAnswer);
|
||||
SkASSERT(error < SK_Scalar1 / 10000);
|
||||
break;
|
||||
case SkOperand2::kString:
|
||||
SkASSERT(value.fOperand.fString->equals(scriptTests[index].fStringAnswer));
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef SkAnimatorScript2_DEFINED
|
||||
#define SkAnimatorScript2_DEFINED
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkScript2.h"
|
||||
#include "SkTypedArray.h"
|
||||
|
||||
class SkAnimateMaker;
|
||||
struct SkMemberInfo;
|
||||
|
||||
#ifndef SkAnimatorScript_DEFINED
|
||||
struct SkDisplayEnumMap {
|
||||
SkDisplayTypes fType;
|
||||
const char* fValues;
|
||||
};
|
||||
#endif
|
||||
|
||||
class SkAnimatorScript2 : public SkScriptEngine2 {
|
||||
public:
|
||||
SkAnimatorScript2(SkAnimateMaker& , SkDisplayable* working, SkDisplayTypes type);
|
||||
~SkAnimatorScript2();
|
||||
bool evalMemberCommon(const SkMemberInfo* info,
|
||||
SkDisplayable* displayable, SkOperand2* value);
|
||||
SkAnimateMaker& getMaker() { return fMaker; }
|
||||
SkDisplayable* getWorking() { return fWorking; }
|
||||
static bool MapEnums(const char* ptr, const char* match, size_t len, int* value);
|
||||
static const SkDisplayEnumMap& GetEnumValues(SkDisplayTypes type);
|
||||
static SkDisplayTypes ToDisplayType(SkOperand2::OpType type);
|
||||
static SkOperand2::OpType ToOpType(SkDisplayTypes type);
|
||||
private:
|
||||
SkAnimateMaker& fMaker;
|
||||
SkDisplayable* fWorking;
|
||||
friend class SkDump;
|
||||
friend struct SkScriptNAnswer;
|
||||
// illegal
|
||||
SkAnimatorScript2& operator=(const SkAnimatorScript2&);
|
||||
#ifdef SK_DEBUG
|
||||
public:
|
||||
static void UnitTest();
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // SkAnimatorScript2_DEFINED
|
||||
@@ -0,0 +1,188 @@
|
||||
/* libs/graphics/animator/SkBase64.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkBase64.h"
|
||||
|
||||
#define DecodePad -2
|
||||
#define EncodePad 64
|
||||
|
||||
static const char encode[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789+/=";
|
||||
|
||||
static const signed char decodeData[] = {
|
||||
62, -1, -1, -1, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, DecodePad, -1, -1,
|
||||
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
|
||||
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
|
||||
};
|
||||
|
||||
SkBase64::SkBase64() : fLength((size_t) -1), fData(NULL) {
|
||||
}
|
||||
|
||||
#if defined _WIN32 && _MSC_VER >= 1300 // disable 'two', etc. may be used without having been initialized
|
||||
#pragma warning ( push )
|
||||
#pragma warning ( disable : 4701 )
|
||||
#endif
|
||||
|
||||
SkBase64::Error SkBase64::decode(const void* srcPtr, size_t size, bool writeDestination) {
|
||||
unsigned char* dst = (unsigned char*) fData;
|
||||
const unsigned char* dstStart = (const unsigned char*) fData;
|
||||
const unsigned char* src = (const unsigned char*) srcPtr;
|
||||
bool padTwo = false;
|
||||
bool padThree = false;
|
||||
const unsigned char* end = src + size;
|
||||
while (src < end) {
|
||||
unsigned char bytes[4];
|
||||
int byte = 0;
|
||||
do {
|
||||
unsigned char srcByte = *src++;
|
||||
if (srcByte == 0)
|
||||
goto goHome;
|
||||
if (srcByte <= ' ')
|
||||
continue; // treat as white space
|
||||
if (srcByte < '+' || srcByte > 'z')
|
||||
return kBadCharError;
|
||||
signed char decoded = decodeData[srcByte - '+'];
|
||||
bytes[byte] = decoded;
|
||||
if (decoded < 0) {
|
||||
if (decoded == DecodePad)
|
||||
goto handlePad;
|
||||
return kBadCharError;
|
||||
} else
|
||||
byte++;
|
||||
if (*src)
|
||||
continue;
|
||||
if (byte == 0)
|
||||
goto goHome;
|
||||
if (byte == 4)
|
||||
break;
|
||||
handlePad:
|
||||
if (byte < 2)
|
||||
return kPadError;
|
||||
padThree = true;
|
||||
if (byte == 2)
|
||||
padTwo = true;
|
||||
break;
|
||||
} while (byte < 4);
|
||||
int two, three;
|
||||
if (writeDestination) {
|
||||
int one = (uint8_t) (bytes[0] << 2);
|
||||
two = bytes[1];
|
||||
one |= two >> 4;
|
||||
two = (uint8_t) (two << 4);
|
||||
three = bytes[2];
|
||||
two |= three >> 2;
|
||||
three = (uint8_t) (three << 6);
|
||||
three |= bytes[3];
|
||||
SkASSERT(one < 256 && two < 256 && three < 256);
|
||||
*dst = (unsigned char) one;
|
||||
}
|
||||
dst++;
|
||||
if (padTwo)
|
||||
break;
|
||||
if (writeDestination)
|
||||
*dst = (unsigned char) two;
|
||||
dst++;
|
||||
if (padThree)
|
||||
break;
|
||||
if (writeDestination)
|
||||
*dst = (unsigned char) three;
|
||||
dst++;
|
||||
}
|
||||
goHome:
|
||||
fLength = dst - dstStart;
|
||||
return kNoError;
|
||||
}
|
||||
|
||||
#if defined _WIN32 && _MSC_VER >= 1300
|
||||
#pragma warning ( pop )
|
||||
#endif
|
||||
|
||||
size_t SkBase64::Encode(const void* srcPtr, size_t length, void* dstPtr) {
|
||||
const unsigned char* src = (const unsigned char*) srcPtr;
|
||||
unsigned char* dst = (unsigned char*) dstPtr;
|
||||
if (dst) {
|
||||
size_t remainder = length % 3;
|
||||
const unsigned char* end = &src[length - remainder];
|
||||
while (src < end) {
|
||||
unsigned a = *src++;
|
||||
unsigned b = *src++;
|
||||
unsigned c = *src++;
|
||||
int d = c & 0x3F;
|
||||
c = (c >> 6 | b << 2) & 0x3F;
|
||||
b = (b >> 4 | a << 4) & 0x3F;
|
||||
a = a >> 2;
|
||||
*dst++ = encode[a];
|
||||
*dst++ = encode[b];
|
||||
*dst++ = encode[c];
|
||||
*dst++ = encode[d];
|
||||
}
|
||||
if (remainder > 0) {
|
||||
int k1 = 0;
|
||||
int k2 = EncodePad;
|
||||
int a = (uint8_t) *src++;
|
||||
if (remainder == 2)
|
||||
{
|
||||
int b = *src++;
|
||||
k1 = b >> 4;
|
||||
k2 = (b << 2) & 0x3F;
|
||||
}
|
||||
*dst++ = encode[a >> 2];
|
||||
*dst++ = encode[(k1 | a << 4) & 0x3F];
|
||||
*dst++ = encode[k2];
|
||||
*dst++ = encode[EncodePad];
|
||||
}
|
||||
}
|
||||
return (length + 2) / 3 * 4;
|
||||
}
|
||||
|
||||
SkBase64::Error SkBase64::decode(const char* src, size_t len) {
|
||||
Error err = decode(src, len, false);
|
||||
SkASSERT(err == kNoError);
|
||||
if (err != kNoError)
|
||||
return err;
|
||||
fData = new char[fLength]; // should use sk_malloc/sk_free
|
||||
decode(src, len, true);
|
||||
return kNoError;
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_UNITTEST
|
||||
void SkBase64::UnitTest() {
|
||||
signed char all[256];
|
||||
for (int index = 0; index < 256; index++)
|
||||
all[index] = (signed char) (index + 1);
|
||||
for (int offset = 0; offset < 6; offset++) {
|
||||
size_t length = 256 - offset;
|
||||
size_t encodeLength = Encode(all + offset, length, NULL);
|
||||
char* src = (char*)sk_malloc_throw(encodeLength + 1);
|
||||
Encode(all + offset, length, src);
|
||||
src[encodeLength] = '\0';
|
||||
SkBase64 tryMe;
|
||||
tryMe.decode(src, encodeLength);
|
||||
SkASSERT(length == tryMe.fLength);
|
||||
SkASSERT(strcmp((const char*) (all + offset), tryMe.fData) == 0);
|
||||
sk_free(src);
|
||||
delete[] tryMe.fData;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/* libs/graphics/animator/SkBase64.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkBase64_DEFINED
|
||||
#define SkBase64_DEFINED
|
||||
|
||||
#include "SkTypes.h"
|
||||
|
||||
struct SkBase64 {
|
||||
public:
|
||||
enum Error {
|
||||
kNoError,
|
||||
kPadError,
|
||||
kBadCharError
|
||||
};
|
||||
|
||||
SkBase64();
|
||||
Error decode(const char* src, size_t length);
|
||||
char* getData() { return fData; }
|
||||
static size_t Encode(const void* src, size_t length, void* dest);
|
||||
|
||||
#ifdef SK_SUPPORT_UNITTEST
|
||||
static void UnitTest();
|
||||
#endif
|
||||
private:
|
||||
Error decode(const void* srcPtr, size_t length, bool writeDestination);
|
||||
|
||||
size_t fLength;
|
||||
char* fData;
|
||||
friend class SkImage;
|
||||
};
|
||||
|
||||
#endif // SkBase64_DEFINED
|
||||
@@ -0,0 +1,64 @@
|
||||
/* libs/graphics/animator/SkBoundable.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkBoundable.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkCanvas.h"
|
||||
|
||||
SkBoundable::SkBoundable() {
|
||||
clearBounds();
|
||||
fBounds.fTop = 0;
|
||||
fBounds.fRight = 0;
|
||||
fBounds.fBottom = 0;
|
||||
}
|
||||
|
||||
void SkBoundable::clearBounder() {
|
||||
fBounds.fLeft = 0x7fff;
|
||||
}
|
||||
|
||||
void SkBoundable::getBounds(SkRect* rect) {
|
||||
SkASSERT(rect);
|
||||
if (fBounds.fLeft == (int16_t)0x8000U) {
|
||||
INHERITED::getBounds(rect);
|
||||
return;
|
||||
}
|
||||
rect->fLeft = SkIntToScalar(fBounds.fLeft);
|
||||
rect->fTop = SkIntToScalar(fBounds.fTop);
|
||||
rect->fRight = SkIntToScalar(fBounds.fRight);
|
||||
rect->fBottom = SkIntToScalar(fBounds.fBottom);
|
||||
}
|
||||
|
||||
void SkBoundable::enableBounder() {
|
||||
fBounds.fLeft = 0;
|
||||
}
|
||||
|
||||
|
||||
SkBoundableAuto::SkBoundableAuto(SkBoundable* boundable,
|
||||
SkAnimateMaker& maker) : fBoundable(boundable), fMaker(maker) {
|
||||
if (fBoundable->hasBounds()) {
|
||||
fMaker.fCanvas->setBounder(&maker.fDisplayList);
|
||||
fMaker.fDisplayList.fBounds.setEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
SkBoundableAuto::~SkBoundableAuto() {
|
||||
if (fBoundable->hasBounds() == false)
|
||||
return;
|
||||
fMaker.fCanvas->setBounder(NULL);
|
||||
fBoundable->setBounds(fMaker.fDisplayList.fBounds);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/* libs/graphics/animator/SkBoundable.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkBoundable_DEFINED
|
||||
#define SkBoundable_DEFINED
|
||||
|
||||
#include "SkDrawable.h"
|
||||
#include "SkRect.h"
|
||||
|
||||
class SkBoundable : public SkDrawable {
|
||||
public:
|
||||
SkBoundable();
|
||||
virtual void clearBounder();
|
||||
virtual void enableBounder();
|
||||
virtual void getBounds(SkRect* );
|
||||
bool hasBounds() { return fBounds.fLeft != (int16_t)0x8000U; }
|
||||
void setBounds(SkIRect& bounds) { fBounds = bounds; }
|
||||
protected:
|
||||
void clearBounds() { fBounds.fLeft = (int16_t) SkToU16(0x8000); }; // mark bounds as unset
|
||||
SkIRect fBounds;
|
||||
private:
|
||||
typedef SkDrawable INHERITED;
|
||||
};
|
||||
|
||||
class SkBoundableAuto {
|
||||
public:
|
||||
SkBoundableAuto(SkBoundable* boundable, SkAnimateMaker& maker);
|
||||
~SkBoundableAuto();
|
||||
private:
|
||||
SkBoundable* fBoundable;
|
||||
SkAnimateMaker& fMaker;
|
||||
SkBoundableAuto& operator= (const SkBoundableAuto& );
|
||||
};
|
||||
|
||||
#endif // SkBoundable_DEFINED
|
||||
|
||||
@@ -0,0 +1,292 @@
|
||||
/* libs/graphics/animator/SkBuildCondensedInfo.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkTypes.h"
|
||||
#if defined SK_BUILD_CONDENSED
|
||||
#include "SkMemberInfo.h"
|
||||
#if SK_USE_CONDENSED_INFO == 1
|
||||
#error "SK_USE_CONDENSED_INFO must be zero to build condensed info"
|
||||
#endif
|
||||
#if !defined SK_BUILD_FOR_WIN32
|
||||
#error "SK_BUILD_FOR_WIN32 must be defined to build condensed info"
|
||||
#endif
|
||||
#include "SkDisplayType.h"
|
||||
#include "SkIntArray.h"
|
||||
#include <stdio.h>
|
||||
|
||||
SkTDMemberInfoArray gInfos;
|
||||
SkTDIntArray gInfosCounts;
|
||||
SkTDDisplayTypesArray gInfosTypeIDs;
|
||||
SkTDMemberInfoArray gUnknowns;
|
||||
SkTDIntArray gUnknownsCounts;
|
||||
|
||||
static void AddInfo(SkDisplayTypes type, const SkMemberInfo* info, int infoCount) {
|
||||
SkASSERT(gInfos[type] == NULL);
|
||||
gInfos[type] = info;
|
||||
gInfosCounts[type] = infoCount;
|
||||
*gInfosTypeIDs.append() = type;
|
||||
size_t allStrs = 0;
|
||||
for (int inner = 0; inner < infoCount; inner++) {
|
||||
SkASSERT(info[inner].fCount < 256);
|
||||
int offset = (int) info[inner].fOffset;
|
||||
SkASSERT(offset < 128 && offset > -129);
|
||||
SkASSERT(allStrs < 256);
|
||||
if (info[inner].fType == SkType_BaseClassInfo) {
|
||||
const SkMemberInfo* innerInfo = (const SkMemberInfo*) info[inner].fName;
|
||||
if (gUnknowns.find(innerInfo) == -1) {
|
||||
*gUnknowns.append() = innerInfo;
|
||||
*gUnknownsCounts.append() = info[inner].fCount;
|
||||
}
|
||||
}
|
||||
if (info[inner].fType != SkType_BaseClassInfo && info[inner].fName)
|
||||
allStrs += strlen(info[inner].fName);
|
||||
allStrs += 1;
|
||||
SkASSERT(info[inner].fType < 256);
|
||||
}
|
||||
}
|
||||
|
||||
static void WriteInfo(FILE* condensed, const SkMemberInfo* info, int infoCount,
|
||||
const char* typeName, bool draw, bool display) {
|
||||
fprintf(condensed, "static const char g%sStrings[] = \n", typeName);
|
||||
int inner;
|
||||
// write strings
|
||||
for (inner = 0; inner < infoCount; inner++) {
|
||||
const char* name = (info[inner].fType != SkType_BaseClassInfo && info[inner].fName) ?
|
||||
info[inner].fName : "";
|
||||
const char* zero = inner < infoCount - 1 ? "\\0" : "";
|
||||
fprintf(condensed, "\t\"%s%s\"\n", name, zero);
|
||||
}
|
||||
fprintf(condensed, ";\n\nstatic const SkMemberInfo g%s", draw ? "Draw" : display ? "Display" : "");
|
||||
fprintf(condensed, "%sInfo[] = {", typeName);
|
||||
size_t nameOffset = 0;
|
||||
// write info tables
|
||||
for (inner = 0; inner < infoCount; inner++) {
|
||||
size_t offset = info[inner].fOffset;
|
||||
if (info[inner].fType == SkType_BaseClassInfo) {
|
||||
offset = (size_t) gInfos.find((const SkMemberInfo* ) info[inner].fName);
|
||||
SkASSERT((int) offset >= 0);
|
||||
offset = gInfosTypeIDs.find((SkDisplayTypes) offset);
|
||||
SkASSERT((int) offset >= 0);
|
||||
}
|
||||
fprintf(condensed, "\n\t{%d, %d, %d, %d}", nameOffset, offset,
|
||||
info[inner].fType, info[inner].fCount);
|
||||
if (inner < infoCount - 1)
|
||||
putc(',', condensed);
|
||||
if (info[inner].fType != SkType_BaseClassInfo && info[inner].fName)
|
||||
nameOffset += strlen(info[inner].fName);
|
||||
nameOffset += 1;
|
||||
}
|
||||
fprintf(condensed, "\n};\n\n");
|
||||
}
|
||||
|
||||
static void Get3DName(char* scratch, const char* name) {
|
||||
if (strncmp("skia3d:", name, sizeof("skia3d:") - 1) == 0) {
|
||||
strcpy(scratch, "3D_");
|
||||
scratch[3]= name[7] & ~0x20;
|
||||
strcpy(&scratch[4], &name[8]);
|
||||
} else {
|
||||
scratch[0] = name[0] & ~0x20;
|
||||
strcpy(&scratch[1], &name[1]);
|
||||
}
|
||||
}
|
||||
|
||||
int type_compare(const void* a, const void* b) {
|
||||
SkDisplayTypes first = *(SkDisplayTypes*) a;
|
||||
SkDisplayTypes second = *(SkDisplayTypes*) b;
|
||||
return first < second ? -1 : first == second ? 0 : 1;
|
||||
}
|
||||
|
||||
void SkDisplayType::BuildCondensedInfo(SkAnimateMaker* maker) {
|
||||
gInfos.setCount(kNumberOfTypes);
|
||||
memset(gInfos.begin(), 0, sizeof(gInfos[0]) * kNumberOfTypes);
|
||||
gInfosCounts.setCount(kNumberOfTypes);
|
||||
memset(gInfosCounts.begin(), -1, sizeof(gInfosCounts[0]) * kNumberOfTypes);
|
||||
// check to see if it is condensable
|
||||
int index, infoCount;
|
||||
for (index = 0; index < kTypeNamesSize; index++) {
|
||||
const SkMemberInfo* info = GetMembers(maker, gTypeNames[index].fType, &infoCount);
|
||||
if (info == NULL)
|
||||
continue;
|
||||
AddInfo(gTypeNames[index].fType, info, infoCount);
|
||||
}
|
||||
const SkMemberInfo* extraInfo =
|
||||
SkDisplayType::GetMembers(maker, SkType_3D_Point, &infoCount);
|
||||
AddInfo(SkType_Point, extraInfo, infoCount);
|
||||
AddInfo(SkType_3D_Point, extraInfo, infoCount);
|
||||
// int baseInfos = gInfos.count();
|
||||
do {
|
||||
SkTDMemberInfoArray oldRefs = gUnknowns;
|
||||
SkTDIntArray oldRefCounts = gUnknownsCounts;
|
||||
gUnknowns.reset();
|
||||
gUnknownsCounts.reset();
|
||||
for (index = 0; index < oldRefs.count(); index++) {
|
||||
const SkMemberInfo* info = oldRefs[index];
|
||||
if (gInfos.find(info) == -1) {
|
||||
int typeIndex = 0;
|
||||
for (; typeIndex < kNumberOfTypes; typeIndex++) {
|
||||
const SkMemberInfo* temp = SkDisplayType::GetMembers(
|
||||
maker, (SkDisplayTypes) typeIndex, NULL);
|
||||
if (temp == info)
|
||||
break;
|
||||
}
|
||||
SkASSERT(typeIndex < kNumberOfTypes);
|
||||
AddInfo((SkDisplayTypes) typeIndex, info, oldRefCounts[index]);
|
||||
}
|
||||
}
|
||||
} while (gUnknowns.count() > 0);
|
||||
qsort(gInfosTypeIDs.begin(), gInfosTypeIDs.count(), sizeof(gInfosTypeIDs[0]), &type_compare);
|
||||
#ifdef SK_DEBUG
|
||||
FILE* condensed = fopen("../../src/animator/SkCondensedDebug.cpp", "w+");
|
||||
fprintf(condensed, "#include \"SkTypes.h\"\n");
|
||||
fprintf(condensed, "#ifdef SK_DEBUG\n");
|
||||
#else
|
||||
FILE* condensed = fopen("../../src/animator/SkCondensedRelease.cpp", "w+");
|
||||
fprintf(condensed, "#include \"SkTypes.h\"\n");
|
||||
fprintf(condensed, "#ifdef SK_RELEASE\n");
|
||||
#endif
|
||||
// write header
|
||||
fprintf(condensed, "// This file was automatically generated.\n");
|
||||
fprintf(condensed, "// To change it, edit the file with the matching debug info.\n");
|
||||
fprintf(condensed, "// Then execute SkDisplayType::BuildCondensedInfo() to "
|
||||
"regenerate this file.\n\n");
|
||||
// write name of memberInfo
|
||||
int typeNameIndex = 0;
|
||||
int unknown = 1;
|
||||
for (index = 0; index < gInfos.count(); index++) {
|
||||
const SkMemberInfo* info = gInfos[index];
|
||||
if (info == NULL)
|
||||
continue;
|
||||
char scratch[64];
|
||||
bool drawPrefix, displayPrefix;
|
||||
while (gTypeNames[typeNameIndex].fType < index)
|
||||
typeNameIndex++;
|
||||
if (gTypeNames[typeNameIndex].fType == index) {
|
||||
Get3DName(scratch, gTypeNames[typeNameIndex].fName);
|
||||
drawPrefix = gTypeNames[typeNameIndex].fDrawPrefix;
|
||||
displayPrefix = gTypeNames[typeNameIndex].fDisplayPrefix;
|
||||
} else {
|
||||
sprintf(scratch, "Unknown%d", unknown++);
|
||||
drawPrefix = displayPrefix = false;
|
||||
}
|
||||
WriteInfo(condensed, info, gInfosCounts[index], scratch, drawPrefix, displayPrefix);
|
||||
}
|
||||
// write array of table pointers
|
||||
// start here;
|
||||
fprintf(condensed, "static const SkMemberInfo* const gInfoTables[] = {");
|
||||
typeNameIndex = 0;
|
||||
unknown = 1;
|
||||
for (index = 0; index < gInfos.count(); index++) {
|
||||
const SkMemberInfo* info = gInfos[index];
|
||||
if (info == NULL)
|
||||
continue;
|
||||
char scratch[64];
|
||||
bool drawPrefix, displayPrefix;
|
||||
while (gTypeNames[typeNameIndex].fType < index)
|
||||
typeNameIndex++;
|
||||
if (gTypeNames[typeNameIndex].fType == index) {
|
||||
Get3DName(scratch, gTypeNames[typeNameIndex].fName);
|
||||
drawPrefix = gTypeNames[typeNameIndex].fDrawPrefix;
|
||||
displayPrefix = gTypeNames[typeNameIndex].fDisplayPrefix;
|
||||
} else {
|
||||
sprintf(scratch, "Unknown%d", unknown++);
|
||||
drawPrefix = displayPrefix = false;
|
||||
}
|
||||
fprintf(condensed, "\n\tg");
|
||||
if (drawPrefix)
|
||||
fprintf(condensed, "Draw");
|
||||
if (displayPrefix)
|
||||
fprintf(condensed, "Display");
|
||||
fprintf(condensed, "%sInfo", scratch);
|
||||
if (index < gInfos.count() - 1)
|
||||
putc(',', condensed);
|
||||
}
|
||||
fprintf(condensed, "\n};\n\n");
|
||||
// write the array of number of entries in the info table
|
||||
fprintf(condensed, "static const unsigned char gInfoCounts[] = {\n\t");
|
||||
int written = 0;
|
||||
for (index = 0; index < gInfosCounts.count(); index++) {
|
||||
int count = gInfosCounts[index];
|
||||
if (count < 0)
|
||||
continue;
|
||||
if (written > 0)
|
||||
putc(',', condensed);
|
||||
if (written % 20 == 19)
|
||||
fprintf(condensed, "\n\t");
|
||||
fprintf(condensed, "%d",count);
|
||||
written++;
|
||||
}
|
||||
fprintf(condensed, "\n};\n\n");
|
||||
// write array of type ids table entries correspond to
|
||||
fprintf(condensed, "static const unsigned char gTypeIDs[] = {\n\t");
|
||||
int typeIDCount = 0;
|
||||
typeNameIndex = 0;
|
||||
unknown = 1;
|
||||
for (index = 0; index < gInfosCounts.count(); index++) {
|
||||
const SkMemberInfo* info = gInfos[index];
|
||||
if (info == NULL)
|
||||
continue;
|
||||
typeIDCount++;
|
||||
char scratch[64];
|
||||
while (gTypeNames[typeNameIndex].fType < index)
|
||||
typeNameIndex++;
|
||||
if (gTypeNames[typeNameIndex].fType == index) {
|
||||
Get3DName(scratch, gTypeNames[typeNameIndex].fName);
|
||||
} else
|
||||
sprintf(scratch, "Unknown%d", unknown++);
|
||||
fprintf(condensed, "%d%c // %s\n\t", index,
|
||||
index < gInfosCounts.count() ? ',' : ' ', scratch);
|
||||
}
|
||||
fprintf(condensed, "\n};\n\n");
|
||||
fprintf(condensed, "static const int kTypeIDs = %d;\n\n", typeIDCount);
|
||||
// write the array of string pointers
|
||||
fprintf(condensed, "static const char* const gInfoNames[] = {");
|
||||
typeNameIndex = 0;
|
||||
unknown = 1;
|
||||
written = 0;
|
||||
for (index = 0; index < gInfosCounts.count(); index++) {
|
||||
const SkMemberInfo* info = gInfos[index];
|
||||
if (info == NULL)
|
||||
continue;
|
||||
if (written > 0)
|
||||
putc(',', condensed);
|
||||
written++;
|
||||
fprintf(condensed, "\n\tg");
|
||||
char scratch[64];
|
||||
while (gTypeNames[typeNameIndex].fType < index)
|
||||
typeNameIndex++;
|
||||
if (gTypeNames[typeNameIndex].fType == index) {
|
||||
Get3DName(scratch, gTypeNames[typeNameIndex].fName);
|
||||
} else
|
||||
sprintf(scratch, "Unknown%d", unknown++);
|
||||
fprintf(condensed, "%sStrings", scratch);
|
||||
}
|
||||
fprintf(condensed, "\n};\n\n");
|
||||
fprintf(condensed, "#endif\n");
|
||||
fclose(condensed);
|
||||
gInfos.reset();
|
||||
gInfosCounts.reset();
|
||||
gInfosTypeIDs.reset();
|
||||
gUnknowns.reset();
|
||||
gUnknownsCounts.reset();
|
||||
}
|
||||
|
||||
#elif defined SK_DEBUG
|
||||
#include "SkDisplayType.h"
|
||||
void SkDisplayType::BuildCondensedInfo(SkAnimateMaker* ) {}
|
||||
#endif
|
||||
|
||||
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -0,0 +1,254 @@
|
||||
/* libs/graphics/animator/SkDisplayAdd.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayAdd.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkDisplayList.h"
|
||||
#include "SkDrawable.h"
|
||||
#include "SkDrawGroup.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkAdd::fInfo[] = {
|
||||
SK_MEMBER(mode, AddMode),
|
||||
SK_MEMBER(offset, Int),
|
||||
SK_MEMBER(use, Drawable),
|
||||
SK_MEMBER(where, Drawable)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// start here;
|
||||
// add onEndElement to turn where string into f_Where
|
||||
// probably need new SkAnimateMaker::resolve flavor that takes
|
||||
// where="id", where="event-target" or not-specified
|
||||
// offset="#" (implements before, after, and index if no 'where')
|
||||
|
||||
DEFINE_GET_MEMBER(SkAdd);
|
||||
|
||||
SkAdd::SkAdd() : mode(kMode_indirect),
|
||||
offset(SK_MaxS32), use(NULL), where(NULL) {
|
||||
}
|
||||
|
||||
SkDisplayable* SkAdd::deepCopy(SkAnimateMaker* maker) {
|
||||
SkDrawable* saveUse = use;
|
||||
SkDrawable* saveWhere = where;
|
||||
use = NULL;
|
||||
where = NULL;
|
||||
SkAdd* copy = (SkAdd*) INHERITED::deepCopy(maker);
|
||||
copy->use = use = saveUse;
|
||||
copy->where = where = saveWhere;
|
||||
return copy;
|
||||
}
|
||||
|
||||
bool SkAdd::draw(SkAnimateMaker& maker) {
|
||||
SkASSERT(use);
|
||||
SkASSERT(use->isDrawable());
|
||||
if (mode == kMode_indirect)
|
||||
use->draw(maker);
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkAdd::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
dumpAttrs(maker);
|
||||
if (where)
|
||||
SkDebugf("where=\"%s\" ", where->id);
|
||||
if (mode == kMode_immediate)
|
||||
SkDebugf("mode=\"immediate\" ");
|
||||
SkDebugf(">\n");
|
||||
SkDisplayList::fIndent += 4;
|
||||
int save = SkDisplayList::fDumpIndex;
|
||||
if (use) //just in case
|
||||
use->dump(maker);
|
||||
SkDisplayList::fIndent -= 4;
|
||||
SkDisplayList::fDumpIndex = save;
|
||||
dumpEnd(maker);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkAdd::enable(SkAnimateMaker& maker ) {
|
||||
SkDisplayTypes type = getType();
|
||||
SkDisplayList& displayList = maker.fDisplayList;
|
||||
SkTDDrawableArray* parentList = displayList.getDrawList();
|
||||
if (type == SkType_Add) {
|
||||
if (use == NULL) // not set in apply yet
|
||||
return true;
|
||||
}
|
||||
bool skipAddToParent = true;
|
||||
SkASSERT(type != SkType_Replace || where);
|
||||
SkTDDrawableArray* grandList SK_INIT_TO_AVOID_WARNING;
|
||||
SkGroup* parentGroup = NULL;
|
||||
SkGroup* thisGroup = NULL;
|
||||
int index = where ? displayList.findGroup(where, &parentList, &parentGroup,
|
||||
&thisGroup, &grandList) : 0;
|
||||
if (index < 0)
|
||||
return true;
|
||||
int max = parentList->count();
|
||||
if (where == NULL && type == SkType_Move)
|
||||
index = max;
|
||||
if (offset != SK_MaxS32) {
|
||||
index += offset;
|
||||
if (index > max) {
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kIndexOutOfRange);
|
||||
return true; // caller should not add
|
||||
}
|
||||
}
|
||||
if (offset < 0 && where == NULL)
|
||||
index += max + 1;
|
||||
switch (type) {
|
||||
case SkType_Add:
|
||||
if (offset == SK_MaxS32 && where == NULL) {
|
||||
if (use->isDrawable()) {
|
||||
skipAddToParent = mode == kMode_immediate;
|
||||
if (skipAddToParent) {
|
||||
if (where == NULL) {
|
||||
SkTDDrawableArray* useParentList;
|
||||
index = displayList.findGroup(this, &useParentList, &parentGroup,
|
||||
&thisGroup, &grandList);
|
||||
if (index >= 0) {
|
||||
parentGroup->markCopySize(index);
|
||||
parentGroup->markCopySet(index);
|
||||
useParentList->begin()[index] = use;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*parentList->append() = use;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if (thisGroup)
|
||||
thisGroup->markCopySize(index);
|
||||
*parentList->insert(index) = use;
|
||||
if (thisGroup)
|
||||
thisGroup->markCopySet(index);
|
||||
if (use->isApply())
|
||||
((SkApply*) use)->setEmbedded();
|
||||
}
|
||||
break;
|
||||
case SkType_Move: {
|
||||
int priorLocation = parentList->find(use);
|
||||
if (priorLocation < 0)
|
||||
break;
|
||||
*parentList->insert(index) = use;
|
||||
if (index < priorLocation)
|
||||
priorLocation++;
|
||||
parentList->remove(priorLocation);
|
||||
} break;
|
||||
case SkType_Remove: {
|
||||
SkDisplayable* old = (*parentList)[index];
|
||||
if (((SkRemove*)(this))->fDelete) {
|
||||
delete old;
|
||||
goto noHelperNeeded;
|
||||
}
|
||||
for (int inner = 0; inner < maker.fChildren.count(); inner++) {
|
||||
SkDisplayable* child = maker.fChildren[inner];
|
||||
if (child == old || child->contains(old))
|
||||
goto noHelperNeeded;
|
||||
}
|
||||
if (maker.fHelpers.find(old) < 0)
|
||||
maker.helperAdd(old);
|
||||
noHelperNeeded:
|
||||
parentList->remove(index);
|
||||
} break;
|
||||
case SkType_Replace:
|
||||
if (thisGroup) {
|
||||
thisGroup->markCopySize(index);
|
||||
if (thisGroup->markedForDelete(index)) {
|
||||
SkDisplayable* old = (*parentList)[index];
|
||||
if (maker.fHelpers.find(old) < 0)
|
||||
maker.helperAdd(old);
|
||||
}
|
||||
}
|
||||
(*parentList)[index] = use;
|
||||
if (thisGroup)
|
||||
thisGroup->markCopySet(index);
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
}
|
||||
if (type == SkType_Remove)
|
||||
return true;
|
||||
if (use->hasEnable())
|
||||
use->enable(maker);
|
||||
return skipAddToParent; // append if indirect: *parentList->append() = this;
|
||||
}
|
||||
|
||||
bool SkAdd::hasEnable() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkAdd::initialize() {
|
||||
if (use)
|
||||
use->initialize();
|
||||
}
|
||||
|
||||
bool SkAdd::isDrawable() const {
|
||||
return getType() == SkType_Add && mode == kMode_indirect && offset == SK_MaxS32 &&
|
||||
where == NULL && use != NULL && use->isDrawable();
|
||||
}
|
||||
|
||||
//SkDisplayable* SkAdd::resolveTarget(SkAnimateMaker& maker) {
|
||||
// return use;
|
||||
//}
|
||||
|
||||
|
||||
bool SkClear::enable(SkAnimateMaker& maker ) {
|
||||
SkDisplayList& displayList = maker.fDisplayList;
|
||||
displayList.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkMove::fInfo[] = {
|
||||
SK_MEMBER_INHERITED
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkMove);
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkRemove::fInfo[] = {
|
||||
SK_MEMBER_ALIAS(delete, fDelete, Boolean), // !!! experimental
|
||||
SK_MEMBER(offset, Int),
|
||||
SK_MEMBER(where, Drawable)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkRemove);
|
||||
|
||||
SkRemove::SkRemove() : fDelete(false) {
|
||||
}
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkReplace::fInfo[] = {
|
||||
SK_MEMBER_INHERITED
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkReplace);
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/* libs/graphics/animator/SkDisplayAdd.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayAdd_DEFINED
|
||||
#define SkDisplayAdd_DEFINED
|
||||
|
||||
#include "SkDrawable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
|
||||
class SkAdd : public SkDrawable {
|
||||
DECLARE_MEMBER_INFO(Add);
|
||||
SkAdd();
|
||||
|
||||
enum Mode {
|
||||
kMode_indirect,
|
||||
kMode_immediate
|
||||
};
|
||||
|
||||
virtual SkDisplayable* deepCopy(SkAnimateMaker* );
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
virtual bool enable(SkAnimateMaker& );
|
||||
virtual bool hasEnable() const;
|
||||
virtual void initialize();
|
||||
virtual bool isDrawable() const;
|
||||
protected:
|
||||
// struct _A {
|
||||
Mode mode;
|
||||
int32_t offset;
|
||||
SkDrawable* use;
|
||||
SkDrawable* where; // if NULL, offset becomes index
|
||||
// } A;
|
||||
private:
|
||||
typedef SkDrawable INHERITED;
|
||||
};
|
||||
|
||||
class SkClear : public SkDisplayable {
|
||||
virtual bool enable(SkAnimateMaker& );
|
||||
};
|
||||
|
||||
class SkMove : public SkAdd {
|
||||
DECLARE_MEMBER_INFO(Move);
|
||||
private:
|
||||
typedef SkAdd INHERITED;
|
||||
};
|
||||
|
||||
class SkRemove : public SkAdd {
|
||||
DECLARE_MEMBER_INFO(Remove);
|
||||
SkRemove();
|
||||
protected:
|
||||
SkBool fDelete;
|
||||
private:
|
||||
friend class SkAdd;
|
||||
typedef SkAdd INHERITED;
|
||||
};
|
||||
|
||||
class SkReplace : public SkAdd {
|
||||
DECLARE_MEMBER_INFO(Replace);
|
||||
private:
|
||||
typedef SkAdd INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDisplayAdd_DEFINED
|
||||
|
||||
|
||||
@@ -0,0 +1,814 @@
|
||||
/* libs/graphics/animator/SkDisplayApply.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkAnimateActive.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkAnimateSet.h"
|
||||
#include "SkAnimatorScript.h"
|
||||
#include "SkDisplayType.h"
|
||||
#include "SkDrawGroup.h"
|
||||
#include "SkParse.h"
|
||||
#include "SkScript.h"
|
||||
#include "SkSystemEventTypes.h"
|
||||
#ifdef SK_DEBUG
|
||||
#include "SkTime.h"
|
||||
#endif
|
||||
#include <ctype.h>
|
||||
|
||||
enum SkApply_Properties {
|
||||
SK_PROPERTY(animator),
|
||||
SK_PROPERTY(step),
|
||||
SK_PROPERTY(steps),
|
||||
SK_PROPERTY(time)
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
// if no attibutes, enclosed displayable is both scope & target
|
||||
// only if both scope & target are specified, or if target and enclosed displayable, are scope and target different
|
||||
const SkMemberInfo SkApply::fInfo[] = {
|
||||
SK_MEMBER_PROPERTY(animator, Animate),
|
||||
SK_MEMBER(begin, MSec),
|
||||
SK_MEMBER(dontDraw, Boolean),
|
||||
SK_MEMBER(dynamicScope, String),
|
||||
SK_MEMBER(interval, MSec), // recommended redraw interval
|
||||
SK_MEMBER(mode, ApplyMode),
|
||||
#if 0
|
||||
SK_MEMBER(pickup, Boolean),
|
||||
#endif
|
||||
SK_MEMBER(restore, Boolean),
|
||||
SK_MEMBER(scope, Drawable), // thing that scopes animation (unnamed enclosed displayable goes here)
|
||||
SK_MEMBER_PROPERTY(step, Int),
|
||||
SK_MEMBER_PROPERTY(steps, Int),
|
||||
SK_MEMBER_PROPERTY(time, MSec),
|
||||
SK_MEMBER(transition, ApplyTransition)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkApply);
|
||||
|
||||
SkApply::SkApply() : begin(0), dontDraw(false), interval((SkMSec) -1), mode((Mode) -1), /*pickup(false), */
|
||||
restore(false), scope(NULL), steps(-1), transition((Transition) -1), fActive(NULL), /*fCurrentScope(NULL),*/
|
||||
fLastTime(0), fAppended(false), fContainsScope(false), fDeleteScope(false), fEmbedded(false),
|
||||
fEnabled(false), fEnabling(false) {
|
||||
}
|
||||
|
||||
SkApply::~SkApply() {
|
||||
for (SkDrawable** curPtr = fScopes.begin(); curPtr < fScopes.end(); curPtr++)
|
||||
delete *curPtr;
|
||||
if (fDeleteScope)
|
||||
delete scope;
|
||||
// !!! caller must call maker.removeActive(fActive)
|
||||
delete fActive;
|
||||
}
|
||||
|
||||
void SkApply::activate(SkAnimateMaker& maker) {
|
||||
if (fActive != NULL) {
|
||||
if (fActive->fDrawIndex == 0 && fActive->fDrawMax == 0)
|
||||
return; // if only one use, nothing more to do
|
||||
if (restore == false)
|
||||
return; // all share same state, regardless of instance number
|
||||
bool save = fActive->initializeSave();
|
||||
fActive->fixInterpolator(save);
|
||||
} else {
|
||||
fActive = new SkActive(*this, maker);
|
||||
fActive->init();
|
||||
maker.appendActive(fActive);
|
||||
if (restore) {
|
||||
fActive->initializeSave();
|
||||
int animators = fAnimators.count();
|
||||
for (int index = 0; index < animators; index++)
|
||||
fActive->saveInterpolatorValues(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SkApply::append(SkApply* apply) {
|
||||
if (fActive == NULL)
|
||||
return;
|
||||
int oldCount = fActive->fAnimators.count();
|
||||
fActive->append(apply);
|
||||
if (restore) {
|
||||
fActive->appendSave(oldCount);
|
||||
int newCount = fActive->fAnimators.count();
|
||||
for (int index = oldCount; index < newCount; index++)
|
||||
fActive->saveInterpolatorValues(index);
|
||||
}
|
||||
}
|
||||
|
||||
void SkApply::applyValues(int animatorIndex, SkOperand* values, int count,
|
||||
SkDisplayTypes valuesType, SkMSec time)
|
||||
{
|
||||
SkAnimateBase* animator = fActive->fAnimators[animatorIndex];
|
||||
const SkMemberInfo * info = animator->fFieldInfo;
|
||||
SkASSERT(animator);
|
||||
SkASSERT(info != NULL);
|
||||
SkDisplayTypes type = (SkDisplayTypes) info->fType;
|
||||
SkDisplayable* target = getTarget(animator);
|
||||
if (animator->hasExecute() || type == SkType_MemberFunction || type == SkType_MemberProperty) {
|
||||
SkDisplayable* executor = animator->hasExecute() ? animator : target;
|
||||
if (type != SkType_MemberProperty) {
|
||||
SkTDArray<SkScriptValue> typedValues;
|
||||
for (int index = 0; index < count; index++) {
|
||||
SkScriptValue temp;
|
||||
temp.fType = valuesType;
|
||||
temp.fOperand = values[index];
|
||||
*typedValues.append() = temp;
|
||||
}
|
||||
executor->executeFunction(target, info->functionIndex(), typedValues, info->getType(), NULL);
|
||||
} else {
|
||||
SkScriptValue scriptValue;
|
||||
scriptValue.fOperand = values[0];
|
||||
scriptValue.fType = info->getType();
|
||||
target->setProperty(info->propertyIndex(), scriptValue);
|
||||
}
|
||||
} else {
|
||||
SkTypedArray converted;
|
||||
if (type == SkType_ARGB) {
|
||||
if (count == 4) {
|
||||
// !!! assert that it is SkType_Float ?
|
||||
animator->packARGB(&values->fScalar, count, &converted);
|
||||
values = converted.begin();
|
||||
count = converted.count();
|
||||
} else
|
||||
SkASSERT(count == 1);
|
||||
}
|
||||
// SkASSERT(type == SkType_ARGB || type == SkType_String ||info->isSettable());
|
||||
if (type == SkType_String || type == SkType_DynamicString)
|
||||
info->setString(target, values->fString);
|
||||
else if (type == SkType_Drawable || type == SkType_Displayable)
|
||||
target->setReference(info, values->fDisplayable);
|
||||
else
|
||||
info->setValue(target, values, count);
|
||||
}
|
||||
}
|
||||
|
||||
bool SkApply::contains(SkDisplayable* child) {
|
||||
for (SkDrawable** curPtr = fScopes.begin(); curPtr < fScopes.end(); curPtr++) {
|
||||
if (*curPtr == child || (*curPtr)->contains(child))
|
||||
return true;
|
||||
}
|
||||
return fDeleteScope && scope == child;
|
||||
}
|
||||
|
||||
SkDisplayable* SkApply::deepCopy(SkAnimateMaker* maker) {
|
||||
SkDrawable* saveScope = scope;
|
||||
scope = NULL;
|
||||
SkApply* result = (SkApply*) INHERITED::deepCopy(maker);
|
||||
result->scope = scope = saveScope;
|
||||
SkAnimateBase** end = fAnimators.end();
|
||||
for (SkAnimateBase** animPtr = fAnimators.begin(); animPtr < end; animPtr++) {
|
||||
SkAnimateBase* anim = (SkAnimateBase*) (*animPtr)->deepCopy(maker);
|
||||
*result->fAnimators.append() = anim;
|
||||
maker->helperAdd(anim);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void SkApply::disable() {
|
||||
//!!! this is the right thing to do, but has bad side effects because of other problems
|
||||
// currently, if an apply is in a g and scopes a statement in another g, it ends up as members
|
||||
// of both containers. The disabling here incorrectly disables both instances
|
||||
// maybe the fEnabled flag needs to be moved to the fActive data so that both
|
||||
// instances are not affected.
|
||||
// fEnabled = false;
|
||||
}
|
||||
|
||||
bool SkApply::draw(SkAnimateMaker& maker) {
|
||||
if (scope ==NULL)
|
||||
return false;
|
||||
if (scope->isApply() || scope->isDrawable() == false)
|
||||
return false;
|
||||
if (fEnabled == false)
|
||||
enable(maker);
|
||||
SkASSERT(scope);
|
||||
activate(maker);
|
||||
if (mode == kMode_immediate)
|
||||
return fActive->draw();
|
||||
bool result = interpolate(maker, maker.getInTime());
|
||||
if (dontDraw == false) {
|
||||
// if (scope->isDrawable())
|
||||
result |= scope->draw(maker);
|
||||
}
|
||||
if (restore) {
|
||||
for (int index = 0; index < fActive->fAnimators.count(); index++)
|
||||
endSave(index);
|
||||
fActive->advance();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkApply::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
if (dynamicScope.isEmpty() == false)
|
||||
SkDebugf("dynamicScope=\"%s\" ", dynamicScope.c_str());
|
||||
if (dontDraw)
|
||||
SkDebugf("dontDraw=\"true\" ");
|
||||
if (begin != 0) //perhaps we want this no matter what?
|
||||
SkDebugf("begin=\"%g\" ", (float) begin/1000.0f); //is this correct?
|
||||
if (interval != (SkMSec) -1)
|
||||
SkDebugf("interval=\"%g\" ", (float) interval/1000.0f);
|
||||
if (steps != -1)
|
||||
SkDebugf("steps=\"%d\" ", steps);
|
||||
if (restore)
|
||||
SkDebugf("restore=\"true\" ");
|
||||
if (transition == kTransition_reverse)
|
||||
SkDebugf("transition=\"reverse\" ");
|
||||
if (mode == kMode_immediate) {
|
||||
SkDebugf("mode=\"immediate\" ");
|
||||
}
|
||||
else if (mode == kMode_create) {
|
||||
SkDebugf("mode=\"create\" ");
|
||||
}
|
||||
bool closedYet = false;
|
||||
SkDisplayList::fIndent += 4;
|
||||
int save = SkDisplayList::fDumpIndex;
|
||||
if (scope) {
|
||||
if (closedYet == false) {
|
||||
SkDebugf(">\n");
|
||||
closedYet = true;
|
||||
}
|
||||
scope->dump(maker);
|
||||
}
|
||||
int index;
|
||||
// if (fActive) {
|
||||
for (index = 0; index < fAnimators.count(); index++) {
|
||||
if (closedYet == false) {
|
||||
SkDebugf(">\n");
|
||||
closedYet = true;
|
||||
}
|
||||
SkAnimateBase* animator = fAnimators[index];
|
||||
animator->dump(maker);
|
||||
// }
|
||||
}
|
||||
SkDisplayList::fIndent -= 4;
|
||||
SkDisplayList::fDumpIndex = save;
|
||||
if (closedYet)
|
||||
dumpEnd(maker);
|
||||
else
|
||||
SkDebugf("/>\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkApply::enable(SkAnimateMaker& maker) {
|
||||
fEnabled = true;
|
||||
bool initialized = fActive != NULL;
|
||||
if (dynamicScope.size() > 0)
|
||||
enableDynamic(maker);
|
||||
if (maker.fError.hasError())
|
||||
return false;
|
||||
int animators = fAnimators.count();
|
||||
int index;
|
||||
for (index = 0; index < animators; index++) {
|
||||
SkAnimateBase* animator = fAnimators[index];
|
||||
animator->fStart = maker.fEnableTime;
|
||||
animator->fResetPending = animator->fReset;
|
||||
}
|
||||
if (scope && scope->isApply())
|
||||
((SkApply*) scope)->setEmbedded();
|
||||
/* if (mode == kMode_once) {
|
||||
if (scope) {
|
||||
activate(maker);
|
||||
interpolate(maker, maker.fEnableTime);
|
||||
inactivate(maker);
|
||||
}
|
||||
return true;
|
||||
}*/
|
||||
if ((mode == kMode_immediate || mode == kMode_create) && scope == NULL)
|
||||
return false; // !!! error?
|
||||
bool enableMe = scope && (scope->hasEnable() || scope->isApply() || scope->isDrawable() == false);
|
||||
if (mode == kMode_immediate && enableMe || mode == kMode_create)
|
||||
activate(maker); // for non-drawables like post, prime them here
|
||||
if (mode == kMode_immediate && enableMe)
|
||||
fActive->enable();
|
||||
if (mode == kMode_create && scope != NULL) {
|
||||
enableCreate(maker);
|
||||
return true;
|
||||
}
|
||||
if (mode == kMode_immediate) {
|
||||
return scope->isApply() || scope->isDrawable() == false;
|
||||
}
|
||||
refresh(maker);
|
||||
SkDisplayList& displayList = maker.fDisplayList;
|
||||
SkDrawable* drawable;
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
SkString debugOut;
|
||||
SkMSec time = maker.getAppTime();
|
||||
debugOut.appendS32(time - maker.fDebugTimeBase);
|
||||
debugOut.append(" apply enable id=");
|
||||
debugOut.append(_id);
|
||||
debugOut.append("; start=");
|
||||
debugOut.appendS32(maker.fEnableTime - maker.fDebugTimeBase);
|
||||
SkDebugf("%s\n", debugOut.c_str());
|
||||
#endif
|
||||
if (scope == NULL || scope->isApply() || scope->getType() == SkType_Movie || scope->isDrawable() == false) {
|
||||
activate(maker); // for non-drawables like post, prime them here
|
||||
if (initialized) {
|
||||
append(this);
|
||||
}
|
||||
fEnabling = true;
|
||||
interpolate(maker, maker.fEnableTime);
|
||||
fEnabling = false;
|
||||
if (scope != NULL && dontDraw == false)
|
||||
scope->enable(maker);
|
||||
return true;
|
||||
} else if (initialized && restore == false)
|
||||
append(this);
|
||||
#if 0
|
||||
bool wasActive = inactivate(maker); // start fresh
|
||||
if (wasActive) {
|
||||
activate(maker);
|
||||
interpolate(maker, maker.fEnableTime);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
// start here;
|
||||
// now that one apply might embed another, only the parent apply should replace the scope
|
||||
// or get appended to the display list
|
||||
// similarly, an apply added by an add immediate has already been located in the display list
|
||||
// and should not get moved or added again here
|
||||
if (fEmbedded) {
|
||||
return false; // already added to display list by embedder
|
||||
}
|
||||
drawable = (SkDrawable*) scope;
|
||||
SkTDDrawableArray* parentList;
|
||||
SkTDDrawableArray* grandList;
|
||||
SkGroup* parentGroup;
|
||||
SkGroup* thisGroup;
|
||||
int old = displayList.findGroup(drawable, &parentList, &parentGroup, &thisGroup, &grandList);
|
||||
if (old < 0)
|
||||
goto append;
|
||||
else if (fContainsScope) {
|
||||
if ((*parentList)[old] != this || restore == true) {
|
||||
append:
|
||||
if (parentGroup)
|
||||
parentGroup->markCopySize(old);
|
||||
if (parentList->count() < 10000) {
|
||||
fAppended = true;
|
||||
*parentList->append() = this;
|
||||
} else
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kDisplayTreeTooDeep);
|
||||
old = -1;
|
||||
} else
|
||||
reset();
|
||||
} else {
|
||||
SkASSERT(old < parentList->count());
|
||||
if ((*parentList)[old]->isApply()) {
|
||||
SkApply* apply = (SkApply*) (*parentList)[old];
|
||||
if (apply != this && apply->fActive == NULL)
|
||||
apply->activate(maker);
|
||||
apply->append(this);
|
||||
parentGroup = NULL;
|
||||
} else {
|
||||
if (parentGroup)
|
||||
parentGroup->markCopySize(old);
|
||||
SkDrawable** newApplyLocation = &(*parentList)[old];
|
||||
SkGroup* pGroup;
|
||||
int oldApply = displayList.findGroup(this, &parentList, &pGroup, &thisGroup, &grandList);
|
||||
if (oldApply >= 0) {
|
||||
(*parentList)[oldApply] = (SkDrawable*) SkDisplayType::CreateInstance(&maker, SkType_Apply);
|
||||
parentGroup = NULL;
|
||||
fDeleteScope = true;
|
||||
}
|
||||
*newApplyLocation = this;
|
||||
}
|
||||
}
|
||||
if (parentGroup) {
|
||||
parentGroup->markCopySet(old);
|
||||
fDeleteScope = dynamicScope.size() == 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkApply::enableCreate(SkAnimateMaker& maker) {
|
||||
SkString newID;
|
||||
for (int step = 0; step <= steps; step++) {
|
||||
fLastTime = step * SK_MSec1;
|
||||
bool success = maker.computeID(scope, this, &newID);
|
||||
if (success == false)
|
||||
return;
|
||||
if (maker.find(newID.c_str(), NULL))
|
||||
continue;
|
||||
SkApply* copy = (SkApply*) deepCopy(&maker); // work on copy of animator state
|
||||
if (mode == kMode_create)
|
||||
copy->mode = (Mode) -1;
|
||||
SkDrawable* copyScope = copy->scope = (SkDrawable*) scope->deepCopy(&maker);
|
||||
*fScopes.append() = copyScope;
|
||||
if (copyScope->resolveIDs(maker, scope, this)) {
|
||||
step = steps; // quit
|
||||
goto next; // resolveIDs failed
|
||||
}
|
||||
if (newID.size() > 0)
|
||||
maker.setID(copyScope, newID);
|
||||
if (copy->resolveIDs(maker, this, this)) { // fix up all fields, including target
|
||||
step = steps; // quit
|
||||
goto next; // resolveIDs failed
|
||||
}
|
||||
copy->activate(maker);
|
||||
copy->interpolate(maker, step * SK_MSec1);
|
||||
maker.removeActive(copy->fActive);
|
||||
next:
|
||||
delete copy;
|
||||
}
|
||||
}
|
||||
|
||||
void SkApply::enableDynamic(SkAnimateMaker& maker) {
|
||||
SkASSERT(mode != kMode_create); // create + dynamic are not currently compatible
|
||||
SkDisplayable* newScope;
|
||||
bool success = SkAnimatorScript::EvaluateDisplayable(maker, this, dynamicScope.c_str(),
|
||||
&newScope);
|
||||
if (success && scope != newScope) {
|
||||
SkTDDrawableArray* pList, * gList;
|
||||
SkGroup* pGroup = NULL, * found = NULL;
|
||||
int old = maker.fDisplayList.findGroup(scope, &pList, &pGroup, &found, &gList);
|
||||
if (pList && old >= 0 && (*pList)[old]->isApply() && (*pList)[old] != this) {
|
||||
if (fAppended == false) {
|
||||
if (found != NULL) {
|
||||
SkDisplayable* oldChild = (*pList)[old];
|
||||
if (oldChild->isApply() && found->copySet(old)) {
|
||||
found->markCopyClear(old);
|
||||
// delete oldChild;
|
||||
}
|
||||
}
|
||||
(*pList)[old] = scope;
|
||||
} else
|
||||
pList->remove(old);
|
||||
}
|
||||
scope = (SkDrawable*) newScope;
|
||||
onEndElement(maker);
|
||||
}
|
||||
maker.removeActive(fActive);
|
||||
delete fActive;
|
||||
fActive = NULL;
|
||||
}
|
||||
|
||||
void SkApply::endSave(int index) {
|
||||
SkAnimateBase* animate = fActive->fAnimators[index];
|
||||
const SkMemberInfo* info = animate->fFieldInfo;
|
||||
SkDisplayTypes type = (SkDisplayTypes) info->fType;
|
||||
if (type == SkType_MemberFunction)
|
||||
return;
|
||||
SkDisplayable* target = getTarget(animate);
|
||||
size_t size = info->getSize(target);
|
||||
int count = (int) (size / sizeof(SkScalar));
|
||||
int activeIndex = fActive->fDrawIndex + index;
|
||||
SkOperand* last = new SkOperand[count];
|
||||
SkAutoTDelete<SkOperand> autoLast(last);
|
||||
if (type != SkType_MemberProperty) {
|
||||
info->getValue(target, last, count);
|
||||
SkOperand* saveOperand = fActive->fSaveRestore[activeIndex];
|
||||
if (saveOperand)
|
||||
info->setValue(target, fActive->fSaveRestore[activeIndex], count);
|
||||
} else {
|
||||
SkScriptValue scriptValue;
|
||||
bool success = target->getProperty(info->propertyIndex(), &scriptValue);
|
||||
SkASSERT(success = true);
|
||||
last[0] = scriptValue.fOperand;
|
||||
scriptValue.fOperand = fActive->fSaveRestore[activeIndex][0];
|
||||
target->setProperty(info->propertyIndex(), scriptValue);
|
||||
}
|
||||
SkOperand* save = fActive->fSaveRestore[activeIndex];
|
||||
if (save)
|
||||
memcpy(save, last, count * sizeof(SkOperand));
|
||||
}
|
||||
|
||||
bool SkApply::getProperty(int index, SkScriptValue* value) const {
|
||||
switch (index) {
|
||||
case SK_PROPERTY(step):
|
||||
value->fType = SkType_Int;
|
||||
value->fOperand.fS32 = fLastTime / SK_MSec1;
|
||||
break;
|
||||
case SK_PROPERTY(steps):
|
||||
value->fType = SkType_Int;
|
||||
value->fOperand.fS32 = steps;
|
||||
break;
|
||||
case SK_PROPERTY(time):
|
||||
value->fType = SkType_MSec;
|
||||
value->fOperand.fS32 = fLastTime;
|
||||
break;
|
||||
default:
|
||||
// SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkApply::getStep(SkScriptValue* value) {
|
||||
getProperty(SK_PROPERTY(step), value);
|
||||
}
|
||||
|
||||
SkDrawable* SkApply::getTarget(SkAnimateBase* animate) {
|
||||
if (animate->fTargetIsScope == false || mode != kMode_create)
|
||||
return animate->fTarget;
|
||||
return scope;
|
||||
}
|
||||
|
||||
bool SkApply::hasDelayedAnimator() const {
|
||||
SkAnimateBase** animEnd = fAnimators.end();
|
||||
for (SkAnimateBase** animPtr = fAnimators.begin(); animPtr < animEnd; animPtr++) {
|
||||
SkAnimateBase* animator = *animPtr;
|
||||
if (animator->fDelayed)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkApply::hasEnable() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkApply::inactivate(SkAnimateMaker& maker) {
|
||||
if (fActive == NULL)
|
||||
return false;
|
||||
maker.removeActive(fActive);
|
||||
delete fActive;
|
||||
fActive = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
SkMSec lastTime = (SkMSec) -1;
|
||||
#endif
|
||||
|
||||
bool SkApply::interpolate(SkAnimateMaker& maker, SkMSec rawTime) {
|
||||
if (fActive == NULL)
|
||||
return false;
|
||||
bool result = false;
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
SkMSec time = maker.getAppTime();
|
||||
if (lastTime == (SkMSec) -1)
|
||||
lastTime = rawTime - 1;
|
||||
if (fActive != NULL &&
|
||||
strcmp(id, "a3") == 0 && rawTime > lastTime) {
|
||||
lastTime += 1000;
|
||||
SkString debugOut;
|
||||
debugOut.appendS32(time - maker.fDebugTimeBase);
|
||||
debugOut.append(" apply id=");
|
||||
debugOut.append(_id);
|
||||
debugOut.append("; ");
|
||||
debugOut.append(fActive->fAnimators[0]->_id);
|
||||
debugOut.append("=");
|
||||
debugOut.appendS32(rawTime - fActive->fState[0].fStartTime);
|
||||
debugOut.append(")");
|
||||
SkDebugf("%s\n", debugOut.c_str());
|
||||
}
|
||||
#endif
|
||||
fActive->start();
|
||||
if (restore)
|
||||
fActive->initializeSave();
|
||||
int animators = fActive->fAnimators.count();
|
||||
for (int inner = 0; inner < animators; inner++) {
|
||||
SkAnimateBase* animate = fActive->fAnimators[inner];
|
||||
if (animate->fChanged) {
|
||||
animate->fChanged = false;
|
||||
animate->fStart = rawTime;
|
||||
// SkTypedArray values;
|
||||
// int count = animate->fValues.count();
|
||||
// values.setCount(count);
|
||||
// memcpy(values.begin(), animate->fValues.begin(), sizeof(SkOperand) * count);
|
||||
animate->onEndElement(maker);
|
||||
// if (memcmp(values.begin(), animate->fValues.begin(), sizeof(SkOperand) * count) != 0) {
|
||||
fActive->append(this);
|
||||
fActive->start();
|
||||
// }
|
||||
}
|
||||
SkMSec time = fActive->getTime(rawTime, inner);
|
||||
SkActive::SkState& state = fActive->fState[inner];
|
||||
if (SkMSec_LT(rawTime, state.fStartTime)) {
|
||||
if (fEnabling) {
|
||||
animate->fDelayed = true;
|
||||
maker.delayEnable(this, state.fStartTime);
|
||||
}
|
||||
continue;
|
||||
} else
|
||||
animate->fDelayed = false;
|
||||
SkMSec innerTime = fLastTime = state.getRelativeTime(time);
|
||||
if (restore)
|
||||
fActive->restoreInterpolatorValues(inner);
|
||||
if (animate->fReset) {
|
||||
if (transition != SkApply::kTransition_reverse) {
|
||||
if (SkMSec_LT(state.fBegin + state.fDuration, innerTime)) {
|
||||
if (animate->fResetPending) {
|
||||
innerTime = 0;
|
||||
animate->fResetPending = false;
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
} else if (innerTime == 0) {
|
||||
if (animate->fResetPending) {
|
||||
innerTime = state.fBegin + state.fDuration;
|
||||
animate->fResetPending = false;
|
||||
} else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
int count = animate->components();
|
||||
SkAutoSTMalloc<16, SkOperand> values(count);
|
||||
SkInterpolatorBase::Result interpResult = fActive->fInterpolators[inner]->timeToValues(
|
||||
innerTime, values.get());
|
||||
result |= (interpResult != SkInterpolatorBase::kFreezeEnd_Result);
|
||||
if ((transition != SkApply::kTransition_reverse && interpResult == SkInterpolatorBase::kFreezeEnd_Result ||
|
||||
transition == SkApply::kTransition_reverse && fLastTime == 0) && state.fUnpostedEndEvent) {
|
||||
// SkDEBUGF(("interpolate: post on end\n"));
|
||||
state.fUnpostedEndEvent = false;
|
||||
maker.postOnEnd(animate, state.fBegin + state.fDuration);
|
||||
maker.fAdjustedStart = 0; // !!! left over from synchronizing animation days, undoubtably out of date (and broken)
|
||||
}
|
||||
if (animate->formula.size() > 0) {
|
||||
if (fLastTime > animate->dur)
|
||||
fLastTime = animate->dur;
|
||||
SkTypedArray formulaValues;
|
||||
formulaValues.setCount(count);
|
||||
bool success = animate->fFieldInfo->setValue(maker, &formulaValues, 0, 0, NULL,
|
||||
animate->getValuesType(), animate->formula);
|
||||
SkASSERT(success);
|
||||
if (restore)
|
||||
save(inner); // save existing value
|
||||
applyValues(inner, formulaValues.begin(), count, animate->getValuesType(), innerTime);
|
||||
} else {
|
||||
if (restore)
|
||||
save(inner); // save existing value
|
||||
applyValues(inner, values.get(), count, animate->getValuesType(), innerTime);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void SkApply::initialize() {
|
||||
if (scope == NULL)
|
||||
return;
|
||||
if (scope->isApply() || scope->isDrawable() == false)
|
||||
return;
|
||||
scope->initialize();
|
||||
}
|
||||
|
||||
void SkApply::onEndElement(SkAnimateMaker& maker)
|
||||
{
|
||||
SkDrawable* scopePtr = scope;
|
||||
while (scopePtr && scopePtr->isApply()) {
|
||||
SkApply* scopedApply = (SkApply*) scopePtr;
|
||||
if (scopedApply->scope == this) {
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kApplyScopesItself);
|
||||
return;
|
||||
}
|
||||
scopePtr = scopedApply->scope;
|
||||
}
|
||||
if (mode == kMode_create)
|
||||
return;
|
||||
if (scope != NULL && steps >= 0 && scope->isApply() == false && scope->isDrawable())
|
||||
scope->setSteps(steps);
|
||||
for (SkAnimateBase** animPtr = fAnimators.begin(); animPtr < fAnimators.end(); animPtr++) {
|
||||
SkAnimateBase* anim = *animPtr;
|
||||
//for reusing apply statements with dynamic scope
|
||||
if (anim->fTarget == NULL || anim->fTargetIsScope) {
|
||||
anim->fTargetIsScope = true;
|
||||
if (scope)
|
||||
anim->fTarget = scope;
|
||||
else
|
||||
anim->setTarget(maker);
|
||||
anim->onEndElement(maker); // allows animate->fFieldInfo to be set
|
||||
}
|
||||
if (scope != NULL && steps >= 0 && anim->fTarget != scope && anim->fTarget->isDrawable())
|
||||
anim->fTarget->setSteps(steps);
|
||||
}
|
||||
}
|
||||
|
||||
const SkMemberInfo* SkApply::preferredChild(SkDisplayTypes type) {
|
||||
SkASSERT(SkDisplayType::IsAnimate(type) == false);
|
||||
fContainsScope = true;
|
||||
return getMember("scope"); // !!! cwap! need to refer to member through enum like kScope instead
|
||||
}
|
||||
|
||||
void SkApply::refresh(SkAnimateMaker& maker) {
|
||||
for (SkAnimateBase** animPtr = fAnimators.begin(); animPtr < fAnimators.end(); animPtr++) {
|
||||
SkAnimateBase* animate = *animPtr;
|
||||
animate->onEndElement(maker);
|
||||
}
|
||||
if (fActive)
|
||||
fActive->resetInterpolators();
|
||||
}
|
||||
|
||||
void SkApply::reset() {
|
||||
if (fActive)
|
||||
fActive->resetState();
|
||||
}
|
||||
|
||||
bool SkApply::resolveIDs(SkAnimateMaker& maker, SkDisplayable* original, SkApply* apply) { // replace to/formula strings in animators of the form xxx.step with the step value, if xxx.step is in scope
|
||||
if (resolveField(maker, apply, &dynamicScope) == false)
|
||||
return true; // failed
|
||||
SkAnimateBase** endPtr = fAnimators.end();
|
||||
SkAnimateBase** origPtr = ((SkApply*) original)->fAnimators.begin();
|
||||
for (SkAnimateBase** animPtr = fAnimators.begin(); animPtr < endPtr; ) {
|
||||
SkAnimateBase* animator = *animPtr++;
|
||||
maker.resolveID(animator, *origPtr++);
|
||||
if (resolveField(maker, this, &animator->target) == false)
|
||||
return true;
|
||||
if (resolveField(maker, this, &animator->from) == false)
|
||||
return true;
|
||||
if (resolveField(maker, this, &animator->to) == false)
|
||||
return true;
|
||||
if (resolveField(maker, this, &animator->formula) == false)
|
||||
return true;
|
||||
}
|
||||
// setEmbedded();
|
||||
onEndElement(maker);
|
||||
return false; // succeeded
|
||||
}
|
||||
|
||||
bool SkApply::resolveField(SkAnimateMaker& maker, SkDisplayable* parent, SkString* str) {
|
||||
const char* script = str->c_str();
|
||||
if (str->startsWith("#string:") == false)
|
||||
return true;
|
||||
script += sizeof("#string:") - 1;
|
||||
return SkAnimatorScript::EvaluateString(maker, this, parent, script, str);
|
||||
}
|
||||
|
||||
void SkApply::save(int index) {
|
||||
SkAnimateBase* animate = fActive->fAnimators[index];
|
||||
const SkMemberInfo * info = animate->fFieldInfo;
|
||||
SkDisplayable* target = getTarget(animate);
|
||||
// if (animate->hasExecute())
|
||||
// info = animate->getResolvedInfo();
|
||||
SkDisplayTypes type = (SkDisplayTypes) info->fType;
|
||||
if (type == SkType_MemberFunction)
|
||||
return; // nothing to save
|
||||
size_t size = info->getSize(target);
|
||||
int count = (int) (size / sizeof(SkScalar));
|
||||
bool useLast = true;
|
||||
// !!! this all may be unneeded, at least in the dynamic case ??
|
||||
int activeIndex = fActive->fDrawIndex + index;
|
||||
SkTDOperandArray last;
|
||||
if (fActive->fSaveRestore[activeIndex] == NULL) {
|
||||
fActive->fSaveRestore[activeIndex] = new SkOperand[count];
|
||||
useLast = false;
|
||||
} else {
|
||||
last.setCount(count);
|
||||
memcpy(last.begin(), fActive->fSaveRestore[activeIndex], count * sizeof(SkOperand));
|
||||
}
|
||||
if (type != SkType_MemberProperty) {
|
||||
info->getValue(target, fActive->fSaveRestore[activeIndex], count);
|
||||
if (useLast)
|
||||
info->setValue(target, last.begin(), count);
|
||||
} else {
|
||||
SkScriptValue scriptValue;
|
||||
bool success = target->getProperty(info->propertyIndex(), &scriptValue);
|
||||
SkASSERT(success == true);
|
||||
SkASSERT(scriptValue.fType == SkType_Float);
|
||||
fActive->fSaveRestore[activeIndex][0] = scriptValue.fOperand;
|
||||
if (useLast) {
|
||||
SkScriptValue scriptValue;
|
||||
scriptValue.fType = type;
|
||||
scriptValue.fOperand = last[0];
|
||||
target->setProperty(info->propertyIndex(), scriptValue);
|
||||
}
|
||||
}
|
||||
// !!! end of unneeded
|
||||
}
|
||||
|
||||
bool SkApply::setProperty(int index, SkScriptValue& scriptValue) {
|
||||
switch (index) {
|
||||
case SK_PROPERTY(animator): {
|
||||
SkAnimateBase* animate = (SkAnimateBase*) scriptValue.fOperand.fDisplayable;
|
||||
SkASSERT(animate->isAnimate());
|
||||
*fAnimators.append() = animate;
|
||||
return true;
|
||||
}
|
||||
case SK_PROPERTY(steps):
|
||||
steps = scriptValue.fOperand.fS32;
|
||||
if (fActive)
|
||||
fActive->setSteps(steps);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkApply::setSteps(int _steps) {
|
||||
steps = _steps;
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void SkApply::validate() {
|
||||
if (fActive)
|
||||
fActive->validate();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/* libs/graphics/animator/SkDisplayApply.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayApply_DEFINED
|
||||
#define SkDisplayApply_DEFINED
|
||||
|
||||
#include "SkAnimateBase.h"
|
||||
#include "SkDrawable.h"
|
||||
#include "SkIntArray.h"
|
||||
|
||||
class SkActive;
|
||||
|
||||
class SkApply : public SkDrawable {
|
||||
DECLARE_MEMBER_INFO(Apply);
|
||||
public:
|
||||
|
||||
SkApply();
|
||||
virtual ~SkApply();
|
||||
|
||||
enum Transition {
|
||||
kTransition_normal,
|
||||
kTransition_reverse
|
||||
};
|
||||
|
||||
enum Mode {
|
||||
kMode_create,
|
||||
kMode_immediate,
|
||||
//kMode_once
|
||||
};
|
||||
void activate(SkAnimateMaker& );
|
||||
void append(SkApply* apply);
|
||||
void appendActive(SkActive* );
|
||||
void applyValues(int animatorIndex, SkOperand* values, int count,
|
||||
SkDisplayTypes , SkMSec time);
|
||||
virtual bool contains(SkDisplayable*);
|
||||
// void createActive(SkAnimateMaker& );
|
||||
virtual SkDisplayable* deepCopy(SkAnimateMaker* );
|
||||
void disable();
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
virtual bool enable(SkAnimateMaker& );
|
||||
void enableCreate(SkAnimateMaker& );
|
||||
void enableDynamic(SkAnimateMaker& );
|
||||
void endSave(int index);
|
||||
Mode getMode() { return mode; }
|
||||
virtual bool getProperty(int index, SkScriptValue* value) const;
|
||||
SkDrawable* getScope() { return scope; }
|
||||
void getStep(SkScriptValue* );
|
||||
SkDrawable* getTarget(SkAnimateBase* );
|
||||
bool hasDelayedAnimator() const;
|
||||
virtual bool hasEnable() const;
|
||||
bool inactivate(SkAnimateMaker& maker);
|
||||
virtual void initialize();
|
||||
bool interpolate(SkAnimateMaker& , SkMSec time);
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
virtual const SkMemberInfo* preferredChild(SkDisplayTypes type);
|
||||
void refresh(SkAnimateMaker& );
|
||||
void reset();
|
||||
virtual bool resolveIDs(SkAnimateMaker& maker, SkDisplayable* original, SkApply* );
|
||||
bool resolveField(SkAnimateMaker& , SkDisplayable* parent, SkString* str);
|
||||
void save(int index);
|
||||
void setEmbedded() { fEmbedded = true; }
|
||||
virtual bool setProperty(int index, SkScriptValue& );
|
||||
virtual void setSteps(int _steps);
|
||||
// virtual void setTime(SkMSec time);
|
||||
#ifdef SK_DEBUG
|
||||
virtual void validate();
|
||||
#endif
|
||||
private:
|
||||
SkMSec begin;
|
||||
SkBool dontDraw;
|
||||
SkString dynamicScope;
|
||||
SkMSec interval;
|
||||
Mode mode;
|
||||
#if 0
|
||||
SkBool pickup;
|
||||
#endif
|
||||
SkBool restore;
|
||||
SkDrawable* scope;
|
||||
int32_t steps;
|
||||
Transition transition;
|
||||
SkActive* fActive;
|
||||
SkTDAnimateArray fAnimators;
|
||||
// SkDrawable* fCurrentScope;
|
||||
SkMSec fLastTime; // used only to return script property time
|
||||
SkTDDrawableArray fScopes;
|
||||
SkBool fAppended : 1;
|
||||
SkBool fContainsScope : 1;
|
||||
SkBool fDeleteScope : 1;
|
||||
SkBool fEmbedded : 1;
|
||||
SkBool fEnabled : 1;
|
||||
SkBool fEnabling : 1; // set if calling interpolate from enable
|
||||
friend class SkActive;
|
||||
friend class SkDisplayList;
|
||||
typedef SkDrawable INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDisplayApply_DEFINED
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/* libs/graphics/animator/SkDisplayBounds.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayBounds.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDisplayBounds::fInfo[] = {
|
||||
SK_MEMBER_INHERITED,
|
||||
SK_MEMBER(inval, Boolean)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDisplayBounds);
|
||||
|
||||
SkDisplayBounds::SkDisplayBounds() : inval(false) {
|
||||
}
|
||||
|
||||
bool SkDisplayBounds::draw(SkAnimateMaker& maker) {
|
||||
maker.fDisplayList.fUnionBounds = SkToBool(inval);
|
||||
maker.fDisplayList.fDrawBounds = false;
|
||||
fBounds.setEmpty();
|
||||
bool result = INHERITED::draw(maker);
|
||||
maker.fDisplayList.fUnionBounds = false;
|
||||
maker.fDisplayList.fDrawBounds = true;
|
||||
if (inval && fBounds.isEmpty() == false) {
|
||||
SkIRect& rect = maker.fDisplayList.fInvalBounds;
|
||||
maker.fDisplayList.fHasUnion = true;
|
||||
if (rect.isEmpty())
|
||||
rect = fBounds;
|
||||
else
|
||||
rect.join(fBounds);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/* libs/graphics/animator/SkDisplayBounds.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayBounds_DEFINED
|
||||
#define SkDisplayBounds_DEFINED
|
||||
|
||||
#include "SkDrawRectangle.h"
|
||||
|
||||
class SkDisplayBounds : public SkDrawRect {
|
||||
DECLARE_DISPLAY_MEMBER_INFO(Bounds);
|
||||
SkDisplayBounds();
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
private:
|
||||
SkBool inval;
|
||||
typedef SkDrawRect INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDisplayBounds_DEFINED
|
||||
|
||||
@@ -0,0 +1,339 @@
|
||||
/* libs/graphics/animator/SkDisplayEvent.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayEvent.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkDisplayInput.h"
|
||||
#include "SkDisplayList.h"
|
||||
#ifdef SK_DEBUG
|
||||
#include "SkDump.h"
|
||||
#endif
|
||||
#include "SkEvent.h"
|
||||
#include "SkDisplayInput.h"
|
||||
#include "SkKey.h"
|
||||
#include "SkMetaData.h"
|
||||
#include "SkScript.h"
|
||||
#include "SkUtils.h"
|
||||
|
||||
enum SkDisplayEvent_Properties {
|
||||
SK_PROPERTY(key),
|
||||
SK_PROPERTY(keys)
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDisplayEvent::fInfo[] = {
|
||||
SK_MEMBER(code, EventCode),
|
||||
SK_MEMBER(disable, Boolean),
|
||||
SK_MEMBER_PROPERTY(key, String), // a single key (also last key pressed)
|
||||
SK_MEMBER_PROPERTY(keys, String), // a single key or dash-delimited range of keys
|
||||
SK_MEMBER(kind, EventKind),
|
||||
SK_MEMBER(target, String),
|
||||
SK_MEMBER(x, Float),
|
||||
SK_MEMBER(y, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDisplayEvent);
|
||||
|
||||
SkDisplayEvent::SkDisplayEvent() : code((SkKey) -1), disable(false),
|
||||
kind(kUser), x(0), y(0), fLastCode((SkKey) -1), fMax((SkKey) -1), fTarget(NULL) {
|
||||
}
|
||||
|
||||
SkDisplayEvent::~SkDisplayEvent() {
|
||||
deleteMembers();
|
||||
}
|
||||
|
||||
bool SkDisplayEvent::add(SkAnimateMaker& , SkDisplayable* child) {
|
||||
*fChildren.append() = child;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkDisplayEvent::contains(SkDisplayable* match) {
|
||||
for (int index = 0; index < fChildren.count(); index++) {
|
||||
if (fChildren[index] == match || fChildren[index]->contains(match))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SkDisplayable* SkDisplayEvent::contains(const SkString& match) {
|
||||
for (int index = 0; index < fChildren.count(); index++) {
|
||||
SkDisplayable* child = fChildren[index];
|
||||
if (child->contains(match))
|
||||
return child;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void SkDisplayEvent::deleteMembers() {
|
||||
for (int index = 0; index < fChildren.count(); index++) {
|
||||
SkDisplayable* evt = fChildren[index];
|
||||
delete evt;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkDisplayEvent::dumpEvent(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
SkString str;
|
||||
SkDump::GetEnumString(SkType_EventKind, kind, &str);
|
||||
SkDebugf("kind=\"%s\" ", str.c_str());
|
||||
if (kind == SkDisplayEvent::kKeyPress || kind == SkDisplayEvent::kKeyPressUp) {
|
||||
if (code >= 0)
|
||||
SkDump::GetEnumString(SkType_EventCode, code, &str);
|
||||
else
|
||||
str.set("none");
|
||||
SkDebugf("code=\"%s\" ", str.c_str());
|
||||
}
|
||||
if (kind == SkDisplayEvent::kKeyChar) {
|
||||
if (fMax != (SkKey) -1 && fMax != code)
|
||||
SkDebugf("keys=\"%c - %c\" ", code, fMax);
|
||||
else
|
||||
SkDebugf("key=\"%c\" ", code);
|
||||
}
|
||||
if (fTarget != NULL) {
|
||||
SkDebugf("target=\"%s\" ", fTarget->id);
|
||||
}
|
||||
if (kind >= SkDisplayEvent::kMouseDown && kind <= SkDisplayEvent::kMouseUp) {
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf("x=\"%g\" y=\"%g\" ", SkScalarToFloat(x), SkScalarToFloat(y));
|
||||
#else
|
||||
SkDebugf("x=\"%x\" y=\"%x\" ", x, y);
|
||||
#endif
|
||||
}
|
||||
if (disable)
|
||||
SkDebugf("disable=\"true\" ");
|
||||
SkDebugf("/>\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkDisplayEvent::enableEvent(SkAnimateMaker& maker)
|
||||
{
|
||||
maker.fActiveEvent = this;
|
||||
if (fChildren.count() == 0)
|
||||
return false;
|
||||
if (disable)
|
||||
return false;
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
if (maker.fDumpEvents) {
|
||||
SkDebugf("enable: ");
|
||||
dumpEvent(&maker);
|
||||
}
|
||||
#endif
|
||||
SkDisplayList& displayList = maker.fDisplayList;
|
||||
for (int index = 0; index < fChildren.count(); index++) {
|
||||
SkDisplayable* displayable = fChildren[index];
|
||||
if (displayable->isGroup()) {
|
||||
SkTDDrawableArray* parentList = displayList.getDrawList();
|
||||
*parentList->append() = (SkDrawable*) displayable; // make it findable before children are enabled
|
||||
}
|
||||
if (displayable->enable(maker))
|
||||
continue;
|
||||
if (maker.hasError())
|
||||
return true;
|
||||
if (displayable->isDrawable() == false)
|
||||
return true; // error
|
||||
SkDrawable* drawable = (SkDrawable*) displayable;
|
||||
SkTDDrawableArray* parentList = displayList.getDrawList();
|
||||
*parentList->append() = drawable;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDisplayEvent::getProperty(int index, SkScriptValue* value) const {
|
||||
switch (index) {
|
||||
case SK_PROPERTY(key):
|
||||
case SK_PROPERTY(keys): {
|
||||
value->fType = SkType_String;
|
||||
char scratch[8];
|
||||
SkKey convert = index == SK_PROPERTY(keys) ? code : fLastCode;
|
||||
size_t size = convert > 0 ? SkUTF8_FromUnichar(convert, scratch) : 0;
|
||||
fKeyString.set(scratch, size);
|
||||
value->fOperand.fString = &fKeyString;
|
||||
if (index != SK_PROPERTY(keys) || fMax == (SkKey) -1 || fMax == code)
|
||||
break;
|
||||
value->fOperand.fString->append("-");
|
||||
size = SkUTF8_FromUnichar(fMax, scratch);
|
||||
value->fOperand.fString->append(scratch, size);
|
||||
} break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkDisplayEvent::onEndElement(SkAnimateMaker& maker)
|
||||
{
|
||||
if (kind == kUser)
|
||||
return;
|
||||
maker.fEvents.addEvent(this);
|
||||
if (kind == kOnEnd) {
|
||||
bool found = maker.find(target.c_str(), &fTarget);
|
||||
SkASSERT(found);
|
||||
SkASSERT(fTarget && fTarget->isAnimate());
|
||||
SkAnimateBase* animate = (SkAnimateBase*) fTarget;
|
||||
animate->setHasEndEvent();
|
||||
}
|
||||
}
|
||||
|
||||
void SkDisplayEvent::populateInput(SkAnimateMaker& maker, const SkEvent& fEvent) {
|
||||
const SkMetaData& meta = fEvent.getMetaData();
|
||||
SkMetaData::Iter iter(meta);
|
||||
SkMetaData::Type type;
|
||||
int number;
|
||||
const char* name;
|
||||
while ((name = iter.next(&type, &number)) != NULL) {
|
||||
if (name[0] == '\0')
|
||||
continue;
|
||||
SkDisplayable* displayable;
|
||||
SkInput* input;
|
||||
for (int index = 0; index < fChildren.count(); index++) {
|
||||
displayable = fChildren[index];
|
||||
if (displayable->getType() != SkType_Input)
|
||||
continue;
|
||||
input = (SkInput*) displayable;
|
||||
if (input->name.equals(name))
|
||||
goto found;
|
||||
}
|
||||
if (!maker.find(name, &displayable) || displayable->getType() != SkType_Input)
|
||||
continue;
|
||||
input = (SkInput*) displayable;
|
||||
found:
|
||||
switch (type) {
|
||||
case SkMetaData::kS32_Type:
|
||||
meta.findS32(name, &input->fInt);
|
||||
break;
|
||||
case SkMetaData::kScalar_Type:
|
||||
meta.findScalar(name, &input->fFloat);
|
||||
break;
|
||||
case SkMetaData::kPtr_Type:
|
||||
SkASSERT(0);
|
||||
break; // !!! not handled for now
|
||||
case SkMetaData::kString_Type:
|
||||
input->string.set(meta.findString(name));
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
}
|
||||
}
|
||||
// re-evaluate all animators that may have built their values from input strings
|
||||
for (SkDisplayable** childPtr = fChildren.begin(); childPtr < fChildren.end(); childPtr++) {
|
||||
SkDisplayable* displayable = *childPtr;
|
||||
if (displayable->isApply() == false)
|
||||
continue;
|
||||
SkApply* apply = (SkApply*) displayable;
|
||||
apply->refresh(maker);
|
||||
}
|
||||
}
|
||||
|
||||
bool SkDisplayEvent::setProperty(int index, SkScriptValue& value) {
|
||||
SkASSERT(index == SK_PROPERTY(key) || index == SK_PROPERTY(keys));
|
||||
SkASSERT(value.fType == SkType_String);
|
||||
SkString* string = value.fOperand.fString;
|
||||
const char* chars = string->c_str();
|
||||
int count = SkUTF8_CountUnichars(chars);
|
||||
SkASSERT(count >= 1);
|
||||
code = (SkKey) SkUTF8_NextUnichar(&chars);
|
||||
fMax = code;
|
||||
SkASSERT(count == 1 || index == SK_PROPERTY(keys));
|
||||
if (--count > 0) {
|
||||
SkASSERT(*chars == '-');
|
||||
chars++;
|
||||
fMax = (SkKey) SkUTF8_NextUnichar(&chars);
|
||||
SkASSERT(fMax >= code);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
|
||||
#include "SkMetaData.h"
|
||||
#include "SkParse.h"
|
||||
#include "SkTextBox.h"
|
||||
#include "SkXMLWriter.h"
|
||||
|
||||
void SkMetaData::setPtr(char const*, void* ) {}
|
||||
void SkMetaData::setS32(char const*, int ) {}
|
||||
bool SkEventSink::doEvent(SkEvent const& ) { return false; }
|
||||
bool SkXMLParser::parse(SkStream& ) { return false; }
|
||||
SkXMLParserError::SkXMLParserError( ) {}
|
||||
void SkEvent::setType(char const*, unsigned long ) {}
|
||||
bool SkEvent::PostTime(SkEvent*, unsigned int, unsigned int ) { return false; }
|
||||
SkEvent::SkEvent(char const* ) {}
|
||||
SkEvent::SkEvent(SkEvent const& ) {}
|
||||
SkEvent::SkEvent( ) {}
|
||||
SkEvent::~SkEvent( ) {}
|
||||
bool SkEventSink::onQuery(SkEvent* ) { return false; }
|
||||
SkEventSink::SkEventSink( ) {}
|
||||
SkEventSink::~SkEventSink( ) {}
|
||||
bool SkXMLParser::parse(char const*, unsigned long ) { return false; }
|
||||
bool SkXMLParser::parse(SkDOM const&, SkDOMNode const* ) { return false; }
|
||||
bool SkEvent::Post(SkEvent*, unsigned int, unsigned int ) { return false; }
|
||||
void SkParse::UnitTest( ) {}
|
||||
const char* SkMetaData::findString(char const*) const {return 0;}
|
||||
bool SkMetaData::findPtr(char const*, void**) const {return false;}
|
||||
bool SkMetaData::findS32(char const*, int*) const {return false;}
|
||||
bool SkEvent::isType(char const*, unsigned long) const { return false; }
|
||||
void SkMetaData::setString(char const*, char const* ) {}
|
||||
const char* SkParse::FindNamedColor(char const*, unsigned long, unsigned int* ) {return false; }
|
||||
const char* SkMetaData::Iter::next(SkMetaData::Type*, int* ) { return false; }
|
||||
SkMetaData::Iter::Iter(SkMetaData const& ) {}
|
||||
bool SkMetaData::findScalar(char const*, int*) const {return false;}
|
||||
void SkMetaData::reset( ) {}
|
||||
void SkEvent::setType(SkString const& ) {}
|
||||
bool SkMetaData::findBool(char const*, bool*) const {return false;}
|
||||
void SkEvent::getType(SkString*) const {}
|
||||
bool SkXMLParser::endElement(char const* ) { return false; }
|
||||
bool SkXMLParser::addAttribute(char const*, char const* ) { return false;}
|
||||
bool SkXMLParser::startElement(char const* ) { return false;}
|
||||
bool SkXMLParser::text(char const*, int ) { return false;}
|
||||
bool SkXMLParser::onText(char const*, int ) { return false;}
|
||||
SkXMLParser::SkXMLParser(SkXMLParserError* ) {}
|
||||
SkXMLParser::~SkXMLParser( ) {}
|
||||
SkXMLParserError::~SkXMLParserError( ) {}
|
||||
void SkXMLParserError::getErrorString(SkString*) const {}
|
||||
void SkTextBox::setSpacing(int, int ) {}
|
||||
void SkTextBox::setSpacingAlign(SkTextBox::SpacingAlign ) {}
|
||||
void SkTextBox::draw(SkCanvas*, char const*, unsigned long, SkPaint const& ) {}
|
||||
void SkTextBox::setBox(SkRect const& ) {}
|
||||
void SkTextBox::setMode(SkTextBox::Mode ) {}
|
||||
SkTextBox::SkTextBox( ) {}
|
||||
void SkMetaData::setScalar(char const*, int ) {}
|
||||
const char* SkParse::FindScalar(char const*, int* ) {return 0; }
|
||||
const char* SkParse::FindScalars(char const*, int*, int ) {return 0; }
|
||||
const char* SkParse::FindHex(char const*, unsigned int* ) {return 0; }
|
||||
const char* SkParse::FindS32(char const*, int* ) {return 0; }
|
||||
void SkXMLWriter::addAttribute(char const*, char const* ) {}
|
||||
void SkXMLWriter::startElement(char const* ) {}
|
||||
void SkXMLWriter::doEnd(SkXMLWriter::Elem* ) {}
|
||||
SkXMLWriter::Elem* SkXMLWriter::getEnd( ) { return 0; }
|
||||
bool SkXMLWriter::doStart(char const*, unsigned long ) { return false; }
|
||||
SkXMLWriter::SkXMLWriter(bool ) {}
|
||||
SkXMLWriter::~SkXMLWriter( ) {}
|
||||
SkMetaData::SkMetaData() {}
|
||||
SkMetaData::~SkMetaData() {}
|
||||
bool SkEventSink::onEvent(SkEvent const&) {return false;}
|
||||
bool SkXMLParser::onEndElement(char const*) {return false;}
|
||||
bool SkXMLParser::onAddAttribute(char const*, char const*) {return false;}
|
||||
bool SkXMLParser::onStartElement(char const*) {return false;}
|
||||
void SkXMLWriter::writeHeader() {}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
/* libs/graphics/animator/SkDisplayEvent.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayEvent_DEFINED
|
||||
#define SkDisplayEvent_DEFINED
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkIntArray.h"
|
||||
#include "SkKey.h"
|
||||
|
||||
class SkEvent;
|
||||
|
||||
class SkDisplayEvent : public SkDisplayable {
|
||||
DECLARE_DISPLAY_MEMBER_INFO(Event);
|
||||
enum Kind {
|
||||
kNo_kind,
|
||||
kKeyChar,
|
||||
kKeyPress,
|
||||
kKeyPressUp, //i assume the order here is intended to match with skanimatorscript.cpp
|
||||
kMouseDown,
|
||||
kMouseDrag,
|
||||
kMouseMove,
|
||||
kMouseUp,
|
||||
kOnEnd,
|
||||
kOnload,
|
||||
kUser
|
||||
};
|
||||
SkDisplayEvent();
|
||||
virtual ~SkDisplayEvent();
|
||||
virtual bool add(SkAnimateMaker& , SkDisplayable* child);
|
||||
virtual bool contains(SkDisplayable*);
|
||||
virtual SkDisplayable* contains(const SkString& );
|
||||
#ifdef SK_DEBUG
|
||||
void dumpEvent(SkAnimateMaker* );
|
||||
#endif
|
||||
bool enableEvent(SkAnimateMaker& );
|
||||
virtual bool getProperty(int index, SkScriptValue* ) const;
|
||||
virtual void onEndElement(SkAnimateMaker& maker);
|
||||
void populateInput(SkAnimateMaker& , const SkEvent& fEvent);
|
||||
virtual bool setProperty(int index, SkScriptValue& );
|
||||
protected:
|
||||
SkKey code;
|
||||
SkBool disable;
|
||||
Kind kind;
|
||||
SkString target;
|
||||
SkScalar x;
|
||||
SkScalar y;
|
||||
SkTDDisplayableArray fChildren;
|
||||
mutable SkString fKeyString;
|
||||
SkKey fLastCode; // last key to trigger this event
|
||||
SkKey fMax; // if the code expresses a range
|
||||
SkDisplayable* fTarget; // used by onEnd
|
||||
private:
|
||||
void deleteMembers();
|
||||
friend class SkEvents;
|
||||
typedef SkDisplayable INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDisplayEvent_DEFINED
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
/* libs/graphics/animator/SkDisplayEvents.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayEvents.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkAnimator.h"
|
||||
#include "SkDisplayEvent.h"
|
||||
#include "SkDisplayMovie.h"
|
||||
#include "SkDrawable.h"
|
||||
#ifdef SK_DEBUG
|
||||
#include "SkDump.h"
|
||||
#endif
|
||||
|
||||
SkEventState::SkEventState() : fCode(0), fDisable(false), fDisplayable(0), fX(0), fY(0) {
|
||||
}
|
||||
|
||||
SkEvents::SkEvents() {
|
||||
}
|
||||
|
||||
SkEvents::~SkEvents() {
|
||||
}
|
||||
|
||||
bool SkEvents::doEvent(SkAnimateMaker& maker, SkDisplayEvent::Kind kind, SkEventState* state) {
|
||||
/*#ifdef SK_DUMP_ENABLED
|
||||
if (maker.fDumpEvents) {
|
||||
SkDebugf("doEvent: ");
|
||||
SkString str;
|
||||
SkDump::GetEnumString(SkType_EventKind, kind, &str);
|
||||
SkDebugf("kind=%s ", str.c_str());
|
||||
if (state && state->fDisplayable)
|
||||
state->fDisplayable->SkDisplayable::dump(&maker);
|
||||
else
|
||||
SkDebugf("\n");
|
||||
}
|
||||
#endif*/
|
||||
bool handled = false;
|
||||
SkDisplayable** firstMovie = maker.fMovies.begin();
|
||||
SkDisplayable** endMovie = maker.fMovies.end();
|
||||
for (SkDisplayable** ptr = firstMovie; ptr < endMovie; ptr++) {
|
||||
SkDisplayMovie* movie = (SkDisplayMovie*) *ptr;
|
||||
if (kind != SkDisplayEvent::kOnload)
|
||||
movie->doEvent(kind, state);
|
||||
}
|
||||
SkDisplayable* displayable = state ? state->fDisplayable : NULL;
|
||||
int keyCode = state ? state->fCode : 0;
|
||||
int count = fEvents.count();
|
||||
for (int index = 0; index < count; index++) {
|
||||
SkDisplayEvent* evt = fEvents[index];
|
||||
if (evt->disable)
|
||||
continue;
|
||||
if (evt->kind != kind)
|
||||
continue;
|
||||
if (evt->code != (SkKey) -1) {
|
||||
if ((int) evt->code > keyCode || (int) (evt->fMax != (SkKey) -1 ? evt->fMax : evt->code) < keyCode)
|
||||
continue;
|
||||
evt->fLastCode = (SkKey) keyCode;
|
||||
}
|
||||
if (evt->fTarget != NULL && evt->fTarget != displayable)
|
||||
continue;
|
||||
if (state == NULL || state->fDisable == 0) {
|
||||
if (kind >= SkDisplayEvent::kMouseDown && kind <= SkDisplayEvent::kMouseUp) {
|
||||
evt->x = state->fX;
|
||||
evt->y = state->fY;
|
||||
}
|
||||
if (evt->enableEvent(maker))
|
||||
fError = true;
|
||||
}
|
||||
handled = true;
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkEvents::dump(SkAnimateMaker& maker) {
|
||||
int index;
|
||||
SkTDDrawableArray& drawArray = maker.fDisplayList.fDrawList;
|
||||
int count = drawArray.count();
|
||||
for (index = 0; index < count; index++) {
|
||||
SkDrawable* drawable = drawArray[index];
|
||||
drawable->dumpEvents();
|
||||
}
|
||||
count = fEvents.count();
|
||||
for (index = 0; index < count; index++) {
|
||||
SkDisplayEvent* evt = fEvents[index];
|
||||
evt->dumpEvent(&maker);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// currently this only removes onLoad events
|
||||
void SkEvents::removeEvent(SkDisplayEvent::Kind kind, SkEventState* state) {
|
||||
int keyCode = state ? state->fCode : 0;
|
||||
SkDisplayable* displayable = state ? state->fDisplayable : NULL;
|
||||
for (SkDisplayEvent** evtPtr = fEvents.begin(); evtPtr < fEvents.end(); evtPtr++) {
|
||||
SkDisplayEvent* evt = *evtPtr;
|
||||
if (evt->kind != kind)
|
||||
continue;
|
||||
if (evt->code != (SkKey) -1) {
|
||||
if ((int) evt->code > keyCode || (int) (evt->fMax != (SkKey) -1 ? evt->fMax : evt->code) < keyCode)
|
||||
continue;
|
||||
}
|
||||
if (evt->fTarget != NULL && evt->fTarget != displayable)
|
||||
continue;
|
||||
int index = fEvents.find(evt);
|
||||
fEvents.remove(index);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/* libs/graphics/animator/SkDisplayEvents.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayEvents_DEFINED
|
||||
#define SkDisplayEvents_DEFINED
|
||||
|
||||
#include "SkEvent.h"
|
||||
#include "SkDisplayEvent.h"
|
||||
|
||||
struct SkEventState {
|
||||
SkEventState();
|
||||
int fCode;
|
||||
SkBool fDisable;
|
||||
SkDisplayable* fDisplayable;
|
||||
SkScalar fX;
|
||||
SkScalar fY;
|
||||
};
|
||||
|
||||
class SkEvents {
|
||||
public:
|
||||
SkEvents();
|
||||
~SkEvents();
|
||||
void addEvent(SkDisplayEvent* evt) { *fEvents.append() = evt; }
|
||||
bool doEvent(SkAnimateMaker& , SkDisplayEvent::Kind , SkEventState* );
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void dump(SkAnimateMaker& );
|
||||
#endif
|
||||
void reset() { fEvents.reset(); }
|
||||
void removeEvent(SkDisplayEvent::Kind kind, SkEventState* );
|
||||
private:
|
||||
SkTDDisplayEventArray fEvents;
|
||||
SkBool fError;
|
||||
friend class SkDisplayXMLParser;
|
||||
};
|
||||
|
||||
#endif // SkDisplayEvents_DEFINED
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/* libs/graphics/animator/SkDisplayInclude.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayInclude.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkAnimator.h"
|
||||
|
||||
#if 0
|
||||
#undef SK_MEMBER
|
||||
#define SK_MEMBER(_member, _type) \
|
||||
{ #_member, SK_OFFSETOF(BASE_CLASS::_A, _member), SkType_##_type, \
|
||||
sizeof(((BASE_CLASS::_A*) 0)->_member) / sizeof(SkScalar) }
|
||||
#endif
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkInclude::fInfo[] = {
|
||||
SK_MEMBER(src, String)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkInclude);
|
||||
|
||||
//SkInclude::SkInclude() {
|
||||
// src.init();
|
||||
//}
|
||||
|
||||
//SkInclude::~SkInclude() {
|
||||
// src.unref();
|
||||
//}
|
||||
|
||||
bool SkInclude::enable(SkAnimateMaker & ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkInclude::hasEnable() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkInclude::onEndElement(SkAnimateMaker& maker) {
|
||||
maker.fInInclude = true;
|
||||
if (src.size() == 0 || maker.decodeURI(src.c_str()) == false) {
|
||||
if (maker.getErrorCode() != SkXMLParserError::kNoError || maker.getNativeCode() != -1) {
|
||||
maker.setInnerError(&maker, src);
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kInInclude);
|
||||
} else {
|
||||
maker.setErrorNoun(src);
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kIncludeNameUnknownOrMissing);
|
||||
}
|
||||
}
|
||||
maker.fInInclude = false;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/* libs/graphics/animator/SkDisplayInclude.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayInclude_DEFINED
|
||||
#define SkDisplayInclude_DEFINED
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
|
||||
class SkInclude : public SkDisplayable {
|
||||
DECLARE_MEMBER_INFO(Include);
|
||||
virtual void onEndElement(SkAnimateMaker & );
|
||||
virtual bool enable(SkAnimateMaker & );
|
||||
virtual bool hasEnable() const;
|
||||
protected:
|
||||
SkString src;
|
||||
};
|
||||
|
||||
#endif // SkDisplayInclude_DEFINED
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/* libs/graphics/animator/SkDisplayInput.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayInput.h"
|
||||
|
||||
enum SkInput_Properties {
|
||||
SK_PROPERTY(initialized)
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkInput::fInfo[] = {
|
||||
SK_MEMBER_ALIAS(float, fFloat, Float),
|
||||
SK_MEMBER_PROPERTY(initialized, Boolean),
|
||||
SK_MEMBER_ALIAS(int, fInt, Int),
|
||||
SK_MEMBER(name, String),
|
||||
SK_MEMBER(string, String)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkInput);
|
||||
|
||||
SkInput::SkInput() : fInt((int) SK_NaN32), fFloat(SK_ScalarNaN) {}
|
||||
|
||||
SkDisplayable* SkInput::contains(const SkString& string) {
|
||||
return string.equals(name) ? this : NULL;
|
||||
}
|
||||
|
||||
bool SkInput::enable(SkAnimateMaker & ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkInput::getProperty(int index, SkScriptValue* value) const {
|
||||
switch (index) {
|
||||
case SK_PROPERTY(initialized):
|
||||
value->fType = SkType_Boolean;
|
||||
value->fOperand.fS32 = fInt != (int) SK_NaN32 ||
|
||||
SkScalarIsNaN(fFloat) == false || string.size() > 0;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkInput::hasEnable() const {
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/* libs/graphics/animator/SkDisplayInput.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayInput_DEFINED
|
||||
#define SkDisplayInput_DEFINED
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
|
||||
class SkInput : public SkDisplayable {
|
||||
DECLARE_MEMBER_INFO(Input);
|
||||
SkInput();
|
||||
virtual SkDisplayable* contains(const SkString& );
|
||||
virtual bool getProperty(int index, SkScriptValue* value) const;
|
||||
virtual bool enable(SkAnimateMaker & );
|
||||
virtual bool hasEnable() const;
|
||||
protected:
|
||||
SkString name;
|
||||
int32_t fInt;
|
||||
SkScalar fFloat;
|
||||
SkString string;
|
||||
private:
|
||||
friend class SkDisplayEvent;
|
||||
friend class SkPost;
|
||||
};
|
||||
|
||||
#endif // SkDisplayInput_DEFINED
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/* libs/graphics/animator/SkDisplayList.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayList.h"
|
||||
#include "SkAnimateActive.h"
|
||||
#include "SkAnimateBase.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkDrawable.h"
|
||||
#include "SkDrawGroup.h"
|
||||
#include "SkDrawMatrix.h"
|
||||
#include "SkInterpolator.h"
|
||||
#include "SkTime.h"
|
||||
|
||||
SkDisplayList::SkDisplayList() : fDrawBounds(true), fUnionBounds(false), fInTime(0) {
|
||||
}
|
||||
|
||||
SkDisplayList::~SkDisplayList() {
|
||||
}
|
||||
|
||||
void SkDisplayList::append(SkActive* active) {
|
||||
*fActiveList.append() = active;
|
||||
}
|
||||
|
||||
bool SkDisplayList::draw(SkAnimateMaker& maker, SkMSec inTime) {
|
||||
validate();
|
||||
fInTime = inTime;
|
||||
bool result = false;
|
||||
fInvalBounds.setEmpty();
|
||||
if (fDrawList.count()) {
|
||||
for (SkActive** activePtr = fActiveList.begin(); activePtr < fActiveList.end(); activePtr++) {
|
||||
SkActive* active = *activePtr;
|
||||
active->reset();
|
||||
}
|
||||
for (int index = 0; index < fDrawList.count(); index++) {
|
||||
SkDrawable* draw = fDrawList[index];
|
||||
draw->initialize(); // allow matrices to reset themselves
|
||||
SkASSERT(draw->isDrawable());
|
||||
validate();
|
||||
result |= draw->draw(maker);
|
||||
}
|
||||
}
|
||||
validate();
|
||||
return result;
|
||||
}
|
||||
|
||||
int SkDisplayList::findGroup(SkDrawable* match, SkTDDrawableArray** list,
|
||||
SkGroup** parent, SkGroup** found, SkTDDrawableArray**grandList) {
|
||||
*parent = NULL;
|
||||
*list = &fDrawList;
|
||||
*grandList = &fDrawList;
|
||||
return SearchForMatch(match, list, parent, found, grandList);
|
||||
}
|
||||
|
||||
void SkDisplayList::hardReset() {
|
||||
fDrawList.reset();
|
||||
fActiveList.reset();
|
||||
}
|
||||
|
||||
bool SkDisplayList::onIRect(const SkIRect& r) {
|
||||
fBounds = r;
|
||||
return fDrawBounds;
|
||||
}
|
||||
|
||||
int SkDisplayList::SearchForMatch(SkDrawable* match, SkTDDrawableArray** list,
|
||||
SkGroup** parent, SkGroup** found, SkTDDrawableArray**grandList) {
|
||||
*found = NULL;
|
||||
for (int index = 0; index < (*list)->count(); index++) {
|
||||
SkDrawable* draw = (**list)[index];
|
||||
if (draw == match)
|
||||
return index;
|
||||
if (draw->isApply()) {
|
||||
SkApply* apply = (SkApply*) draw;
|
||||
if (apply->scope == match)
|
||||
return index;
|
||||
if (apply->scope->isGroup() && SearchGroupForMatch(apply->scope, match, list, parent, found, grandList, index))
|
||||
return index;
|
||||
if (apply->mode == SkApply::kMode_create) {
|
||||
for (SkDrawable** ptr = apply->fScopes.begin(); ptr < apply->fScopes.end(); ptr++) {
|
||||
SkDrawable* scope = *ptr;
|
||||
if (scope == match)
|
||||
return index;
|
||||
//perhaps should call SearchGroupForMatch here as well (on scope)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (draw->isGroup() && SearchGroupForMatch(draw, match, list, parent, found, grandList, index))
|
||||
return index;
|
||||
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool SkDisplayList::SearchGroupForMatch(SkDrawable* draw, SkDrawable* match, SkTDDrawableArray** list,
|
||||
SkGroup** parent, SkGroup** found, SkTDDrawableArray** grandList, int &index) {
|
||||
SkGroup* group = (SkGroup*) draw;
|
||||
if (group->getOriginal() == match)
|
||||
return true;
|
||||
SkTDDrawableArray* saveList = *list;
|
||||
int groupIndex = group->findGroup(match, list, parent, found, grandList);
|
||||
if (groupIndex >= 0) {
|
||||
*found = group;
|
||||
index = groupIndex;
|
||||
return true;
|
||||
}
|
||||
*list = saveList;
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkDisplayList::reset() {
|
||||
for (int index = 0; index < fDrawList.count(); index++) {
|
||||
SkDrawable* draw = fDrawList[index];
|
||||
if (draw->isApply() == false)
|
||||
continue;
|
||||
SkApply* apply = (SkApply*) draw;
|
||||
apply->reset();
|
||||
}
|
||||
}
|
||||
|
||||
void SkDisplayList::remove(SkActive* active) {
|
||||
int index = fActiveList.find(active);
|
||||
SkASSERT(index >= 0);
|
||||
fActiveList.remove(index); // !!! could use shuffle instead
|
||||
SkASSERT(fActiveList.find(active) < 0);
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
int SkDisplayList::fDumpIndex;
|
||||
int SkDisplayList::fIndent;
|
||||
|
||||
void SkDisplayList::dump(SkAnimateMaker* maker) {
|
||||
fIndent = 0;
|
||||
dumpInner(maker);
|
||||
}
|
||||
|
||||
void SkDisplayList::dumpInner(SkAnimateMaker* maker) {
|
||||
for (int index = 0; index < fDrawList.count(); index++) {
|
||||
fDumpIndex = index;
|
||||
fDrawList[fDumpIndex]->dump(maker);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void SkDisplayList::validate() {
|
||||
for (int index = 0; index < fDrawList.count(); index++) {
|
||||
SkDrawable* draw = fDrawList[index];
|
||||
draw->validate();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/* libs/graphics/animator/SkDisplayList.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayList_DEFINED
|
||||
#define SkDisplayList_DEFINED
|
||||
|
||||
#include "SkOperand.h"
|
||||
#include "SkIntArray.h"
|
||||
#include "SkBounder.h"
|
||||
#include "SkRect.h"
|
||||
|
||||
class SkAnimateMaker;
|
||||
class SkActive;
|
||||
class SkApply;
|
||||
class SkDrawable;
|
||||
class SkGroup;
|
||||
|
||||
class SkDisplayList : public SkBounder {
|
||||
public:
|
||||
SkDisplayList();
|
||||
virtual ~SkDisplayList();
|
||||
void append(SkActive* );
|
||||
void clear() { fDrawList.reset(); }
|
||||
int count() { return fDrawList.count(); }
|
||||
bool draw(SkAnimateMaker& , SkMSec time);
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void dump(SkAnimateMaker* maker);
|
||||
void dumpInner(SkAnimateMaker* maker);
|
||||
static int fIndent;
|
||||
static int fDumpIndex;
|
||||
#endif
|
||||
int findGroup(SkDrawable* match, SkTDDrawableArray** list,
|
||||
SkGroup** parent, SkGroup** found, SkTDDrawableArray** grandList);
|
||||
SkDrawable* get(int index) { return fDrawList[index]; }
|
||||
SkMSec getTime() { return fInTime; }
|
||||
SkTDDrawableArray* getDrawList() { return &fDrawList; }
|
||||
void hardReset();
|
||||
virtual bool onIRect(const SkIRect& r);
|
||||
void reset();
|
||||
void remove(SkActive* );
|
||||
#ifdef SK_DEBUG
|
||||
void validate();
|
||||
#else
|
||||
void validate() {}
|
||||
#endif
|
||||
static int SearchForMatch(SkDrawable* match, SkTDDrawableArray** list,
|
||||
SkGroup** parent, SkGroup** found, SkTDDrawableArray**grandList);
|
||||
static bool SearchGroupForMatch(SkDrawable* draw, SkDrawable* match,
|
||||
SkTDDrawableArray** list, SkGroup** parent, SkGroup** found, SkTDDrawableArray** grandList,
|
||||
int &index);
|
||||
public:
|
||||
SkIRect fBounds;
|
||||
SkIRect fInvalBounds;
|
||||
bool fDrawBounds;
|
||||
bool fHasUnion;
|
||||
bool fUnionBounds;
|
||||
private:
|
||||
SkTDDrawableArray fDrawList;
|
||||
SkTDActiveArray fActiveList;
|
||||
SkMSec fInTime;
|
||||
friend class SkEvents;
|
||||
};
|
||||
|
||||
#endif // SkDisplayList_DEFINED
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
/* libs/graphics/animator/SkDisplayMath.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayMath.h"
|
||||
|
||||
enum SkDisplayMath_Properties {
|
||||
SK_PROPERTY(E),
|
||||
SK_PROPERTY(LN10),
|
||||
SK_PROPERTY(LN2),
|
||||
SK_PROPERTY(LOG10E),
|
||||
SK_PROPERTY(LOG2E),
|
||||
SK_PROPERTY(PI),
|
||||
SK_PROPERTY(SQRT1_2),
|
||||
SK_PROPERTY(SQRT2)
|
||||
};
|
||||
|
||||
const SkScalar SkDisplayMath::gConstants[] = {
|
||||
#ifdef SK_SCALAR_IS_FLOAT
|
||||
2.718281828f, // E
|
||||
2.302585093f, // LN10
|
||||
0.693147181f, // LN2
|
||||
0.434294482f, // LOG10E
|
||||
1.442695041f, // LOG2E
|
||||
3.141592654f, // PI
|
||||
0.707106781f, // SQRT1_2
|
||||
1.414213562f // SQRT2
|
||||
#else
|
||||
0x2B7E1, // E
|
||||
0x24D76, // LN10
|
||||
0xB172, // LN2
|
||||
0x6F2E, // LOG10E
|
||||
0x17154, // LOG2E
|
||||
0x3243F, // PI
|
||||
0xB505, // SQRT1_2
|
||||
0x16A0A // SQRT2
|
||||
#endif
|
||||
};
|
||||
|
||||
enum SkDisplayMath_Functions {
|
||||
SK_FUNCTION(abs),
|
||||
SK_FUNCTION(acos),
|
||||
SK_FUNCTION(asin),
|
||||
SK_FUNCTION(atan),
|
||||
SK_FUNCTION(atan2),
|
||||
SK_FUNCTION(ceil),
|
||||
SK_FUNCTION(cos),
|
||||
SK_FUNCTION(exp),
|
||||
SK_FUNCTION(floor),
|
||||
SK_FUNCTION(log),
|
||||
SK_FUNCTION(max),
|
||||
SK_FUNCTION(min),
|
||||
SK_FUNCTION(pow),
|
||||
SK_FUNCTION(random),
|
||||
SK_FUNCTION(round),
|
||||
SK_FUNCTION(sin),
|
||||
SK_FUNCTION(sqrt),
|
||||
SK_FUNCTION(tan)
|
||||
};
|
||||
|
||||
const SkFunctionParamType SkDisplayMath::fFunctionParameters[] = {
|
||||
(SkFunctionParamType) SkType_Float, // abs
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // acos
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // asin
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // atan
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // atan2
|
||||
(SkFunctionParamType) SkType_Float,
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // ceil
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // cos
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // exp
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // floor
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // log
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Array, // max
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Array, // min
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // pow
|
||||
(SkFunctionParamType) SkType_Float,
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // random
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // round
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // sin
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // sqrt
|
||||
(SkFunctionParamType) 0,
|
||||
(SkFunctionParamType) SkType_Float, // tan
|
||||
(SkFunctionParamType) 0
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDisplayMath::fInfo[] = {
|
||||
SK_MEMBER_PROPERTY(E, Float),
|
||||
SK_MEMBER_PROPERTY(LN10, Float),
|
||||
SK_MEMBER_PROPERTY(LN2, Float),
|
||||
SK_MEMBER_PROPERTY(LOG10E, Float),
|
||||
SK_MEMBER_PROPERTY(LOG2E, Float),
|
||||
SK_MEMBER_PROPERTY(PI, Float),
|
||||
SK_MEMBER_PROPERTY(SQRT1_2, Float),
|
||||
SK_MEMBER_PROPERTY(SQRT2, Float),
|
||||
SK_MEMBER_FUNCTION(abs, Float),
|
||||
SK_MEMBER_FUNCTION(acos, Float),
|
||||
SK_MEMBER_FUNCTION(asin, Float),
|
||||
SK_MEMBER_FUNCTION(atan, Float),
|
||||
SK_MEMBER_FUNCTION(atan2, Float),
|
||||
SK_MEMBER_FUNCTION(ceil, Float),
|
||||
SK_MEMBER_FUNCTION(cos, Float),
|
||||
SK_MEMBER_FUNCTION(exp, Float),
|
||||
SK_MEMBER_FUNCTION(floor, Float),
|
||||
SK_MEMBER_FUNCTION(log, Float),
|
||||
SK_MEMBER_FUNCTION(max, Float),
|
||||
SK_MEMBER_FUNCTION(min, Float),
|
||||
SK_MEMBER_FUNCTION(pow, Float),
|
||||
SK_MEMBER_FUNCTION(random, Float),
|
||||
SK_MEMBER_FUNCTION(round, Float),
|
||||
SK_MEMBER_FUNCTION(sin, Float),
|
||||
SK_MEMBER_FUNCTION(sqrt, Float),
|
||||
SK_MEMBER_FUNCTION(tan, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDisplayMath);
|
||||
|
||||
void SkDisplayMath::executeFunction(SkDisplayable* target, int index,
|
||||
SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
|
||||
SkScriptValue* scriptValue) {
|
||||
if (scriptValue == NULL)
|
||||
return;
|
||||
SkASSERT(target == this);
|
||||
SkScriptValue* array = parameters.begin();
|
||||
SkScriptValue* end = parameters.end();
|
||||
SkScalar input = parameters[0].fOperand.fScalar;
|
||||
SkScalar scalarResult;
|
||||
switch (index) {
|
||||
case SK_FUNCTION(abs):
|
||||
scalarResult = SkScalarAbs(input);
|
||||
break;
|
||||
case SK_FUNCTION(acos):
|
||||
scalarResult = SkScalarACos(input);
|
||||
break;
|
||||
case SK_FUNCTION(asin):
|
||||
scalarResult = SkScalarASin(input);
|
||||
break;
|
||||
case SK_FUNCTION(atan):
|
||||
scalarResult = SkScalarATan2(input, SK_Scalar1);
|
||||
break;
|
||||
case SK_FUNCTION(atan2):
|
||||
scalarResult = SkScalarATan2(input, parameters[1].fOperand.fScalar);
|
||||
break;
|
||||
case SK_FUNCTION(ceil):
|
||||
scalarResult = SkIntToScalar(SkScalarCeil(input));
|
||||
break;
|
||||
case SK_FUNCTION(cos):
|
||||
scalarResult = SkScalarCos(input);
|
||||
break;
|
||||
case SK_FUNCTION(exp):
|
||||
scalarResult = SkScalarExp(input);
|
||||
break;
|
||||
case SK_FUNCTION(floor):
|
||||
scalarResult = SkIntToScalar(SkScalarFloor(input));
|
||||
break;
|
||||
case SK_FUNCTION(log):
|
||||
scalarResult = SkScalarLog(input);
|
||||
break;
|
||||
case SK_FUNCTION(max):
|
||||
scalarResult = -SK_ScalarMax;
|
||||
while (array < end) {
|
||||
scalarResult = SkMaxScalar(scalarResult, array->fOperand.fScalar);
|
||||
array++;
|
||||
}
|
||||
break;
|
||||
case SK_FUNCTION(min):
|
||||
scalarResult = SK_ScalarMax;
|
||||
while (array < end) {
|
||||
scalarResult = SkMinScalar(scalarResult, array->fOperand.fScalar);
|
||||
array++;
|
||||
}
|
||||
break;
|
||||
case SK_FUNCTION(pow):
|
||||
// not the greatest -- but use x^y = e^(y * ln(x))
|
||||
scalarResult = SkScalarLog(input);
|
||||
scalarResult = SkScalarMul(parameters[1].fOperand.fScalar, scalarResult);
|
||||
scalarResult = SkScalarExp(scalarResult);
|
||||
break;
|
||||
case SK_FUNCTION(random):
|
||||
scalarResult = fRandom.nextUScalar1();
|
||||
break;
|
||||
case SK_FUNCTION(round):
|
||||
scalarResult = SkIntToScalar(SkScalarRound(input));
|
||||
break;
|
||||
case SK_FUNCTION(sin):
|
||||
scalarResult = SkScalarSin(input);
|
||||
break;
|
||||
case SK_FUNCTION(sqrt): {
|
||||
SkASSERT(parameters.count() == 1);
|
||||
SkASSERT(type == SkType_Float);
|
||||
scalarResult = SkScalarSqrt(input);
|
||||
} break;
|
||||
case SK_FUNCTION(tan):
|
||||
scalarResult = SkScalarTan(input);
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
scalarResult = SK_ScalarNaN;
|
||||
}
|
||||
scriptValue->fOperand.fScalar = scalarResult;
|
||||
scriptValue->fType = SkType_Float;
|
||||
}
|
||||
|
||||
const SkFunctionParamType* SkDisplayMath::getFunctionsParameters() {
|
||||
return fFunctionParameters;
|
||||
}
|
||||
|
||||
bool SkDisplayMath::getProperty(int index, SkScriptValue* value) const {
|
||||
if ((unsigned)index < SK_ARRAY_COUNT(gConstants)) {
|
||||
value->fOperand.fScalar = gConstants[index];
|
||||
value->fType = SkType_Float;
|
||||
return true;
|
||||
}
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/* libs/graphics/animator/SkDisplayMath.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayMath_DEFINED
|
||||
#define SkDisplayMath_DEFINED
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkRandom.h"
|
||||
|
||||
class SkDisplayMath : public SkDisplayable {
|
||||
DECLARE_DISPLAY_MEMBER_INFO(Math);
|
||||
virtual void executeFunction(SkDisplayable* , int index,
|
||||
SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
|
||||
SkScriptValue* );
|
||||
virtual const SkFunctionParamType* getFunctionsParameters();
|
||||
virtual bool getProperty(int index, SkScriptValue* value) const;
|
||||
private:
|
||||
mutable SkRandom fRandom;
|
||||
static const SkScalar gConstants[];
|
||||
static const SkFunctionParamType fFunctionParameters[];
|
||||
|
||||
};
|
||||
|
||||
#endif // SkDisplayMath_DEFINED
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
/* libs/graphics/animator/SkDisplayMovie.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayMovie.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkPaint.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDisplayMovie::fInfo[] = {
|
||||
SK_MEMBER(src, String)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDisplayMovie);
|
||||
|
||||
SkDisplayMovie::SkDisplayMovie() : fDecodedSuccessfully(false), fLoaded(false), fMovieBuilt(false) {
|
||||
fMovie.fMaker->fInMovie = true;
|
||||
}
|
||||
|
||||
SkDisplayMovie::~SkDisplayMovie() {
|
||||
}
|
||||
|
||||
void SkDisplayMovie::buildMovie() {
|
||||
if (fMovieBuilt)
|
||||
return;
|
||||
SkAnimateMaker* movieMaker = fMovie.fMaker;
|
||||
SkAnimateMaker* parentMaker = movieMaker->fParentMaker;
|
||||
if (src.size() == 0 || parentMaker == NULL)
|
||||
return;
|
||||
movieMaker->fPrefix.set(parentMaker->fPrefix);
|
||||
fDecodedSuccessfully = fMovie.fMaker->decodeURI(src.c_str());
|
||||
if (fDecodedSuccessfully == false) {
|
||||
|
||||
if (movieMaker->getErrorCode() != SkXMLParserError::kNoError || movieMaker->getNativeCode() != -1) {
|
||||
movieMaker->setInnerError(parentMaker, src);
|
||||
parentMaker->setErrorCode(SkDisplayXMLParserError::kInMovie);
|
||||
} else {
|
||||
parentMaker->setErrorNoun(src);
|
||||
parentMaker->setErrorCode(SkDisplayXMLParserError::kMovieNameUnknownOrMissing);
|
||||
}
|
||||
}
|
||||
fMovieBuilt = true;
|
||||
}
|
||||
|
||||
SkDisplayable* SkDisplayMovie::deepCopy(SkAnimateMaker* maker) {
|
||||
SkDisplayMovie* copy = (SkDisplayMovie*) INHERITED::deepCopy(maker);
|
||||
copy->fMovie.fMaker->fParentMaker = fMovie.fMaker->fParentMaker;
|
||||
copy->fMovie.fMaker->fHostEventSinkID = fMovie.fMaker->fHostEventSinkID;
|
||||
copy->fMovieBuilt = false;
|
||||
*fMovie.fMaker->fParentMaker->fMovies.append() = copy;
|
||||
return copy;
|
||||
}
|
||||
|
||||
void SkDisplayMovie::dirty() {
|
||||
buildMovie();
|
||||
}
|
||||
|
||||
bool SkDisplayMovie::doEvent(SkDisplayEvent::Kind kind, SkEventState* state) {
|
||||
if (fLoaded == false)
|
||||
return false;
|
||||
fMovie.fMaker->fEnableTime = fMovie.fMaker->fParentMaker->fEnableTime;
|
||||
return fMovie.fMaker->fEvents.doEvent(*fMovie.fMaker, kind, state);
|
||||
}
|
||||
|
||||
bool SkDisplayMovie::draw(SkAnimateMaker& maker) {
|
||||
if (fDecodedSuccessfully == false)
|
||||
return false;
|
||||
if (fLoaded == false)
|
||||
enable(maker);
|
||||
maker.fCanvas->save();
|
||||
SkPaint local = SkPaint(*maker.fPaint);
|
||||
bool result = fMovie.draw(maker.fCanvas, &local,
|
||||
maker.fDisplayList.getTime()) != SkAnimator::kNotDifferent;
|
||||
maker.fDisplayList.fInvalBounds.join(fMovie.fMaker->fDisplayList.fInvalBounds);
|
||||
maker.fCanvas->restore();
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkDisplayMovie::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
SkDebugf("src=\"%s\"/>\n", src.c_str());
|
||||
SkAnimateMaker* movieMaker = fMovie.fMaker;
|
||||
SkDisplayList::fIndent += 4;
|
||||
movieMaker->fDisplayList.dumpInner(movieMaker);
|
||||
SkDisplayList::fIndent -= 4;
|
||||
dumpEnd(maker);
|
||||
}
|
||||
|
||||
void SkDisplayMovie::dumpEvents() {
|
||||
fMovie.fMaker->fEvents.dump(*fMovie.fMaker);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkDisplayMovie::enable(SkAnimateMaker& maker) {
|
||||
if (fDecodedSuccessfully == false)
|
||||
return false;
|
||||
SkAnimateMaker* movieMaker = fMovie.fMaker;
|
||||
movieMaker->fEvents.doEvent(*movieMaker, SkDisplayEvent::kOnload, NULL);
|
||||
movieMaker->fEvents.removeEvent(SkDisplayEvent::kOnload, NULL);
|
||||
fLoaded = true;
|
||||
movieMaker->fLoaded = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDisplayMovie::hasEnable() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkDisplayMovie::onEndElement(SkAnimateMaker& maker) {
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
fMovie.fMaker->fDebugTimeBase = maker.fDebugTimeBase;
|
||||
#endif
|
||||
fMovie.fMaker->fPrefix.set(maker.fPrefix);
|
||||
fMovie.fMaker->fHostEventSinkID = maker.fHostEventSinkID;
|
||||
fMovie.fMaker->fParentMaker = &maker;
|
||||
buildMovie();
|
||||
*maker.fMovies.append() = this;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/* libs/graphics/animator/SkDisplayMovie.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayMovie_DEFINED
|
||||
#define SkDisplayMovie_DEFINED
|
||||
|
||||
#include "SkAnimator.h"
|
||||
#include "SkDrawable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
|
||||
struct SkEventState;
|
||||
|
||||
class SkDisplayMovie : public SkDrawable {
|
||||
DECLARE_DISPLAY_MEMBER_INFO(Movie);
|
||||
SkDisplayMovie();
|
||||
virtual ~SkDisplayMovie();
|
||||
void buildMovie();
|
||||
virtual SkDisplayable* deepCopy(SkAnimateMaker* );
|
||||
virtual void dirty();
|
||||
bool doEvent(const SkEvent& evt) {
|
||||
return fLoaded && fMovie.doEvent(evt);
|
||||
}
|
||||
virtual bool doEvent(SkDisplayEvent::Kind , SkEventState* state );
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
virtual void dumpEvents();
|
||||
#endif
|
||||
virtual bool enable(SkAnimateMaker& );
|
||||
const SkAnimator* getAnimator() const { return &fMovie; }
|
||||
virtual bool hasEnable() const;
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
protected:
|
||||
SkString src;
|
||||
SkAnimator fMovie;
|
||||
SkBool8 fDecodedSuccessfully;
|
||||
SkBool8 fLoaded;
|
||||
SkBool8 fMovieBuilt;
|
||||
friend class SkAnimateMaker;
|
||||
friend class SkPost;
|
||||
private:
|
||||
typedef SkDrawable INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDisplayMovie_DEFINED
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/* libs/graphics/animator/SkDisplayNumber.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayNumber.h"
|
||||
|
||||
enum SkDisplayNumber_Properties {
|
||||
SK_PROPERTY(MAX_VALUE),
|
||||
SK_PROPERTY(MIN_VALUE),
|
||||
SK_PROPERTY(NEGATIVE_INFINITY),
|
||||
SK_PROPERTY(NaN),
|
||||
SK_PROPERTY(POSITIVE_INFINITY)
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDisplayNumber::fInfo[] = {
|
||||
SK_MEMBER_PROPERTY(MAX_VALUE, Float),
|
||||
SK_MEMBER_PROPERTY(MIN_VALUE, Float),
|
||||
SK_MEMBER_PROPERTY(NEGATIVE_INFINITY, Float),
|
||||
SK_MEMBER_PROPERTY(NaN, Float),
|
||||
SK_MEMBER_PROPERTY(POSITIVE_INFINITY, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDisplayNumber);
|
||||
|
||||
bool SkDisplayNumber::getProperty(int index, SkScriptValue* value) const {
|
||||
SkScalar constant;
|
||||
switch (index) {
|
||||
case SK_PROPERTY(MAX_VALUE):
|
||||
constant = SK_ScalarMax;
|
||||
break;
|
||||
case SK_PROPERTY(MIN_VALUE):
|
||||
constant = SK_ScalarMin;
|
||||
break;
|
||||
case SK_PROPERTY(NEGATIVE_INFINITY):
|
||||
constant = -SK_ScalarInfinity;
|
||||
break;
|
||||
case SK_PROPERTY(NaN):
|
||||
constant = SK_ScalarNaN;
|
||||
break;
|
||||
case SK_PROPERTY(POSITIVE_INFINITY):
|
||||
constant = SK_ScalarInfinity;
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
value->fOperand.fScalar = constant;
|
||||
value->fType = SkType_Float;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/* libs/graphics/animator/SkDisplayNumber.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayNumber_DEFINED
|
||||
#define SkDisplayNumber_DEFINED
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
|
||||
class SkDisplayNumber : public SkDisplayable {
|
||||
DECLARE_DISPLAY_MEMBER_INFO(Number);
|
||||
virtual bool getProperty(int index, SkScriptValue* value) const;
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // SkDisplayNumber_DEFINED
|
||||
@@ -0,0 +1,315 @@
|
||||
/* libs/graphics/animator/SkDisplayPost.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayPost.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkAnimator.h"
|
||||
#include "SkDisplayMovie.h"
|
||||
#include "SkPostParts.h"
|
||||
#include "SkScript.h"
|
||||
#ifdef SK_DEBUG
|
||||
#include "SkDump.h"
|
||||
#include "SkTime.h"
|
||||
#endif
|
||||
|
||||
enum SkPost_Properties {
|
||||
SK_PROPERTY(target),
|
||||
SK_PROPERTY(type)
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkPost::fInfo[] = {
|
||||
SK_MEMBER(delay, MSec),
|
||||
// SK_MEMBER(initialized, Boolean),
|
||||
SK_MEMBER(mode, EventMode),
|
||||
SK_MEMBER(sink, String),
|
||||
SK_MEMBER_PROPERTY(target, String),
|
||||
SK_MEMBER_PROPERTY(type, String)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkPost);
|
||||
|
||||
SkPost::SkPost() : delay(0), /*initialized(SkBool(-1)), */ mode(kImmediate), fMaker(NULL),
|
||||
fSinkID(0), fTargetMaker(NULL), fChildHasID(false), fDirty(false) {
|
||||
}
|
||||
|
||||
SkPost::~SkPost() {
|
||||
for (SkData** part = fParts.begin(); part < fParts.end(); part++)
|
||||
delete *part;
|
||||
}
|
||||
|
||||
bool SkPost::add(SkAnimateMaker& , SkDisplayable* child) {
|
||||
SkASSERT(child && child->isData());
|
||||
SkData* part = (SkData*) child;
|
||||
*fParts.append() = part;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkPost::childrenNeedDisposing() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkPost::dirty() {
|
||||
fDirty = true;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkPost::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
SkString* eventType = new SkString();
|
||||
fEvent.getType(eventType);
|
||||
if (eventType->equals("user")) {
|
||||
const char* target = fEvent.findString("id");
|
||||
SkDebugf("target=\"%s\" ", target);
|
||||
}
|
||||
else
|
||||
SkDebugf("type=\"%s\" ", eventType->c_str());
|
||||
delete eventType;
|
||||
|
||||
if (delay > 0) {
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf("delay=\"%g\" ", SkScalarToFloat(SkScalarDiv(delay, 1000)));
|
||||
#else
|
||||
SkDebugf("delay=\"%x\" ", SkScalarDiv(delay, 1000));
|
||||
#endif
|
||||
}
|
||||
// if (initialized == false)
|
||||
// SkDebugf("(uninitialized) ");
|
||||
SkString string;
|
||||
SkDump::GetEnumString(SkType_EventMode, mode, &string);
|
||||
if (!string.equals("immediate"))
|
||||
SkDebugf("mode=\"%s\" ", string.c_str());
|
||||
// !!! could enhance this to search through make hierarchy to show name of sink
|
||||
if (sink.size() > 0) {
|
||||
SkDebugf("sink=\"%s\" sinkID=\"%d\" ", sink.c_str(), fSinkID);
|
||||
} else if (fSinkID != maker->getAnimator()->getSinkID() && fSinkID != 0) {
|
||||
SkDebugf("sinkID=\"%d\" ", fSinkID);
|
||||
}
|
||||
const SkMetaData& meta = fEvent.getMetaData();
|
||||
SkMetaData::Iter iter(meta);
|
||||
SkMetaData::Type type;
|
||||
int number;
|
||||
const char* name;
|
||||
bool closedYet = false;
|
||||
SkDisplayList::fIndent += 4;
|
||||
//this seems to work, but kinda hacky
|
||||
//for some reason the last part is id, which i don't want
|
||||
//and the parts seem to be in the reverse order from the one in which we find the
|
||||
//data itself
|
||||
//SkData** ptr = fParts.end();
|
||||
//SkData* data;
|
||||
//const char* ID;
|
||||
while ((name = iter.next(&type, &number)) != NULL) {
|
||||
//ptr--;
|
||||
if (strcmp(name, "id") == 0)
|
||||
continue;
|
||||
if (closedYet == false) {
|
||||
SkDebugf(">\n");
|
||||
closedYet = true;
|
||||
}
|
||||
//data = *ptr;
|
||||
//if (data->id)
|
||||
// ID = data->id;
|
||||
//else
|
||||
// ID = "";
|
||||
SkDebugf("%*s<data name=\"%s\" ", SkDisplayList::fIndent, "", name);
|
||||
switch (type) {
|
||||
case SkMetaData::kS32_Type: {
|
||||
int32_t s32;
|
||||
meta.findS32(name, &s32);
|
||||
SkDebugf("int=\"%d\" ", s32);
|
||||
} break;
|
||||
case SkMetaData::kScalar_Type: {
|
||||
SkScalar scalar;
|
||||
meta.findScalar(name, &scalar);
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf("float=\"%g\" ", SkScalarToFloat(scalar));
|
||||
#else
|
||||
SkDebugf("float=\"%x\" ", scalar);
|
||||
#endif
|
||||
} break;
|
||||
case SkMetaData::kString_Type:
|
||||
SkDebugf("string=\"%s\" ", meta.findString(name));
|
||||
break;
|
||||
case SkMetaData::kPtr_Type: {//when do we have a pointer
|
||||
void* ptr;
|
||||
meta.findPtr(name, &ptr);
|
||||
SkDebugf("0x%08x ", ptr);
|
||||
} break;
|
||||
case SkMetaData::kBool_Type: {
|
||||
bool boolean;
|
||||
meta.findBool(name, &boolean);
|
||||
SkDebugf("boolean=\"%s\" ", boolean ? "true " : "false ");
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
SkDebugf("/>\n");
|
||||
//ptr++;
|
||||
/* perhaps this should only be done in the case of a pointer?
|
||||
SkDisplayable* displayable;
|
||||
if (maker->find(name, &displayable))
|
||||
displayable->dump(maker);
|
||||
else
|
||||
SkDebugf("\n");*/
|
||||
}
|
||||
SkDisplayList::fIndent -= 4;
|
||||
if (closedYet)
|
||||
dumpEnd(maker);
|
||||
else
|
||||
SkDebugf("/>\n");
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkPost::enable(SkAnimateMaker& maker ) {
|
||||
if (maker.hasError())
|
||||
return true;
|
||||
if (fDirty) {
|
||||
if (sink.size() > 0)
|
||||
findSinkID();
|
||||
if (fChildHasID) {
|
||||
SkString preserveID(fEvent.findString("id"));
|
||||
fEvent.getMetaData().reset();
|
||||
if (preserveID.size() > 0)
|
||||
fEvent.setString("id", preserveID);
|
||||
for (SkData** part = fParts.begin(); part < fParts.end(); part++) {
|
||||
if ((*part)->add())
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kErrorAddingDataToPost);
|
||||
}
|
||||
}
|
||||
fDirty = false;
|
||||
}
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
if (maker.fDumpPosts) {
|
||||
SkDebugf("post enable: ");
|
||||
dump(&maker);
|
||||
}
|
||||
#if defined SK_DEBUG_ANIMATION_TIMING
|
||||
SkString debugOut;
|
||||
SkMSec time = maker.getAppTime();
|
||||
debugOut.appendS32(time - maker.fDebugTimeBase);
|
||||
debugOut.append(" post id=");
|
||||
debugOut.append(_id);
|
||||
debugOut.append(" enable=");
|
||||
debugOut.appendS32(maker.fEnableTime - maker.fDebugTimeBase);
|
||||
debugOut.append(" delay=");
|
||||
debugOut.appendS32(delay);
|
||||
#endif
|
||||
#endif
|
||||
// SkMSec adjustedDelay = maker.adjustDelay(maker.fEnableTime, delay);
|
||||
SkMSec futureTime = maker.fEnableTime + delay;
|
||||
fEvent.setFast32(futureTime);
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
debugOut.append(" future=");
|
||||
debugOut.appendS32(futureTime - maker.fDebugTimeBase);
|
||||
SkDebugf("%s\n", debugOut.c_str());
|
||||
#endif
|
||||
SkEventSinkID targetID = fSinkID;
|
||||
bool isAnimatorEvent = true;
|
||||
SkAnimator* anim = maker.getAnimator();
|
||||
if (targetID == 0) {
|
||||
isAnimatorEvent = fEvent.findString("id") != NULL;
|
||||
if (isAnimatorEvent)
|
||||
targetID = anim->getSinkID();
|
||||
else if (maker.fHostEventSinkID)
|
||||
targetID = maker.fHostEventSinkID;
|
||||
else
|
||||
return true;
|
||||
} else
|
||||
anim = fTargetMaker->getAnimator();
|
||||
if (delay == 0) {
|
||||
if (isAnimatorEvent && mode == kImmediate)
|
||||
fTargetMaker->doEvent(fEvent);
|
||||
else
|
||||
anim->onEventPost(new SkEvent(fEvent), targetID);
|
||||
} else
|
||||
anim->onEventPostTime(new SkEvent(fEvent), targetID, futureTime);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkPost::findSinkID() {
|
||||
// get the next delimiter '.' if any
|
||||
fTargetMaker = fMaker;
|
||||
const char* ch = sink.c_str();
|
||||
do {
|
||||
const char* end = strchr(ch, '.');
|
||||
size_t len = end ? end - ch : strlen(ch);
|
||||
SkDisplayable* displayable = NULL;
|
||||
if (SK_LITERAL_STR_EQUAL("parent", ch, len)) {
|
||||
if (fTargetMaker->fParentMaker)
|
||||
fTargetMaker = fTargetMaker->fParentMaker;
|
||||
else {
|
||||
fTargetMaker->setErrorCode(SkDisplayXMLParserError::kNoParentAvailable);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
fTargetMaker->find(ch, len, &displayable);
|
||||
if (displayable == NULL || displayable->getType() != SkType_Movie) {
|
||||
fTargetMaker->setErrorCode(SkDisplayXMLParserError::kExpectedMovie);
|
||||
return;
|
||||
}
|
||||
SkDisplayMovie* movie = (SkDisplayMovie*) displayable;
|
||||
fTargetMaker = movie->fMovie.fMaker;
|
||||
}
|
||||
if (end == NULL)
|
||||
break;
|
||||
ch = ++end;
|
||||
} while (true);
|
||||
SkAnimator* anim = fTargetMaker->getAnimator();
|
||||
fSinkID = anim->getSinkID();
|
||||
}
|
||||
|
||||
bool SkPost::hasEnable() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkPost::onEndElement(SkAnimateMaker& maker) {
|
||||
fTargetMaker = fMaker = &maker;
|
||||
if (fChildHasID == false) {
|
||||
for (SkData** part = fParts.begin(); part < fParts.end(); part++)
|
||||
delete *part;
|
||||
fParts.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void SkPost::setChildHasID() {
|
||||
fChildHasID = true;
|
||||
}
|
||||
|
||||
bool SkPost::setProperty(int index, SkScriptValue& value) {
|
||||
SkASSERT(value.fType == SkType_String);
|
||||
SkString* string = value.fOperand.fString;
|
||||
switch(index) {
|
||||
case SK_PROPERTY(target): {
|
||||
fEvent.setType("user");
|
||||
fEvent.setString("id", *string);
|
||||
mode = kImmediate;
|
||||
} break;
|
||||
case SK_PROPERTY(type):
|
||||
fEvent.setType(*string);
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/* libs/graphics/animator/SkDisplayPost.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayPost_DEFINED
|
||||
#define SkDisplayPost_DEFINED
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkEvent.h"
|
||||
#include "SkEventSink.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkIntArray.h"
|
||||
|
||||
class SkData;
|
||||
class SkAnimateMaker;
|
||||
|
||||
class SkPost : public SkDisplayable {
|
||||
DECLARE_MEMBER_INFO(Post);
|
||||
enum Mode {
|
||||
kDeferred,
|
||||
kImmediate
|
||||
};
|
||||
SkPost();
|
||||
virtual ~SkPost();
|
||||
virtual bool add(SkAnimateMaker& , SkDisplayable* child);
|
||||
virtual bool childrenNeedDisposing() const;
|
||||
virtual void dirty();
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
virtual bool enable(SkAnimateMaker& );
|
||||
virtual bool hasEnable() const;
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
virtual void setChildHasID();
|
||||
virtual bool setProperty(int index, SkScriptValue& );
|
||||
protected:
|
||||
SkMSec delay;
|
||||
SkString sink;
|
||||
// SkBool initialized;
|
||||
Mode mode;
|
||||
SkEvent fEvent;
|
||||
SkAnimateMaker* fMaker;
|
||||
SkTDDataArray fParts;
|
||||
SkEventSinkID fSinkID;
|
||||
SkAnimateMaker* fTargetMaker;
|
||||
SkBool8 fChildHasID;
|
||||
SkBool8 fDirty;
|
||||
private:
|
||||
void findSinkID();
|
||||
friend class SkData;
|
||||
typedef SkDisplayable INHERITED;
|
||||
};
|
||||
|
||||
#endif //SkDisplayPost_DEFINED
|
||||
@@ -0,0 +1,80 @@
|
||||
/* libs/graphics/animator/SkDisplayRandom.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayRandom.h"
|
||||
#include "SkInterpolator.h"
|
||||
|
||||
enum SkDisplayRandom_Properties {
|
||||
SK_PROPERTY(random),
|
||||
SK_PROPERTY(seed)
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDisplayRandom::fInfo[] = {
|
||||
SK_MEMBER(blend, Float),
|
||||
SK_MEMBER(max, Float),
|
||||
SK_MEMBER(min, Float),
|
||||
SK_MEMBER_DYNAMIC_PROPERTY(random, Float),
|
||||
SK_MEMBER_PROPERTY(seed, Int)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDisplayRandom);
|
||||
|
||||
SkDisplayRandom::SkDisplayRandom() : blend(0), min(0), max(SK_Scalar1) {
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkDisplayRandom::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf("min=\"%g\" ", SkScalarToFloat(min));
|
||||
SkDebugf("max=\"%g\" ", SkScalarToFloat(max));
|
||||
SkDebugf("blend=\"%g\" ", SkScalarToFloat(blend));
|
||||
#else
|
||||
SkDebugf("min=\"%x\" ", min);
|
||||
SkDebugf("max=\"%x\" ", max);
|
||||
SkDebugf("blend=\"%x\" ", blend);
|
||||
#endif
|
||||
SkDebugf("/>\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkDisplayRandom::getProperty(int index, SkScriptValue* value) const {
|
||||
switch(index) {
|
||||
case SK_PROPERTY(random): {
|
||||
SkScalar random = fRandom.nextUScalar1();
|
||||
SkScalar relativeT = SkUnitCubicInterp(random, SK_Scalar1 - blend, 0, 0, SK_Scalar1 - blend);
|
||||
value->fOperand.fScalar = min + SkScalarMul(max - min, relativeT);
|
||||
value->fType = SkType_Float;
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
SkASSERT(0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDisplayRandom::setProperty(int index, SkScriptValue& value) {
|
||||
SkASSERT(index == SK_PROPERTY(seed));
|
||||
SkASSERT(value.fType == SkType_Int);
|
||||
fRandom.setSeed(value.fOperand.fS32);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/* libs/graphics/animator/SkDisplayRandom.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayRandom_DEFINED
|
||||
#define SkDisplayRandom_DEFINED
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkRandom.h"
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
class SkDisplayRandom : public SkDisplayable {
|
||||
DECLARE_DISPLAY_MEMBER_INFO(Random);
|
||||
SkDisplayRandom();
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
virtual bool getProperty(int index, SkScriptValue* value) const;
|
||||
virtual bool setProperty(int index, SkScriptValue& );
|
||||
private:
|
||||
SkScalar blend;
|
||||
SkScalar min;
|
||||
SkScalar max;
|
||||
mutable SkRandom fRandom;
|
||||
};
|
||||
|
||||
#endif // SkDisplayRandom_DEFINED
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/* libs/graphics/animator/SkDisplayScreenplay.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayScreenplay.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDisplayScreenplay::fInfo[] = {
|
||||
SK_MEMBER(time, MSec)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDisplayScreenplay);
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/* libs/graphics/animator/SkDisplayScreenplay.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayScreenplay_DEFINED
|
||||
#define SkDisplayScreenplay_DEFINED
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
|
||||
class SkDisplayScreenplay : public SkDisplayable {
|
||||
DECLARE_DISPLAY_MEMBER_INFO(Screenplay);
|
||||
SkMSec time;
|
||||
};
|
||||
|
||||
#endif // SkDisplayScreenplay_DEFINED
|
||||
@@ -0,0 +1,774 @@
|
||||
/* libs/graphics/animator/SkDisplayType.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayType.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkAnimateSet.h"
|
||||
#include "SkDisplayAdd.h"
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkDisplayBounds.h"
|
||||
#include "SkDisplayEvent.h"
|
||||
#include "SkDisplayInclude.h"
|
||||
#ifdef SK_DEBUG
|
||||
#include "SkDisplayList.h"
|
||||
#endif
|
||||
#include "SkDisplayMath.h"
|
||||
#include "SkDisplayMovie.h"
|
||||
#include "SkDisplayNumber.h"
|
||||
#include "SkDisplayPost.h"
|
||||
#include "SkDisplayRandom.h"
|
||||
#include "SkDisplayTypes.h"
|
||||
#include "SkDraw3D.h"
|
||||
#include "SkDrawBitmap.h"
|
||||
#include "SkDrawClip.h"
|
||||
#include "SkDrawDash.h"
|
||||
#include "SkDrawDiscrete.h"
|
||||
#include "SkDrawEmboss.h"
|
||||
#include "SkDrawFull.h"
|
||||
#include "SkDrawGradient.h"
|
||||
#include "SkDrawLine.h"
|
||||
#include "SkDrawMatrix.h"
|
||||
#include "SkDrawOval.h"
|
||||
#include "SkDrawPaint.h"
|
||||
#include "SkDrawPath.h"
|
||||
#include "SkDrawPoint.h"
|
||||
#include "SkDrawSaveLayer.h"
|
||||
#include "SkDrawText.h"
|
||||
#include "SkDrawTextBox.h"
|
||||
#include "SkDrawTo.h"
|
||||
#include "SkDrawTransparentShader.h"
|
||||
#include "SkDump.h"
|
||||
#include "SkExtras.h"
|
||||
#include "SkHitClear.h"
|
||||
#include "SkHitTest.h"
|
||||
#include "SkMatrixParts.h"
|
||||
#include "SkPathParts.h"
|
||||
#include "SkPostParts.h"
|
||||
#include "SkSnapshot.h"
|
||||
#include "SkTextOnPath.h"
|
||||
#include "SkTextToPath.h"
|
||||
#include "SkTSearch.h"
|
||||
|
||||
#define CASE_NEW(_class) \
|
||||
case SkType_##_class: result = new Sk##_class(); break
|
||||
#define CASE_DRAW_NEW(_class) \
|
||||
case SkType_##_class: result = new SkDraw##_class(); break
|
||||
#define CASE_DISPLAY_NEW(_class) \
|
||||
case SkType_##_class: result = new SkDisplay##_class(); break
|
||||
#ifdef SK_DEBUG
|
||||
#define CASE_DEBUG_RETURN_NIL(_class) \
|
||||
case SkType_##_class: return NULL
|
||||
#else
|
||||
#define CASE_DEBUG_RETURN_NIL(_class)
|
||||
#endif
|
||||
|
||||
|
||||
SkDisplayTypes SkDisplayType::gNewTypes = kNumberOfTypes;
|
||||
|
||||
SkDisplayable* SkDisplayType::CreateInstance(SkAnimateMaker* maker, SkDisplayTypes type) {
|
||||
SkDisplayable* result = NULL;
|
||||
switch (type) {
|
||||
// unknown
|
||||
CASE_DISPLAY_NEW(Math);
|
||||
CASE_DISPLAY_NEW(Number);
|
||||
CASE_NEW(Add);
|
||||
CASE_NEW(AddCircle);
|
||||
// addgeom
|
||||
CASE_DEBUG_RETURN_NIL(AddMode);
|
||||
CASE_NEW(AddOval);
|
||||
CASE_NEW(AddPath);
|
||||
CASE_NEW(AddRect);
|
||||
CASE_NEW(AddRoundRect);
|
||||
CASE_DEBUG_RETURN_NIL(Align);
|
||||
CASE_NEW(Animate);
|
||||
// animatebase
|
||||
CASE_NEW(Apply);
|
||||
CASE_DEBUG_RETURN_NIL(ApplyMode);
|
||||
CASE_DEBUG_RETURN_NIL(ApplyTransition);
|
||||
CASE_DISPLAY_NEW(Array);
|
||||
// argb
|
||||
// base64
|
||||
// basebitmap
|
||||
// baseclassinfo
|
||||
CASE_DRAW_NEW(Bitmap);
|
||||
// bitmapencoding
|
||||
// bitmapformat
|
||||
CASE_DRAW_NEW(BitmapShader);
|
||||
CASE_DRAW_NEW(Blur);
|
||||
CASE_DISPLAY_NEW(Boolean);
|
||||
// boundable
|
||||
CASE_DISPLAY_NEW(Bounds);
|
||||
CASE_DEBUG_RETURN_NIL(Cap);
|
||||
CASE_NEW(Clear);
|
||||
CASE_DRAW_NEW(Clip);
|
||||
CASE_NEW(Close);
|
||||
CASE_DRAW_NEW(Color);
|
||||
CASE_NEW(CubicTo);
|
||||
CASE_NEW(Dash);
|
||||
CASE_NEW(Data);
|
||||
CASE_NEW(Discrete);
|
||||
// displayable
|
||||
// drawable
|
||||
CASE_NEW(DrawTo);
|
||||
CASE_NEW(Dump);
|
||||
// dynamicstring
|
||||
CASE_DRAW_NEW(Emboss);
|
||||
CASE_DISPLAY_NEW(Event);
|
||||
CASE_DEBUG_RETURN_NIL(EventCode);
|
||||
CASE_DEBUG_RETURN_NIL(EventKind);
|
||||
CASE_DEBUG_RETURN_NIL(EventMode);
|
||||
// filltype
|
||||
// filtertype
|
||||
CASE_DISPLAY_NEW(Float);
|
||||
CASE_NEW(FromPath);
|
||||
CASE_DEBUG_RETURN_NIL(FromPathMode);
|
||||
CASE_NEW(Full);
|
||||
// gradient
|
||||
CASE_NEW(Group);
|
||||
CASE_NEW(HitClear);
|
||||
CASE_NEW(HitTest);
|
||||
CASE_NEW(Image);
|
||||
CASE_NEW(Include);
|
||||
CASE_NEW(Input);
|
||||
CASE_DISPLAY_NEW(Int);
|
||||
CASE_DEBUG_RETURN_NIL(Join);
|
||||
CASE_NEW(Line);
|
||||
CASE_NEW(LineTo);
|
||||
CASE_NEW(LinearGradient);
|
||||
CASE_DRAW_NEW(MaskFilter);
|
||||
CASE_DEBUG_RETURN_NIL(MaskFilterBlurStyle);
|
||||
// maskfilterlight
|
||||
CASE_DRAW_NEW(Matrix);
|
||||
// memberfunction
|
||||
// memberproperty
|
||||
CASE_NEW(Move);
|
||||
CASE_NEW(MoveTo);
|
||||
CASE_DISPLAY_NEW(Movie);
|
||||
// msec
|
||||
CASE_NEW(Oval);
|
||||
CASE_DRAW_NEW(Paint);
|
||||
CASE_DRAW_NEW(Path);
|
||||
// pathdirection
|
||||
CASE_DRAW_NEW(PathEffect);
|
||||
// point
|
||||
CASE_NEW(DrawPoint);
|
||||
CASE_NEW(PolyToPoly);
|
||||
CASE_NEW(Polygon);
|
||||
CASE_NEW(Polyline);
|
||||
CASE_NEW(Post);
|
||||
CASE_NEW(QuadTo);
|
||||
CASE_NEW(RCubicTo);
|
||||
CASE_NEW(RLineTo);
|
||||
CASE_NEW(RMoveTo);
|
||||
CASE_NEW(RQuadTo);
|
||||
CASE_NEW(RadialGradient);
|
||||
CASE_DISPLAY_NEW(Random);
|
||||
CASE_DRAW_NEW(Rect);
|
||||
CASE_NEW(RectToRect);
|
||||
CASE_NEW(Remove);
|
||||
CASE_NEW(Replace);
|
||||
CASE_NEW(Rotate);
|
||||
CASE_NEW(RoundRect);
|
||||
CASE_NEW(Save);
|
||||
CASE_NEW(SaveLayer);
|
||||
CASE_NEW(Scale);
|
||||
// screenplay
|
||||
CASE_NEW(Set);
|
||||
CASE_DRAW_NEW(Shader);
|
||||
CASE_NEW(Skew);
|
||||
CASE_NEW(3D_Camera);
|
||||
CASE_NEW(3D_Patch);
|
||||
// 3dpoint
|
||||
CASE_NEW(Snapshot);
|
||||
CASE_DISPLAY_NEW(String);
|
||||
// style
|
||||
CASE_NEW(Text);
|
||||
CASE_DRAW_NEW(TextBox);
|
||||
// textboxalign
|
||||
// textboxmode
|
||||
CASE_NEW(TextOnPath);
|
||||
CASE_NEW(TextToPath);
|
||||
CASE_DEBUG_RETURN_NIL(TileMode);
|
||||
CASE_NEW(Translate);
|
||||
CASE_DRAW_NEW(TransparentShader);
|
||||
CASE_DRAW_NEW(Typeface);
|
||||
CASE_DEBUG_RETURN_NIL(Xfermode);
|
||||
default:
|
||||
SkExtras** end = maker->fExtras.end();
|
||||
for (SkExtras** extraPtr = maker->fExtras.begin(); extraPtr < end; extraPtr++) {
|
||||
if ((result = (*extraPtr)->createInstance(type)) != NULL)
|
||||
return result;
|
||||
}
|
||||
SkASSERT(0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#undef CASE_NEW
|
||||
#undef CASE_DRAW_NEW
|
||||
#undef CASE_DISPLAY_NEW
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
#define CASE_GET_INFO(_class) case SkType_##_class: \
|
||||
info = Sk##_class::fInfo; infoCount = Sk##_class::fInfoCount; break
|
||||
#define CASE_GET_DRAW_INFO(_class) case SkType_##_class: \
|
||||
info = SkDraw##_class::fInfo; infoCount = SkDraw##_class::fInfoCount; break
|
||||
#define CASE_GET_DISPLAY_INFO(_class) case SkType_##_class: \
|
||||
info = SkDisplay##_class::fInfo; infoCount = SkDisplay##_class::fInfoCount; \
|
||||
break
|
||||
|
||||
const SkMemberInfo* SkDisplayType::GetMembers(SkAnimateMaker* maker,
|
||||
SkDisplayTypes type, int* infoCountPtr) {
|
||||
const SkMemberInfo* info = NULL;
|
||||
int infoCount = 0;
|
||||
switch (type) {
|
||||
// unknown
|
||||
CASE_GET_DISPLAY_INFO(Math);
|
||||
CASE_GET_DISPLAY_INFO(Number);
|
||||
CASE_GET_INFO(Add);
|
||||
CASE_GET_INFO(AddCircle);
|
||||
CASE_GET_INFO(AddGeom);
|
||||
// addmode
|
||||
CASE_GET_INFO(AddOval);
|
||||
CASE_GET_INFO(AddPath);
|
||||
CASE_GET_INFO(AddRect);
|
||||
CASE_GET_INFO(AddRoundRect);
|
||||
// align
|
||||
CASE_GET_INFO(Animate);
|
||||
CASE_GET_INFO(AnimateBase);
|
||||
CASE_GET_INFO(Apply);
|
||||
// applymode
|
||||
// applytransition
|
||||
CASE_GET_DISPLAY_INFO(Array);
|
||||
// argb
|
||||
// base64
|
||||
CASE_GET_INFO(BaseBitmap);
|
||||
// baseclassinfo
|
||||
CASE_GET_DRAW_INFO(Bitmap);
|
||||
// bitmapencoding
|
||||
// bitmapformat
|
||||
CASE_GET_DRAW_INFO(BitmapShader);
|
||||
CASE_GET_DRAW_INFO(Blur);
|
||||
CASE_GET_DISPLAY_INFO(Boolean);
|
||||
// boundable
|
||||
CASE_GET_DISPLAY_INFO(Bounds);
|
||||
// cap
|
||||
// clear
|
||||
CASE_GET_DRAW_INFO(Clip);
|
||||
// close
|
||||
CASE_GET_DRAW_INFO(Color);
|
||||
CASE_GET_INFO(CubicTo);
|
||||
CASE_GET_INFO(Dash);
|
||||
CASE_GET_INFO(Data);
|
||||
CASE_GET_INFO(Discrete);
|
||||
// displayable
|
||||
// drawable
|
||||
CASE_GET_INFO(DrawTo);
|
||||
CASE_GET_INFO(Dump);
|
||||
// dynamicstring
|
||||
CASE_GET_DRAW_INFO(Emboss);
|
||||
CASE_GET_DISPLAY_INFO(Event);
|
||||
// eventcode
|
||||
// eventkind
|
||||
// eventmode
|
||||
// filltype
|
||||
// filtertype
|
||||
CASE_GET_DISPLAY_INFO(Float);
|
||||
CASE_GET_INFO(FromPath);
|
||||
// frompathmode
|
||||
// full
|
||||
CASE_GET_INFO(Gradient);
|
||||
CASE_GET_INFO(Group);
|
||||
CASE_GET_INFO(HitClear);
|
||||
CASE_GET_INFO(HitTest);
|
||||
CASE_GET_INFO(Image);
|
||||
CASE_GET_INFO(Include);
|
||||
CASE_GET_INFO(Input);
|
||||
CASE_GET_DISPLAY_INFO(Int);
|
||||
// join
|
||||
CASE_GET_INFO(Line);
|
||||
CASE_GET_INFO(LineTo);
|
||||
CASE_GET_INFO(LinearGradient);
|
||||
// maskfilter
|
||||
// maskfilterblurstyle
|
||||
// maskfilterlight
|
||||
CASE_GET_DRAW_INFO(Matrix);
|
||||
// memberfunction
|
||||
// memberproperty
|
||||
CASE_GET_INFO(Move);
|
||||
CASE_GET_INFO(MoveTo);
|
||||
CASE_GET_DISPLAY_INFO(Movie);
|
||||
// msec
|
||||
CASE_GET_INFO(Oval);
|
||||
CASE_GET_DRAW_INFO(Path);
|
||||
CASE_GET_DRAW_INFO(Paint);
|
||||
// pathdirection
|
||||
// patheffect
|
||||
case SkType_Point: info = Sk_Point::fInfo; infoCount = Sk_Point::fInfoCount; break; // no virtual flavor
|
||||
CASE_GET_INFO(DrawPoint); // virtual flavor
|
||||
CASE_GET_INFO(PolyToPoly);
|
||||
CASE_GET_INFO(Polygon);
|
||||
CASE_GET_INFO(Polyline);
|
||||
CASE_GET_INFO(Post);
|
||||
CASE_GET_INFO(QuadTo);
|
||||
CASE_GET_INFO(RCubicTo);
|
||||
CASE_GET_INFO(RLineTo);
|
||||
CASE_GET_INFO(RMoveTo);
|
||||
CASE_GET_INFO(RQuadTo);
|
||||
CASE_GET_INFO(RadialGradient);
|
||||
CASE_GET_DISPLAY_INFO(Random);
|
||||
CASE_GET_DRAW_INFO(Rect);
|
||||
CASE_GET_INFO(RectToRect);
|
||||
CASE_GET_INFO(Remove);
|
||||
CASE_GET_INFO(Replace);
|
||||
CASE_GET_INFO(Rotate);
|
||||
CASE_GET_INFO(RoundRect);
|
||||
CASE_GET_INFO(Save);
|
||||
CASE_GET_INFO(SaveLayer);
|
||||
CASE_GET_INFO(Scale);
|
||||
// screenplay
|
||||
CASE_GET_INFO(Set);
|
||||
CASE_GET_DRAW_INFO(Shader);
|
||||
CASE_GET_INFO(Skew);
|
||||
CASE_GET_INFO(3D_Camera);
|
||||
CASE_GET_INFO(3D_Patch);
|
||||
CASE_GET_INFO(3D_Point);
|
||||
CASE_GET_INFO(Snapshot);
|
||||
CASE_GET_DISPLAY_INFO(String);
|
||||
// style
|
||||
CASE_GET_INFO(Text);
|
||||
CASE_GET_DRAW_INFO(TextBox);
|
||||
// textboxalign
|
||||
// textboxmode
|
||||
CASE_GET_INFO(TextOnPath);
|
||||
CASE_GET_INFO(TextToPath);
|
||||
// tilemode
|
||||
CASE_GET_INFO(Translate);
|
||||
// transparentshader
|
||||
CASE_GET_DRAW_INFO(Typeface);
|
||||
// xfermode
|
||||
// knumberoftypes
|
||||
default:
|
||||
if (maker) {
|
||||
SkExtras** end = maker->fExtras.end();
|
||||
for (SkExtras** extraPtr = maker->fExtras.begin(); extraPtr < end; extraPtr++) {
|
||||
if ((info = (*extraPtr)->getMembers(type, infoCountPtr)) != NULL)
|
||||
return info;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
if (infoCountPtr)
|
||||
*infoCountPtr = infoCount;
|
||||
return info;
|
||||
}
|
||||
|
||||
const SkMemberInfo* SkDisplayType::GetMember(SkAnimateMaker* maker,
|
||||
SkDisplayTypes type, const char** matchPtr ) {
|
||||
int infoCount;
|
||||
const SkMemberInfo* info = GetMembers(maker, type, &infoCount);
|
||||
info = SkMemberInfo::Find(info, infoCount, matchPtr);
|
||||
// SkASSERT(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
#undef CASE_GET_INFO
|
||||
#undef CASE_GET_DRAW_INFO
|
||||
#undef CASE_GET_DISPLAY_INFO
|
||||
|
||||
#endif // SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
#if defined SK_DEBUG || defined SK_BUILD_CONDENSED
|
||||
#define DRAW_NAME(_name, _type) {_name, _type, true, false }
|
||||
#define DISPLAY_NAME(_name, _type) {_name, _type, false, true }
|
||||
#define INIT_BOOL_FIELDS , false, false
|
||||
#else
|
||||
#define DRAW_NAME(_name, _type) {_name, _type }
|
||||
#define DISPLAY_NAME(_name, _type) {_name, _type }
|
||||
#define INIT_BOOL_FIELDS
|
||||
#endif
|
||||
|
||||
const TypeNames gTypeNames[] = {
|
||||
// unknown
|
||||
{ "Math", SkType_Math INIT_BOOL_FIELDS },
|
||||
{ "Number", SkType_Number INIT_BOOL_FIELDS },
|
||||
{ "add", SkType_Add INIT_BOOL_FIELDS },
|
||||
{ "addCircle", SkType_AddCircle INIT_BOOL_FIELDS },
|
||||
// addgeom
|
||||
// addmode
|
||||
{ "addOval", SkType_AddOval INIT_BOOL_FIELDS },
|
||||
{ "addPath", SkType_AddPath INIT_BOOL_FIELDS },
|
||||
{ "addRect", SkType_AddRect INIT_BOOL_FIELDS },
|
||||
{ "addRoundRect", SkType_AddRoundRect INIT_BOOL_FIELDS },
|
||||
// align
|
||||
{ "animate", SkType_Animate INIT_BOOL_FIELDS },
|
||||
// animateBase
|
||||
{ "apply", SkType_Apply INIT_BOOL_FIELDS },
|
||||
// applymode
|
||||
// applytransition
|
||||
{ "array", SkType_Array INIT_BOOL_FIELDS },
|
||||
// argb
|
||||
// base64
|
||||
// basebitmap
|
||||
// baseclassinfo
|
||||
DRAW_NAME("bitmap", SkType_Bitmap),
|
||||
// bitmapencoding
|
||||
// bitmapformat
|
||||
DRAW_NAME("bitmapShader", SkType_BitmapShader),
|
||||
DRAW_NAME("blur", SkType_Blur),
|
||||
{ "boolean", SkType_Boolean INIT_BOOL_FIELDS },
|
||||
// boundable
|
||||
DISPLAY_NAME("bounds", SkType_Bounds),
|
||||
// cap
|
||||
{ "clear", SkType_Clear INIT_BOOL_FIELDS },
|
||||
DRAW_NAME("clip", SkType_Clip),
|
||||
{ "close", SkType_Close INIT_BOOL_FIELDS },
|
||||
DRAW_NAME("color", SkType_Color),
|
||||
{ "cubicTo", SkType_CubicTo INIT_BOOL_FIELDS },
|
||||
{ "dash", SkType_Dash INIT_BOOL_FIELDS },
|
||||
{ "data", SkType_Data INIT_BOOL_FIELDS },
|
||||
{ "discrete", SkType_Discrete INIT_BOOL_FIELDS },
|
||||
// displayable
|
||||
// drawable
|
||||
{ "drawTo", SkType_DrawTo INIT_BOOL_FIELDS },
|
||||
{ "dump", SkType_Dump INIT_BOOL_FIELDS },
|
||||
// dynamicstring
|
||||
DRAW_NAME("emboss", SkType_Emboss),
|
||||
DISPLAY_NAME("event", SkType_Event),
|
||||
// eventcode
|
||||
// eventkind
|
||||
// eventmode
|
||||
// filltype
|
||||
// filtertype
|
||||
{ "float", SkType_Float INIT_BOOL_FIELDS },
|
||||
{ "fromPath", SkType_FromPath INIT_BOOL_FIELDS },
|
||||
// frompathmode
|
||||
{ "full", SkType_Full INIT_BOOL_FIELDS },
|
||||
// gradient
|
||||
{ "group", SkType_Group INIT_BOOL_FIELDS },
|
||||
{ "hitClear", SkType_HitClear INIT_BOOL_FIELDS },
|
||||
{ "hitTest", SkType_HitTest INIT_BOOL_FIELDS },
|
||||
{ "image", SkType_Image INIT_BOOL_FIELDS },
|
||||
{ "include", SkType_Include INIT_BOOL_FIELDS },
|
||||
{ "input", SkType_Input INIT_BOOL_FIELDS },
|
||||
{ "int", SkType_Int INIT_BOOL_FIELDS },
|
||||
// join
|
||||
{ "line", SkType_Line INIT_BOOL_FIELDS },
|
||||
{ "lineTo", SkType_LineTo INIT_BOOL_FIELDS },
|
||||
{ "linearGradient", SkType_LinearGradient INIT_BOOL_FIELDS },
|
||||
{ "maskFilter", SkType_MaskFilter INIT_BOOL_FIELDS },
|
||||
// maskfilterblurstyle
|
||||
// maskfilterlight
|
||||
DRAW_NAME("matrix", SkType_Matrix),
|
||||
// memberfunction
|
||||
// memberproperty
|
||||
{ "move", SkType_Move INIT_BOOL_FIELDS },
|
||||
{ "moveTo", SkType_MoveTo INIT_BOOL_FIELDS },
|
||||
{ "movie", SkType_Movie INIT_BOOL_FIELDS },
|
||||
// msec
|
||||
{ "oval", SkType_Oval INIT_BOOL_FIELDS },
|
||||
DRAW_NAME("paint", SkType_Paint),
|
||||
DRAW_NAME("path", SkType_Path),
|
||||
// pathdirection
|
||||
{ "pathEffect", SkType_PathEffect INIT_BOOL_FIELDS },
|
||||
// point
|
||||
DRAW_NAME("point", SkType_DrawPoint),
|
||||
{ "polyToPoly", SkType_PolyToPoly INIT_BOOL_FIELDS },
|
||||
{ "polygon", SkType_Polygon INIT_BOOL_FIELDS },
|
||||
{ "polyline", SkType_Polyline INIT_BOOL_FIELDS },
|
||||
{ "post", SkType_Post INIT_BOOL_FIELDS },
|
||||
{ "quadTo", SkType_QuadTo INIT_BOOL_FIELDS },
|
||||
{ "rCubicTo", SkType_RCubicTo INIT_BOOL_FIELDS },
|
||||
{ "rLineTo", SkType_RLineTo INIT_BOOL_FIELDS },
|
||||
{ "rMoveTo", SkType_RMoveTo INIT_BOOL_FIELDS },
|
||||
{ "rQuadTo", SkType_RQuadTo INIT_BOOL_FIELDS },
|
||||
{ "radialGradient", SkType_RadialGradient INIT_BOOL_FIELDS },
|
||||
DISPLAY_NAME("random", SkType_Random),
|
||||
{ "rect", SkType_Rect INIT_BOOL_FIELDS },
|
||||
{ "rectToRect", SkType_RectToRect INIT_BOOL_FIELDS },
|
||||
{ "remove", SkType_Remove INIT_BOOL_FIELDS },
|
||||
{ "replace", SkType_Replace INIT_BOOL_FIELDS },
|
||||
{ "rotate", SkType_Rotate INIT_BOOL_FIELDS },
|
||||
{ "roundRect", SkType_RoundRect INIT_BOOL_FIELDS },
|
||||
{ "save", SkType_Save INIT_BOOL_FIELDS },
|
||||
{ "saveLayer", SkType_SaveLayer INIT_BOOL_FIELDS },
|
||||
{ "scale", SkType_Scale INIT_BOOL_FIELDS },
|
||||
// screenplay
|
||||
{ "set", SkType_Set INIT_BOOL_FIELDS },
|
||||
{ "shader", SkType_Shader INIT_BOOL_FIELDS },
|
||||
{ "skew", SkType_Skew INIT_BOOL_FIELDS },
|
||||
{ "skia3d:camera", SkType_3D_Camera INIT_BOOL_FIELDS },
|
||||
{ "skia3d:patch", SkType_3D_Patch INIT_BOOL_FIELDS },
|
||||
// point
|
||||
{ "snapshot", SkType_Snapshot INIT_BOOL_FIELDS },
|
||||
{ "string", SkType_String INIT_BOOL_FIELDS },
|
||||
// style
|
||||
{ "text", SkType_Text INIT_BOOL_FIELDS },
|
||||
{ "textBox", SkType_TextBox INIT_BOOL_FIELDS },
|
||||
// textboxalign
|
||||
// textboxmode
|
||||
{ "textOnPath", SkType_TextOnPath INIT_BOOL_FIELDS },
|
||||
{ "textToPath", SkType_TextToPath INIT_BOOL_FIELDS },
|
||||
// tilemode
|
||||
{ "translate", SkType_Translate INIT_BOOL_FIELDS },
|
||||
DRAW_NAME("transparentShader", SkType_TransparentShader),
|
||||
{ "typeface", SkType_Typeface INIT_BOOL_FIELDS }
|
||||
// xfermode
|
||||
// knumberoftypes
|
||||
};
|
||||
|
||||
const int kTypeNamesSize = SK_ARRAY_COUNT(gTypeNames);
|
||||
|
||||
SkDisplayTypes SkDisplayType::Find(SkAnimateMaker* maker, const SkMemberInfo* match) {
|
||||
for (int index = 0; index < kTypeNamesSize; index++) {
|
||||
SkDisplayTypes type = gTypeNames[index].fType;
|
||||
const SkMemberInfo* info = SkDisplayType::GetMembers(maker, type, NULL);
|
||||
if (info == match)
|
||||
return type;
|
||||
}
|
||||
return (SkDisplayTypes) -1;
|
||||
}
|
||||
|
||||
// !!! optimize this by replacing function with a byte-sized lookup table
|
||||
SkDisplayTypes SkDisplayType::GetParent(SkAnimateMaker* maker, SkDisplayTypes base) {
|
||||
if (base == SkType_Group || base == SkType_Save || base == SkType_SaveLayer) //!!! cheat a little until we have a lookup table
|
||||
return SkType_Displayable;
|
||||
if (base == SkType_Set)
|
||||
return SkType_Animate; // another cheat until we have a lookup table
|
||||
const SkMemberInfo* info = GetMembers(maker, base, NULL); // get info for this type
|
||||
SkASSERT(info);
|
||||
if (info->fType != SkType_BaseClassInfo)
|
||||
return SkType_Unknown; // if no base, done
|
||||
// !!! could change SK_MEMBER_INHERITED macro to take type, stuff in offset, so that
|
||||
// this (and table builder) could know type without the following steps:
|
||||
const SkMemberInfo* inherited = info->getInherited();
|
||||
SkDisplayTypes result = (SkDisplayTypes) (SkType_Unknown + 1);
|
||||
for (; result <= SkType_Xfermode; result = (SkDisplayTypes) (result + 1)) {
|
||||
const SkMemberInfo* match = GetMembers(maker, result, NULL);
|
||||
if (match == inherited)
|
||||
break;
|
||||
}
|
||||
SkASSERT(result <= SkType_Xfermode);
|
||||
return result;
|
||||
}
|
||||
|
||||
SkDisplayTypes SkDisplayType::GetType(SkAnimateMaker* maker, const char match[], size_t len ) {
|
||||
int index = SkStrSearch(&gTypeNames[0].fName, kTypeNamesSize, match,
|
||||
len, sizeof(gTypeNames[0]));
|
||||
if (index >= 0 && index < kTypeNamesSize)
|
||||
return gTypeNames[index].fType;
|
||||
SkExtras** end = maker->fExtras.end();
|
||||
for (SkExtras** extraPtr = maker->fExtras.begin(); extraPtr < end; extraPtr++) {
|
||||
SkDisplayTypes result = (*extraPtr)->getType(match, len);
|
||||
if (result != SkType_Unknown)
|
||||
return result;
|
||||
}
|
||||
return (SkDisplayTypes) -1;
|
||||
}
|
||||
|
||||
bool SkDisplayType::IsEnum(SkAnimateMaker* , SkDisplayTypes type) {
|
||||
switch (type) {
|
||||
case SkType_AddMode:
|
||||
case SkType_Align:
|
||||
case SkType_ApplyMode:
|
||||
case SkType_ApplyTransition:
|
||||
case SkType_BitmapEncoding:
|
||||
case SkType_BitmapFormat:
|
||||
case SkType_Boolean:
|
||||
case SkType_Cap:
|
||||
case SkType_EventCode:
|
||||
case SkType_EventKind:
|
||||
case SkType_EventMode:
|
||||
case SkType_FillType:
|
||||
case SkType_FilterType:
|
||||
case SkType_FontStyle:
|
||||
case SkType_FromPathMode:
|
||||
case SkType_Join:
|
||||
case SkType_MaskFilterBlurStyle:
|
||||
case SkType_PathDirection:
|
||||
case SkType_Style:
|
||||
case SkType_TextBoxAlign:
|
||||
case SkType_TextBoxMode:
|
||||
case SkType_TileMode:
|
||||
case SkType_Xfermode:
|
||||
return true;
|
||||
default: // to avoid warnings
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDisplayType::IsDisplayable(SkAnimateMaker* , SkDisplayTypes type) {
|
||||
switch (type) {
|
||||
case SkType_Add:
|
||||
case SkType_AddCircle:
|
||||
case SkType_AddOval:
|
||||
case SkType_AddPath:
|
||||
case SkType_AddRect:
|
||||
case SkType_AddRoundRect:
|
||||
case SkType_Animate:
|
||||
case SkType_AnimateBase:
|
||||
case SkType_Apply:
|
||||
case SkType_BaseBitmap:
|
||||
case SkType_Bitmap:
|
||||
case SkType_BitmapShader:
|
||||
case SkType_Blur:
|
||||
case SkType_Clear:
|
||||
case SkType_Clip:
|
||||
case SkType_Close:
|
||||
case SkType_Color:
|
||||
case SkType_CubicTo:
|
||||
case SkType_Dash:
|
||||
case SkType_Data:
|
||||
case SkType_Discrete:
|
||||
case SkType_Displayable:
|
||||
case SkType_Drawable:
|
||||
case SkType_DrawTo:
|
||||
case SkType_Emboss:
|
||||
case SkType_Event:
|
||||
case SkType_FromPath:
|
||||
case SkType_Full:
|
||||
case SkType_Group:
|
||||
case SkType_Image:
|
||||
case SkType_Input:
|
||||
case SkType_Line:
|
||||
case SkType_LineTo:
|
||||
case SkType_LinearGradient:
|
||||
case SkType_Matrix:
|
||||
case SkType_Move:
|
||||
case SkType_MoveTo:
|
||||
case SkType_Movie:
|
||||
case SkType_Oval:
|
||||
case SkType_Paint:
|
||||
case SkType_Path:
|
||||
case SkType_PolyToPoly:
|
||||
case SkType_Polygon:
|
||||
case SkType_Polyline:
|
||||
case SkType_Post:
|
||||
case SkType_QuadTo:
|
||||
case SkType_RCubicTo:
|
||||
case SkType_RLineTo:
|
||||
case SkType_RMoveTo:
|
||||
case SkType_RQuadTo:
|
||||
case SkType_RadialGradient:
|
||||
case SkType_Random:
|
||||
case SkType_Rect:
|
||||
case SkType_RectToRect:
|
||||
case SkType_Remove:
|
||||
case SkType_Replace:
|
||||
case SkType_Rotate:
|
||||
case SkType_RoundRect:
|
||||
case SkType_Save:
|
||||
case SkType_SaveLayer:
|
||||
case SkType_Scale:
|
||||
case SkType_Set:
|
||||
case SkType_Shader:
|
||||
case SkType_Skew:
|
||||
case SkType_3D_Camera:
|
||||
case SkType_3D_Patch:
|
||||
case SkType_Snapshot:
|
||||
case SkType_Text:
|
||||
case SkType_TextBox:
|
||||
case SkType_TextOnPath:
|
||||
case SkType_TextToPath:
|
||||
case SkType_Translate:
|
||||
case SkType_TransparentShader:
|
||||
return true;
|
||||
default: // to avoid warnings
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDisplayType::IsStruct(SkAnimateMaker* , SkDisplayTypes type) {
|
||||
switch (type) {
|
||||
case SkType_Point:
|
||||
case SkType_3D_Point:
|
||||
return true;
|
||||
default: // to avoid warnings
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
SkDisplayTypes SkDisplayType::RegisterNewType() {
|
||||
gNewTypes = (SkDisplayTypes) (gNewTypes + 1);
|
||||
return gNewTypes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
const char* SkDisplayType::GetName(SkAnimateMaker* maker, SkDisplayTypes type) {
|
||||
for (int index = 0; index < kTypeNamesSize - 1; index++) {
|
||||
if (gTypeNames[index].fType == type)
|
||||
return gTypeNames[index].fName;
|
||||
}
|
||||
SkExtras** end = maker->fExtras.end();
|
||||
for (SkExtras** extraPtr = maker->fExtras.begin(); extraPtr < end; extraPtr++) {
|
||||
const char* result = (*extraPtr)->getName(type);
|
||||
if (result != NULL)
|
||||
return result;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SK_SUPPORT_UNITTEST
|
||||
void SkDisplayType::UnitTest() {
|
||||
SkAnimator animator;
|
||||
SkAnimateMaker* maker = animator.fMaker;
|
||||
int index;
|
||||
for (index = 0; index < kTypeNamesSize - 1; index++) {
|
||||
SkASSERT(strcmp(gTypeNames[index].fName, gTypeNames[index + 1].fName) < 0);
|
||||
SkASSERT(gTypeNames[index].fType < gTypeNames[index + 1].fType);
|
||||
}
|
||||
for (index = 0; index < kTypeNamesSize; index++) {
|
||||
SkDisplayable* test = CreateInstance(maker, gTypeNames[index].fType);
|
||||
if (test == NULL)
|
||||
continue;
|
||||
#if defined _WIN32 && _MSC_VER >= 1300 && defined _INC_CRTDBG // only on windows, only if using "crtdbg.h"
|
||||
// we know that crtdbg puts 0xfdfdfdfd at the end of the block
|
||||
// look for unitialized memory, signature 0xcdcdcdcd prior to that
|
||||
int* start = (int*) test;
|
||||
while (*start != 0xfdfdfdfd) {
|
||||
SkASSERT(*start != 0xcdcdcdcd);
|
||||
start++;
|
||||
}
|
||||
#endif
|
||||
delete test;
|
||||
}
|
||||
for (index = 0; index < kTypeNamesSize; index++) {
|
||||
int infoCount;
|
||||
const SkMemberInfo* info = GetMembers(maker, gTypeNames[index].fType, &infoCount);
|
||||
if (info == NULL)
|
||||
continue;
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
for (int inner = 0; inner < infoCount - 1; inner++) {
|
||||
if (info[inner].fType == SkType_BaseClassInfo)
|
||||
continue;
|
||||
SkASSERT(strcmp(info[inner].fName, info[inner + 1].fName) < 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#if defined SK_DEBUG || defined SK_BUILD_CONDENSED
|
||||
BuildCondensedInfo(maker);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,216 @@
|
||||
/* libs/graphics/animator/SkDisplayType.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayType_DEFINED
|
||||
#define SkDisplayType_DEFINED
|
||||
|
||||
#include "SkMath.h"
|
||||
#include "SkScalar.h"
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
#define SK_DUMP_ENABLED
|
||||
#endif
|
||||
#ifdef SK_BUILD_FOR_MAC
|
||||
#define SK_FIND_LEAKS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define SK_LITERAL_STR_EQUAL(str, token, len) (sizeof(str) - 1 == len \
|
||||
&& strncmp(str, token, sizeof(str) - 1) == 0)
|
||||
|
||||
class SkAnimateMaker;
|
||||
class SkDisplayable;
|
||||
struct SkMemberInfo;
|
||||
|
||||
enum SkDisplayTypes {
|
||||
SkType_Unknown,
|
||||
SkType_Math, // for ecmascript compatible Math functions and constants
|
||||
SkType_Number, // for for ecmascript compatible Number functions and constants
|
||||
SkType_Add,
|
||||
SkType_AddCircle,
|
||||
SkType_AddGeom,
|
||||
SkType_AddMode,
|
||||
SkType_AddOval,
|
||||
SkType_AddPath,
|
||||
SkType_AddRect, // path part
|
||||
SkType_AddRoundRect,
|
||||
SkType_Align,
|
||||
SkType_Animate,
|
||||
SkType_AnimateBase, // base type for animate, set
|
||||
SkType_Apply,
|
||||
SkType_ApplyMode,
|
||||
SkType_ApplyTransition,
|
||||
SkType_Array,
|
||||
SkType_ARGB,
|
||||
SkType_Base64,
|
||||
SkType_BaseBitmap,
|
||||
SkType_BaseClassInfo,
|
||||
SkType_Bitmap,
|
||||
SkType_BitmapEncoding,
|
||||
SkType_BitmapFormat,
|
||||
SkType_BitmapShader,
|
||||
SkType_Blur,
|
||||
SkType_Boolean, // can have values -1 (uninitialized), 0, 1
|
||||
SkType_Boundable,
|
||||
SkType_Bounds,
|
||||
SkType_Cap,
|
||||
SkType_Clear,
|
||||
SkType_Clip,
|
||||
SkType_Close,
|
||||
SkType_Color,
|
||||
SkType_CubicTo,
|
||||
SkType_Dash,
|
||||
SkType_Data,
|
||||
SkType_Discrete,
|
||||
SkType_Displayable,
|
||||
SkType_Drawable,
|
||||
SkType_DrawTo,
|
||||
SkType_Dump,
|
||||
SkType_DynamicString, // evaluate at draw time
|
||||
SkType_Emboss,
|
||||
SkType_Event,
|
||||
SkType_EventCode,
|
||||
SkType_EventKind,
|
||||
SkType_EventMode,
|
||||
SkType_FillType,
|
||||
SkType_FilterType,
|
||||
SkType_Float,
|
||||
SkType_FontStyle,
|
||||
SkType_FromPath,
|
||||
SkType_FromPathMode,
|
||||
SkType_Full,
|
||||
SkType_Gradient,
|
||||
SkType_Group,
|
||||
SkType_HitClear,
|
||||
SkType_HitTest,
|
||||
SkType_Image,
|
||||
SkType_Include,
|
||||
SkType_Input,
|
||||
SkType_Int,
|
||||
SkType_Join,
|
||||
SkType_Line, // simple line primitive
|
||||
SkType_LineTo, // used as part of path construction
|
||||
SkType_LinearGradient,
|
||||
SkType_MaskFilter,
|
||||
SkType_MaskFilterBlurStyle,
|
||||
SkType_MaskFilterLight,
|
||||
SkType_Matrix,
|
||||
SkType_MemberFunction,
|
||||
SkType_MemberProperty,
|
||||
SkType_Move,
|
||||
SkType_MoveTo,
|
||||
SkType_Movie,
|
||||
SkType_MSec,
|
||||
SkType_Oval,
|
||||
SkType_Paint,
|
||||
SkType_Path,
|
||||
SkType_PathDirection,
|
||||
SkType_PathEffect,
|
||||
SkType_Point, // used inside other structures, no vtable
|
||||
SkType_DrawPoint, // used to draw points, has a vtable
|
||||
SkType_PolyToPoly,
|
||||
SkType_Polygon,
|
||||
SkType_Polyline,
|
||||
SkType_Post,
|
||||
SkType_QuadTo,
|
||||
SkType_RCubicTo,
|
||||
SkType_RLineTo,
|
||||
SkType_RMoveTo,
|
||||
SkType_RQuadTo,
|
||||
SkType_RadialGradient,
|
||||
SkType_Random,
|
||||
SkType_Rect,
|
||||
SkType_RectToRect,
|
||||
SkType_Remove,
|
||||
SkType_Replace,
|
||||
SkType_Rotate,
|
||||
SkType_RoundRect,
|
||||
SkType_Save,
|
||||
SkType_SaveLayer,
|
||||
SkType_Scale,
|
||||
SkType_Screenplay,
|
||||
SkType_Set,
|
||||
SkType_Shader,
|
||||
SkType_Skew,
|
||||
SkType_3D_Camera,
|
||||
SkType_3D_Patch,
|
||||
SkType_3D_Point,
|
||||
SkType_Snapshot,
|
||||
SkType_String, // pointer to SkString
|
||||
SkType_Style,
|
||||
SkType_Text,
|
||||
SkType_TextBox,
|
||||
SkType_TextBoxAlign,
|
||||
SkType_TextBoxMode,
|
||||
SkType_TextOnPath,
|
||||
SkType_TextToPath,
|
||||
SkType_TileMode,
|
||||
SkType_Translate,
|
||||
SkType_TransparentShader,
|
||||
SkType_Typeface,
|
||||
SkType_Xfermode,
|
||||
kNumberOfTypes
|
||||
};
|
||||
|
||||
struct TypeNames {
|
||||
const char* fName;
|
||||
SkDisplayTypes fType;
|
||||
#if defined SK_DEBUG || defined SK_BUILD_CONDENSED
|
||||
bool fDrawPrefix;
|
||||
bool fDisplayPrefix;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
typedef SkDisplayTypes SkFunctionParamType;
|
||||
#else
|
||||
typedef unsigned char SkFunctionParamType;
|
||||
#endif
|
||||
|
||||
extern const TypeNames gTypeNames[];
|
||||
extern const int kTypeNamesSize;
|
||||
|
||||
class SkDisplayType {
|
||||
public:
|
||||
static SkDisplayTypes Find(SkAnimateMaker* , const SkMemberInfo* );
|
||||
static const SkMemberInfo* GetMember(SkAnimateMaker* , SkDisplayTypes , const char** );
|
||||
static const SkMemberInfo* GetMembers(SkAnimateMaker* , SkDisplayTypes , int* infoCountPtr);
|
||||
static SkDisplayTypes GetParent(SkAnimateMaker* , SkDisplayTypes );
|
||||
static bool IsDisplayable(SkAnimateMaker* , SkDisplayTypes );
|
||||
static bool IsEnum(SkAnimateMaker* , SkDisplayTypes );
|
||||
static bool IsStruct(SkAnimateMaker* , SkDisplayTypes );
|
||||
static SkDisplayTypes RegisterNewType();
|
||||
static SkDisplayTypes Resolve(const char[] , const SkMemberInfo** );
|
||||
#ifdef SK_DEBUG
|
||||
static bool IsAnimate(SkDisplayTypes type ) { return type == SkType_Animate ||
|
||||
type == SkType_Set; }
|
||||
static const char* GetName(SkAnimateMaker* , SkDisplayTypes );
|
||||
#endif
|
||||
#ifdef SK_SUPPORT_UNITTEST
|
||||
static void UnitTest();
|
||||
#endif
|
||||
#if defined SK_DEBUG || defined SK_BUILD_CONDENSED
|
||||
static void BuildCondensedInfo(SkAnimateMaker* );
|
||||
#endif
|
||||
static SkDisplayTypes GetType(SkAnimateMaker* , const char[] , size_t len);
|
||||
static SkDisplayable* CreateInstance(SkAnimateMaker* , SkDisplayTypes );
|
||||
private:
|
||||
static SkDisplayTypes gNewTypes;
|
||||
};
|
||||
|
||||
#endif // SkDisplayType_DEFINED
|
||||
@@ -0,0 +1,229 @@
|
||||
/* libs/graphics/animator/SkDisplayTypes.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayTypes.h"
|
||||
#include "SkAnimateBase.h"
|
||||
|
||||
bool SkDisplayDepend::canContainDependents() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkDisplayDepend::dirty() {
|
||||
SkDisplayable** last = fDependents.end();
|
||||
for (SkDisplayable** depPtr = fDependents.begin(); depPtr < last; depPtr++) {
|
||||
SkAnimateBase* animate = (SkAnimateBase* ) *depPtr;
|
||||
animate->setChanged(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Boolean
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDisplayBoolean::fInfo[] = {
|
||||
SK_MEMBER(value, Boolean)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDisplayBoolean);
|
||||
|
||||
SkDisplayBoolean::SkDisplayBoolean() : value(false) {
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkDisplayBoolean::dump(SkAnimateMaker* maker){
|
||||
dumpBase(maker);
|
||||
SkDebugf("value=\"%s\" />\n", value ? "true" : "false");
|
||||
}
|
||||
#endif
|
||||
|
||||
// int32_t
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDisplayInt::fInfo[] = {
|
||||
SK_MEMBER(value, Int)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDisplayInt);
|
||||
|
||||
SkDisplayInt::SkDisplayInt() : value(0) {
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkDisplayInt::dump(SkAnimateMaker* maker){
|
||||
dumpBase(maker);
|
||||
SkDebugf("value=\"%d\" />\n", value);
|
||||
}
|
||||
#endif
|
||||
|
||||
// SkScalar
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDisplayFloat::fInfo[] = {
|
||||
SK_MEMBER(value, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDisplayFloat);
|
||||
|
||||
SkDisplayFloat::SkDisplayFloat() : value(0) {
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkDisplayFloat::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf("value=\"%g\" />\n", SkScalarToFloat(value));
|
||||
#else
|
||||
SkDebugf("value=\"%x\" />\n", value);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// SkString
|
||||
enum SkDisplayString_Functions {
|
||||
SK_FUNCTION(slice)
|
||||
};
|
||||
|
||||
enum SkDisplayString_Properties {
|
||||
SK_PROPERTY(length)
|
||||
};
|
||||
|
||||
const SkFunctionParamType SkDisplayString::fFunctionParameters[] = {
|
||||
(SkFunctionParamType) SkType_Int, // slice
|
||||
(SkFunctionParamType) SkType_Int,
|
||||
(SkFunctionParamType) 0
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDisplayString::fInfo[] = {
|
||||
SK_MEMBER_PROPERTY(length, Int),
|
||||
SK_MEMBER_FUNCTION(slice, String),
|
||||
SK_MEMBER(value, String)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDisplayString);
|
||||
|
||||
SkDisplayString::SkDisplayString() {
|
||||
}
|
||||
|
||||
SkDisplayString::SkDisplayString(SkString& copyFrom) : value(copyFrom) {
|
||||
}
|
||||
|
||||
void SkDisplayString::executeFunction(SkDisplayable* target, int index,
|
||||
SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
|
||||
SkScriptValue* scriptValue) {
|
||||
if (scriptValue == NULL)
|
||||
return;
|
||||
SkASSERT(target == this);
|
||||
switch (index) {
|
||||
case SK_FUNCTION(slice):
|
||||
scriptValue->fType = SkType_String;
|
||||
SkASSERT(parameters[0].fType == SkType_Int);
|
||||
int start = parameters[0].fOperand.fS32;
|
||||
if (start < 0)
|
||||
start = (int) (value.size() - start);
|
||||
int end = (int) value.size();
|
||||
if (parameters.count() > 1) {
|
||||
SkASSERT(parameters[1].fType == SkType_Int);
|
||||
end = parameters[1].fOperand.fS32;
|
||||
}
|
||||
//if (end >= 0 && end < (int) value.size())
|
||||
if (end >= 0 && end <= (int) value.size())
|
||||
scriptValue->fOperand.fString = new SkString(&value.c_str()[start], end - start);
|
||||
else
|
||||
scriptValue->fOperand.fString = new SkString(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const SkFunctionParamType* SkDisplayString::getFunctionsParameters() {
|
||||
return fFunctionParameters;
|
||||
}
|
||||
|
||||
bool SkDisplayString::getProperty(int index, SkScriptValue* scriptValue) const {
|
||||
switch (index) {
|
||||
case SK_PROPERTY(length):
|
||||
scriptValue->fType = SkType_Int;
|
||||
scriptValue->fOperand.fS32 = (int32_t) value.size();
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// SkArray
|
||||
#if 0 // !!! reason enough to qualify enum with class name or move typedArray into its own file
|
||||
enum SkDisplayArray_Properties {
|
||||
SK_PROPERTY(length)
|
||||
};
|
||||
#endif
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDisplayArray::fInfo[] = {
|
||||
SK_MEMBER_PROPERTY(length, Int),
|
||||
SK_MEMBER_ARRAY(values, Unknown)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDisplayArray);
|
||||
|
||||
SkDisplayArray::SkDisplayArray() {
|
||||
}
|
||||
|
||||
SkDisplayArray::SkDisplayArray(SkTypedArray& copyFrom) : values(copyFrom) {
|
||||
|
||||
}
|
||||
|
||||
SkDisplayArray::~SkDisplayArray() {
|
||||
if (values.getType() == SkType_String) {
|
||||
for (int index = 0; index < values.count(); index++)
|
||||
delete values[index].fString;
|
||||
return;
|
||||
}
|
||||
if (values.getType() == SkType_Array) {
|
||||
for (int index = 0; index < values.count(); index++)
|
||||
delete values[index].fArray;
|
||||
}
|
||||
}
|
||||
|
||||
bool SkDisplayArray::getProperty(int index, SkScriptValue* value) const {
|
||||
switch (index) {
|
||||
case SK_PROPERTY(length):
|
||||
value->fType = SkType_Int;
|
||||
value->fOperand.fS32 = values.count();
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/* libs/graphics/animator/SkDisplayTypes.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayTypes_DEFINED
|
||||
#define SkDisplayTypes_DEFINED
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkTypedArray.h"
|
||||
|
||||
class SkOpArray; // compiled script experiment
|
||||
|
||||
|
||||
class SkDisplayDepend : public SkDisplayable {
|
||||
public:
|
||||
virtual bool canContainDependents() const;
|
||||
void addDependent(SkDisplayable* displayable) {
|
||||
if (fDependents.find(displayable) < 0)
|
||||
*fDependents.append() = displayable;
|
||||
}
|
||||
virtual void dirty();
|
||||
private:
|
||||
SkTDDisplayableArray fDependents;
|
||||
typedef SkDisplayable INHERITED;
|
||||
};
|
||||
|
||||
class SkDisplayBoolean : public SkDisplayDepend {
|
||||
DECLARE_DISPLAY_MEMBER_INFO(Boolean);
|
||||
SkDisplayBoolean();
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
SkBool value;
|
||||
friend class SkAnimatorScript;
|
||||
friend class SkAnimatorScript_Box;
|
||||
friend class SkAnimatorScript_Unbox;
|
||||
typedef SkDisplayDepend INHERITED;
|
||||
};
|
||||
|
||||
class SkDisplayInt : public SkDisplayDepend {
|
||||
DECLARE_DISPLAY_MEMBER_INFO(Int);
|
||||
SkDisplayInt();
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
private:
|
||||
int32_t value;
|
||||
friend class SkAnimatorScript;
|
||||
friend class SkAnimatorScript_Box;
|
||||
friend class SkAnimatorScript_Unbox;
|
||||
typedef SkDisplayDepend INHERITED;
|
||||
};
|
||||
|
||||
class SkDisplayFloat : public SkDisplayDepend {
|
||||
DECLARE_DISPLAY_MEMBER_INFO(Float);
|
||||
SkDisplayFloat();
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
private:
|
||||
SkScalar value;
|
||||
friend class SkAnimatorScript;
|
||||
friend class SkAnimatorScript_Box;
|
||||
friend class SkAnimatorScript_Unbox;
|
||||
typedef SkDisplayDepend INHERITED;
|
||||
};
|
||||
|
||||
class SkDisplayString : public SkDisplayDepend {
|
||||
DECLARE_DISPLAY_MEMBER_INFO(String);
|
||||
SkDisplayString();
|
||||
SkDisplayString(SkString& );
|
||||
virtual void executeFunction(SkDisplayable* , int index,
|
||||
SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
|
||||
SkScriptValue* );
|
||||
virtual const SkFunctionParamType* getFunctionsParameters();
|
||||
virtual bool getProperty(int index, SkScriptValue* ) const;
|
||||
SkString value;
|
||||
private:
|
||||
static const SkFunctionParamType fFunctionParameters[];
|
||||
};
|
||||
|
||||
class SkDisplayArray : public SkDisplayDepend {
|
||||
DECLARE_DISPLAY_MEMBER_INFO(Array);
|
||||
SkDisplayArray();
|
||||
SkDisplayArray(SkTypedArray& );
|
||||
SkDisplayArray(SkOpArray& ); // compiled script experiment
|
||||
virtual ~SkDisplayArray();
|
||||
virtual bool getProperty(int index, SkScriptValue* ) const;
|
||||
private:
|
||||
SkTypedArray values;
|
||||
friend class SkAnimator;
|
||||
friend class SkAnimatorScript;
|
||||
friend class SkAnimatorScript2;
|
||||
friend class SkAnimatorScript_Unbox;
|
||||
friend class SkDisplayable;
|
||||
friend struct SkMemberInfo;
|
||||
friend class SkScriptEngine;
|
||||
};
|
||||
|
||||
#endif // SkDisplayTypes_DEFINED
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
/* libs/graphics/animator/SkDisplayXMLParser.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayXMLParser.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkUtils.h"
|
||||
#ifdef SK_DEBUG
|
||||
#include "SkTime.h"
|
||||
#endif
|
||||
|
||||
static char const* const gErrorStrings[] = {
|
||||
"unknown error ",
|
||||
"apply scopes itself",
|
||||
"display tree too deep (circular reference?) ",
|
||||
"element missing parent ",
|
||||
"element type not allowed in parent ",
|
||||
"error adding <data> to <post> ",
|
||||
"error adding to <matrix> ",
|
||||
"error adding to <paint> ",
|
||||
"error adding to <path> ",
|
||||
"error in attribute value ",
|
||||
"error in script ",
|
||||
"expected movie in sink attribute ",
|
||||
"field not in target ",
|
||||
"number of offsets in gradient must match number of colors",
|
||||
"no offset in gradient may be greater than one",
|
||||
"last offset in gradient must be one",
|
||||
"offsets in gradient must be increasing",
|
||||
"first offset in gradient must be zero",
|
||||
"gradient attribute \"points\" must have length of four",
|
||||
"in include ",
|
||||
"in movie ",
|
||||
"include name unknown or missing ",
|
||||
"index out of range ",
|
||||
"movie name unknown or missing ",
|
||||
"no parent available to resolve sink attribute ",
|
||||
"parent element can't contain ",
|
||||
"saveLayer must specify a bounds",
|
||||
"target id not found ",
|
||||
"unexpected type "
|
||||
};
|
||||
|
||||
SkDisplayXMLParserError::~SkDisplayXMLParserError() {
|
||||
}
|
||||
|
||||
void SkDisplayXMLParserError::getErrorString(SkString* str) const {
|
||||
if (fCode > kUnknownError)
|
||||
str->set(gErrorStrings[fCode - kUnknownError]);
|
||||
else
|
||||
str->reset();
|
||||
INHERITED::getErrorString(str);
|
||||
}
|
||||
|
||||
void SkDisplayXMLParserError::setInnerError(SkAnimateMaker* parent, const SkString& src) {
|
||||
SkString inner;
|
||||
getErrorString(&inner);
|
||||
inner.prepend(": ");
|
||||
inner.prependS32(getLineNumber());
|
||||
inner.prepend(", line ");
|
||||
inner.prepend(src);
|
||||
parent->setErrorNoun(inner);
|
||||
}
|
||||
|
||||
|
||||
SkDisplayXMLParser::SkDisplayXMLParser(SkAnimateMaker& maker)
|
||||
: INHERITED(&maker.fError), fMaker(maker), fInInclude(maker.fInInclude),
|
||||
fInSkia(maker.fInInclude), fCurrDisplayable(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
SkDisplayXMLParser::~SkDisplayXMLParser() {
|
||||
if (fCurrDisplayable && fMaker.fChildren.find(fCurrDisplayable) < 0)
|
||||
delete fCurrDisplayable;
|
||||
for (Parent* parPtr = fParents.begin() + 1; parPtr < fParents.end(); parPtr++) {
|
||||
SkDisplayable* displayable = parPtr->fDisplayable;
|
||||
if (displayable == fCurrDisplayable)
|
||||
continue;
|
||||
SkASSERT(fMaker.fChildren.find(displayable) < 0);
|
||||
if (fMaker.fHelpers.find(displayable) < 0)
|
||||
delete displayable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SkDisplayXMLParser::onAddAttribute(const char name[], const char value[]) {
|
||||
return onAddAttributeLen(name, value, strlen(value));
|
||||
}
|
||||
|
||||
bool SkDisplayXMLParser::onAddAttributeLen(const char attrName[], const char attrValue[],
|
||||
size_t attrValueLen)
|
||||
{
|
||||
if (fCurrDisplayable == NULL) // this signals we should ignore attributes for this element
|
||||
return strncmp(attrName, "xmlns", sizeof("xmlns") - 1) != 0;
|
||||
SkDisplayable* displayable = fCurrDisplayable;
|
||||
SkDisplayTypes type = fCurrType;
|
||||
|
||||
if (strcmp(attrName, "id") == 0) {
|
||||
if (fMaker.find(attrValue, attrValueLen, NULL)) {
|
||||
fError->setNoun(attrValue, attrValueLen);
|
||||
fError->setCode(SkXMLParserError::kDuplicateIDs);
|
||||
return true;
|
||||
}
|
||||
#ifdef SK_DEBUG
|
||||
displayable->_id.set(attrValue, attrValueLen);
|
||||
displayable->id = displayable->_id.c_str();
|
||||
#endif
|
||||
fMaker.idsSet(attrValue, attrValueLen, displayable);
|
||||
int parentIndex = fParents.count() - 1;
|
||||
if (parentIndex > 0) {
|
||||
SkDisplayable* parent = fParents[parentIndex - 1].fDisplayable;
|
||||
parent->setChildHasID();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const char* name = attrName;
|
||||
const SkMemberInfo* info = SkDisplayType::GetMember(&fMaker, type, &name);
|
||||
if (info == NULL) {
|
||||
fError->setNoun(name);
|
||||
fError->setCode(SkXMLParserError::kUnknownAttributeName);
|
||||
return true;
|
||||
}
|
||||
if (info->setValue(fMaker, NULL, 0, info->getCount(), displayable, info->getType(), attrValue,
|
||||
attrValueLen))
|
||||
return false;
|
||||
if (fMaker.fError.hasError()) {
|
||||
fError->setNoun(attrValue, attrValueLen);
|
||||
return true;
|
||||
}
|
||||
SkDisplayable* ref = NULL;
|
||||
if (fMaker.find(attrValue, attrValueLen, &ref) == false) {
|
||||
ref = fMaker.createInstance(attrValue, attrValueLen);
|
||||
if (ref == NULL) {
|
||||
fError->setNoun(attrValue, attrValueLen);
|
||||
fError->setCode(SkXMLParserError::kErrorInAttributeValue);
|
||||
return true;
|
||||
} else
|
||||
fMaker.helperAdd(ref);
|
||||
}
|
||||
if (info->fType != SkType_MemberProperty) {
|
||||
fError->setNoun(name);
|
||||
fError->setCode(SkXMLParserError::kUnknownAttributeName);
|
||||
return true;
|
||||
}
|
||||
SkScriptValue scriptValue;
|
||||
scriptValue.fOperand.fDisplayable = ref;
|
||||
scriptValue.fType = ref->getType();
|
||||
displayable->setProperty(info->propertyIndex(), scriptValue);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDisplayXMLParser::onEndElement(const char elem[])
|
||||
{
|
||||
int parentIndex = fParents.count() - 1;
|
||||
if (parentIndex >= 0) {
|
||||
Parent& container = fParents[parentIndex];
|
||||
SkDisplayable* displayable = container.fDisplayable;
|
||||
fMaker.fEndDepth = parentIndex;
|
||||
displayable->onEndElement(fMaker);
|
||||
if (fMaker.fError.hasError())
|
||||
return true;
|
||||
if (parentIndex > 0) {
|
||||
SkDisplayable* parent = fParents[parentIndex - 1].fDisplayable;
|
||||
bool result = parent->add(fMaker, displayable);
|
||||
if (fMaker.hasError())
|
||||
return true;
|
||||
if (result == false) {
|
||||
int infoCount;
|
||||
const SkMemberInfo* info =
|
||||
SkDisplayType::GetMembers(&fMaker, fParents[parentIndex - 1].fType, &infoCount);
|
||||
const SkMemberInfo* foundInfo;
|
||||
if ((foundInfo = searchContainer(info, infoCount)) != NULL) {
|
||||
parent->setReference(foundInfo, displayable);
|
||||
// if (displayable->isHelper() == false)
|
||||
fMaker.helperAdd(displayable);
|
||||
} else {
|
||||
fMaker.setErrorCode(SkDisplayXMLParserError::kElementTypeNotAllowedInParent);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (parent->childrenNeedDisposing())
|
||||
delete displayable;
|
||||
}
|
||||
fParents.remove(parentIndex);
|
||||
}
|
||||
fCurrDisplayable = NULL;
|
||||
if (fInInclude == false && strcasecmp(elem, "screenplay") == 0) {
|
||||
if (fMaker.fInMovie == false) {
|
||||
fMaker.fEnableTime = fMaker.getAppTime();
|
||||
#if defined SK_DEBUG && defined SK_DEBUG_ANIMATION_TIMING
|
||||
if (fMaker.fDebugTimeBase == (SkMSec) -1)
|
||||
fMaker.fDebugTimeBase = fMaker.fEnableTime;
|
||||
SkString debugOut;
|
||||
SkMSec time = fMaker.getAppTime();
|
||||
debugOut.appendS32(time - fMaker.fDebugTimeBase);
|
||||
debugOut.append(" onLoad enable=");
|
||||
debugOut.appendS32(fMaker.fEnableTime - fMaker.fDebugTimeBase);
|
||||
SkDebugf("%s\n", debugOut.c_str());
|
||||
#endif
|
||||
fMaker.fEvents.doEvent(fMaker, SkDisplayEvent::kOnload, NULL);
|
||||
if (fMaker.fError.hasError())
|
||||
return true;
|
||||
fMaker.fEvents.removeEvent(SkDisplayEvent::kOnload, NULL);
|
||||
|
||||
}
|
||||
fInSkia = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDisplayXMLParser::onStartElement(const char name[])
|
||||
{
|
||||
return onStartElementLen(name, strlen(name));
|
||||
}
|
||||
|
||||
bool SkDisplayXMLParser::onStartElementLen(const char name[], size_t len) {
|
||||
fCurrDisplayable = NULL; // init so we'll ignore attributes if we exit early
|
||||
|
||||
if (strncasecmp(name, "screenplay", len) == 0) {
|
||||
fInSkia = true;
|
||||
if (fInInclude == false)
|
||||
fMaker.idsSet(name, len, &fMaker.fScreenplay);
|
||||
return false;
|
||||
}
|
||||
if (fInSkia == false)
|
||||
return false;
|
||||
|
||||
SkDisplayable* displayable = fMaker.createInstance(name, len);
|
||||
if (displayable == NULL) {
|
||||
fError->setNoun(name, len);
|
||||
fError->setCode(SkXMLParserError::kUnknownElement);
|
||||
return true;
|
||||
}
|
||||
SkDisplayTypes type = displayable->getType();
|
||||
Parent record = { displayable, type };
|
||||
*fParents.append() = record;
|
||||
if (fParents.count() == 1)
|
||||
fMaker.childrenAdd(displayable);
|
||||
else {
|
||||
Parent* parent = fParents.end() - 2;
|
||||
if (displayable->setParent(parent->fDisplayable)) {
|
||||
fError->setNoun(name, len);
|
||||
getError()->setCode(SkDisplayXMLParserError::kParentElementCantContain);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// set these for subsequent calls to addAttribute()
|
||||
fCurrDisplayable = displayable;
|
||||
fCurrType = type;
|
||||
return false;
|
||||
}
|
||||
|
||||
const SkMemberInfo* SkDisplayXMLParser::searchContainer(const SkMemberInfo* infoBase,
|
||||
int infoCount) {
|
||||
const SkMemberInfo* bestDisplayable = NULL;
|
||||
const SkMemberInfo* lastResort = NULL;
|
||||
for (int index = 0; index < infoCount; index++) {
|
||||
const SkMemberInfo* info = &infoBase[index];
|
||||
if (info->fType == SkType_BaseClassInfo) {
|
||||
const SkMemberInfo* inherited = info->getInherited();
|
||||
const SkMemberInfo* result = searchContainer(inherited, info->fCount);
|
||||
if (result != NULL)
|
||||
return result;
|
||||
continue;
|
||||
}
|
||||
Parent* container = fParents.end() - 1;
|
||||
SkDisplayTypes type = (SkDisplayTypes) info->fType;
|
||||
if (type == SkType_MemberProperty)
|
||||
type = info->propertyType();
|
||||
SkDisplayTypes containerType = container->fType;
|
||||
if (type == containerType && (type == SkType_Rect || type == SkType_Polygon ||
|
||||
type == SkType_Array || type == SkType_Int || type == SkType_Bitmap))
|
||||
goto rectNext;
|
||||
while (type != containerType) {
|
||||
if (containerType == SkType_Displayable)
|
||||
goto next;
|
||||
containerType = SkDisplayType::GetParent(&fMaker, containerType);
|
||||
if (containerType == SkType_Unknown)
|
||||
goto next;
|
||||
}
|
||||
return info;
|
||||
next:
|
||||
if (type == SkType_Drawable || type == SkType_Displayable &&
|
||||
container->fDisplayable->isDrawable()) {
|
||||
rectNext:
|
||||
if (fParents.count() > 1) {
|
||||
Parent* parent = fParents.end() - 2;
|
||||
if (info == parent->fDisplayable->preferredChild(type))
|
||||
bestDisplayable = info;
|
||||
else
|
||||
lastResort = info;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bestDisplayable)
|
||||
return bestDisplayable;
|
||||
if (lastResort)
|
||||
return lastResort;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/* libs/graphics/animator/SkDisplayXMLParser.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayXMLParser_DEFINED
|
||||
#define SkDisplayXMLParser_DEFINED
|
||||
|
||||
#include "SkIntArray.h"
|
||||
#include "SkTDict.h"
|
||||
#include "SkDisplayType.h"
|
||||
#include "SkXMLParser.h"
|
||||
|
||||
class SkAnimateMaker;
|
||||
class SkDisplayable;
|
||||
|
||||
class SkDisplayXMLParserError : public SkXMLParserError {
|
||||
public:
|
||||
enum ErrorCode {
|
||||
kApplyScopesItself = kUnknownError + 1,
|
||||
kDisplayTreeTooDeep,
|
||||
kElementMissingParent,
|
||||
kElementTypeNotAllowedInParent,
|
||||
kErrorAddingDataToPost,
|
||||
kErrorAddingToMatrix,
|
||||
kErrorAddingToPaint,
|
||||
kErrorAddingToPath,
|
||||
kErrorInAttributeValue,
|
||||
kErrorInScript,
|
||||
kExpectedMovie,
|
||||
kFieldNotInTarget,
|
||||
kGradientOffsetsDontMatchColors,
|
||||
kGradientOffsetsMustBeNoMoreThanOne,
|
||||
kGradientOffsetsMustEndWithOne,
|
||||
kGradientOffsetsMustIncrease,
|
||||
kGradientOffsetsMustStartWithZero,
|
||||
kGradientPointsLengthMustBeFour,
|
||||
kInInclude,
|
||||
kInMovie,
|
||||
kIncludeNameUnknownOrMissing,
|
||||
kIndexOutOfRange,
|
||||
kMovieNameUnknownOrMissing,
|
||||
kNoParentAvailable,
|
||||
kParentElementCantContain,
|
||||
kSaveLayerNeedsBounds,
|
||||
kTargetIDNotFound,
|
||||
kUnexpectedType
|
||||
};
|
||||
virtual ~SkDisplayXMLParserError();
|
||||
virtual void getErrorString(SkString* str) const;
|
||||
void setCode(ErrorCode code) { INHERITED::setCode((INHERITED::ErrorCode) code); }
|
||||
void setInnerError(SkAnimateMaker* maker, const SkString& str);
|
||||
typedef SkXMLParserError INHERITED;
|
||||
friend class SkDisplayXMLParser;
|
||||
};
|
||||
|
||||
class SkDisplayXMLParser : public SkXMLParser {
|
||||
public:
|
||||
SkDisplayXMLParser(SkAnimateMaker& maker);
|
||||
virtual ~SkDisplayXMLParser();
|
||||
protected:
|
||||
virtual bool onAddAttribute(const char name[], const char value[]);
|
||||
bool onAddAttributeLen(const char name[], const char value[], size_t len);
|
||||
virtual bool onEndElement(const char elem[]);
|
||||
virtual bool onStartElement(const char elem[]);
|
||||
bool onStartElementLen(const char elem[], size_t len);
|
||||
private:
|
||||
struct Parent {
|
||||
SkDisplayable* fDisplayable;
|
||||
SkDisplayTypes fType;
|
||||
};
|
||||
SkTDArray<Parent> fParents;
|
||||
SkDisplayXMLParser& operator= (const SkDisplayXMLParser& );
|
||||
SkDisplayXMLParserError* getError() { return (SkDisplayXMLParserError*) fError; }
|
||||
const SkMemberInfo* searchContainer(const SkMemberInfo* ,
|
||||
int infoCount);
|
||||
SkAnimateMaker& fMaker;
|
||||
SkBool fInInclude;
|
||||
SkBool fInSkia;
|
||||
// local state between onStartElement and onAddAttribute
|
||||
SkDisplayable* fCurrDisplayable;
|
||||
SkDisplayTypes fCurrType;
|
||||
friend class SkXMLAnimatorWriter;
|
||||
typedef SkXMLParser INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDisplayXMLParser_DEFINED
|
||||
|
||||
|
||||
@@ -0,0 +1,566 @@
|
||||
/* libs/graphics/animator/SkDisplayable.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDisplayable.h"
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkParse.h"
|
||||
#ifdef SK_DEBUG
|
||||
#include "SkDisplayList.h"
|
||||
#endif
|
||||
#include "SkDisplayTypes.h"
|
||||
|
||||
#ifdef SK_FIND_LEAKS
|
||||
// int SkDisplayable::fAllocationCount;
|
||||
SkTDDisplayableArray SkDisplayable::fAllocations;
|
||||
#endif
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
SkDisplayable::SkDisplayable() {
|
||||
id = _id.c_str();
|
||||
#ifdef SK_FIND_LEAKS
|
||||
// fAllocationCount++;
|
||||
*fAllocations.append() = this;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
SkDisplayable::~SkDisplayable() {
|
||||
#ifdef SK_FIND_LEAKS
|
||||
// fAllocationCount--;
|
||||
int index = fAllocations.find(this);
|
||||
SkASSERT(index >= 0);
|
||||
fAllocations.remove(index);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool SkDisplayable::add(SkAnimateMaker& , SkDisplayable* child) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//void SkDisplayable::apply(SkAnimateMaker& , const SkMemberInfo* ,
|
||||
// SkDisplayable* , SkScalar [], int count) {
|
||||
// SkASSERT(0);
|
||||
//}
|
||||
|
||||
bool SkDisplayable::canContainDependents() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDisplayable::childrenNeedDisposing() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkDisplayable::clearBounder() {
|
||||
}
|
||||
|
||||
bool SkDisplayable::contains(SkDisplayable* ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SkDisplayable* SkDisplayable::contains(const SkString& ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SkDisplayable* SkDisplayable::deepCopy(SkAnimateMaker* maker) {
|
||||
SkDisplayTypes type = getType();
|
||||
if (type == SkType_Unknown) {
|
||||
SkASSERT(0);
|
||||
return NULL;
|
||||
}
|
||||
SkDisplayable* copy = SkDisplayType::CreateInstance(maker, type);
|
||||
int index = -1;
|
||||
int propIndex = 0;
|
||||
const SkMemberInfo* info;
|
||||
do {
|
||||
info = copy->getMember(++index);
|
||||
if (info == NULL)
|
||||
break;
|
||||
if (info->fType == SkType_MemberProperty) {
|
||||
SkScriptValue value;
|
||||
if (getProperty(propIndex, &value))
|
||||
copy->setProperty(propIndex, value);
|
||||
propIndex++;
|
||||
continue;
|
||||
}
|
||||
if (info->fType == SkType_MemberFunction)
|
||||
continue;
|
||||
if (info->fType == SkType_Array) {
|
||||
SkTDOperandArray* array = (SkTDOperandArray*) info->memberData(this);
|
||||
int arrayCount;
|
||||
if (array == NULL || (arrayCount = array->count()) == 0)
|
||||
continue;
|
||||
SkTDOperandArray* copyArray = (SkTDOperandArray*) info->memberData(copy);
|
||||
copyArray->setCount(arrayCount);
|
||||
SkDisplayTypes elementType;
|
||||
if (type == SkType_Array) {
|
||||
SkDisplayArray* dispArray = (SkDisplayArray*) this;
|
||||
elementType = dispArray->values.getType();
|
||||
} else
|
||||
elementType = info->arrayType();
|
||||
size_t elementSize = SkMemberInfo::GetSize(elementType);
|
||||
size_t byteSize = elementSize * arrayCount;
|
||||
memcpy(copyArray->begin(), array->begin(), byteSize);
|
||||
continue;
|
||||
}
|
||||
if (SkDisplayType::IsDisplayable(maker, info->fType)) {
|
||||
SkDisplayable** displayable = (SkDisplayable**) info->memberData(this);
|
||||
if (*displayable == NULL || *displayable == (SkDisplayable*) -1)
|
||||
continue;
|
||||
SkDisplayable* deeper = (*displayable)->deepCopy(maker);
|
||||
info->setMemberData(copy, deeper, sizeof(deeper));
|
||||
continue;
|
||||
}
|
||||
if (info->fType == SkType_String || info->fType == SkType_DynamicString) {
|
||||
SkString* string;
|
||||
info->getString(this, &string);
|
||||
info->setString(copy, string);
|
||||
continue;
|
||||
}
|
||||
void* data = info->memberData(this);
|
||||
size_t size = SkMemberInfo::GetSize(info->fType);
|
||||
info->setMemberData(copy, data, size);
|
||||
} while (true);
|
||||
copy->dirty();
|
||||
return copy;
|
||||
}
|
||||
|
||||
void SkDisplayable::dirty() {
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkDisplayable::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
this->dumpAttrs(maker);
|
||||
this->dumpChildren(maker);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SkDisplayable::dumpAttrs(SkAnimateMaker* maker) {
|
||||
SkDisplayTypes type = getType();
|
||||
if (type == SkType_Unknown) {
|
||||
//SkDebugf("/>\n");
|
||||
return;
|
||||
}
|
||||
SkDisplayable* blankCopy = SkDisplayType::CreateInstance(maker, type);
|
||||
|
||||
int index = -1;
|
||||
int propIndex = 0;
|
||||
const SkMemberInfo* info;
|
||||
const SkMemberInfo* blankInfo;
|
||||
SkScriptValue value;
|
||||
SkScriptValue blankValue;
|
||||
SkOperand values[2];
|
||||
SkOperand blankValues[2];
|
||||
do {
|
||||
info = this->getMember(++index);
|
||||
if (NULL == info) {
|
||||
//SkDebugf("\n");
|
||||
break;
|
||||
}
|
||||
if (SkType_MemberProperty == info->fType) {
|
||||
if (getProperty(propIndex, &value)) {
|
||||
blankCopy->getProperty(propIndex, &blankValue);
|
||||
//last two are dummies
|
||||
dumpValues(info, value.fType, value.fOperand, blankValue.fOperand, value.fOperand, blankValue.fOperand);
|
||||
}
|
||||
|
||||
propIndex++;
|
||||
continue;
|
||||
}
|
||||
if (SkDisplayType::IsDisplayable(maker, info->fType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (info->fType == SkType_MemberFunction)
|
||||
continue;
|
||||
|
||||
|
||||
if (info->fType == SkType_Array) {
|
||||
SkTDOperandArray* array = (SkTDOperandArray*) info->memberData(this);
|
||||
int arrayCount;
|
||||
if (array == NULL || (arrayCount = array->count()) == 0)
|
||||
continue;
|
||||
SkDisplayTypes elementType;
|
||||
if (type == SkType_Array) {
|
||||
SkDisplayArray* dispArray = (SkDisplayArray*) this;
|
||||
elementType = dispArray->values.getType();
|
||||
} else
|
||||
elementType = info->arrayType();
|
||||
bool firstElem = true;
|
||||
SkDebugf("%s=\"[", info->fName);
|
||||
for (SkOperand* op = array->begin(); op < array->end(); op++) {
|
||||
if (!firstElem) SkDebugf(",");
|
||||
switch (elementType) {
|
||||
case SkType_Displayable:
|
||||
SkDebugf("%s", op->fDisplayable->id);
|
||||
break;
|
||||
case SkType_Int:
|
||||
SkDebugf("%d", op->fS32);
|
||||
break;
|
||||
case SkType_Float:
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf("%g", SkScalarToFloat(op->fScalar));
|
||||
#else
|
||||
SkDebugf("%x", op->fScalar);
|
||||
#endif
|
||||
break;
|
||||
case SkType_String:
|
||||
case SkType_DynamicString:
|
||||
SkDebugf("%s", op->fString->c_str());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
firstElem = false;
|
||||
}
|
||||
SkDebugf("]\" ");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (info->fType == SkType_String || info->fType == SkType_DynamicString) {
|
||||
SkString* string;
|
||||
info->getString(this, &string);
|
||||
if (string->isEmpty() == false)
|
||||
SkDebugf("%s=\"%s\"\t", info->fName, string->c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
blankInfo = blankCopy->getMember(index);
|
||||
int i = info->fCount;
|
||||
info->getValue(this, values, i);
|
||||
blankInfo->getValue(blankCopy, blankValues, i);
|
||||
dumpValues(info, info->fType, values[0], blankValues[0], values[1], blankValues[1]);
|
||||
} while (true);
|
||||
delete blankCopy;
|
||||
}
|
||||
|
||||
void SkDisplayable::dumpBase(SkAnimateMaker* maker) {
|
||||
SkDisplayTypes type = getType();
|
||||
const char* elementName = "(unknown)";
|
||||
if (type != SkType_Unknown && type != SkType_Screenplay)
|
||||
elementName = SkDisplayType::GetName(maker, type);
|
||||
SkDebugf("%*s", SkDisplayList::fIndent, "");
|
||||
if (SkDisplayList::fDumpIndex != 0 && SkDisplayList::fIndent == 0)
|
||||
SkDebugf("%d: ", SkDisplayList::fDumpIndex);
|
||||
SkDebugf("<%s ", elementName);
|
||||
if (strcmp(id,"") != 0)
|
||||
SkDebugf("id=\"%s\" ", id);
|
||||
}
|
||||
|
||||
void SkDisplayable::dumpChildren(SkAnimateMaker* maker, bool closedAngle) {
|
||||
|
||||
int index = -1;
|
||||
const SkMemberInfo* info;
|
||||
index = -1;
|
||||
SkDisplayList::fIndent += 4;
|
||||
do {
|
||||
info = this->getMember(++index);
|
||||
if (NULL == info) {
|
||||
break;
|
||||
}
|
||||
if (SkDisplayType::IsDisplayable(maker, info->fType)) {
|
||||
SkDisplayable** displayable = (SkDisplayable**) info->memberData(this);
|
||||
if (*displayable == NULL || *displayable == (SkDisplayable*) -1)
|
||||
continue;
|
||||
if (closedAngle == false) {
|
||||
SkDebugf(">\n");
|
||||
closedAngle = true;
|
||||
}
|
||||
(*displayable)->dump(maker);
|
||||
}
|
||||
} while (true);
|
||||
SkDisplayList::fIndent -= 4;
|
||||
if (closedAngle)
|
||||
dumpEnd(maker);
|
||||
else
|
||||
SkDebugf("/>\n");
|
||||
}
|
||||
|
||||
void SkDisplayable::dumpEnd(SkAnimateMaker* maker) {
|
||||
SkDisplayTypes type = getType();
|
||||
const char* elementName = "(unknown)";
|
||||
if (type != SkType_Unknown && type != SkType_Screenplay)
|
||||
elementName = SkDisplayType::GetName(maker, type);
|
||||
SkDebugf("%*s", SkDisplayList::fIndent, "");
|
||||
SkDebugf("</%s>\n", elementName);
|
||||
}
|
||||
|
||||
void SkDisplayable::dumpEvents() {
|
||||
}
|
||||
|
||||
void SkDisplayable::dumpValues(const SkMemberInfo* info, SkDisplayTypes type, SkOperand op, SkOperand blankOp,
|
||||
SkOperand op2, SkOperand blankOp2) {
|
||||
switch (type) {
|
||||
case SkType_BitmapEncoding:
|
||||
switch (op.fS32) {
|
||||
case 0 : SkDebugf("type=\"jpeg\" ");
|
||||
break;
|
||||
case 1 : SkDebugf("type=\"png\" ");
|
||||
break;
|
||||
default: SkDebugf("type=\"UNDEFINED\" ");
|
||||
}
|
||||
break;
|
||||
//should make this a separate case in dump attrs, rather than make dump values have a larger signature
|
||||
case SkType_Point:
|
||||
if (op.fScalar != blankOp.fScalar || op2.fScalar != blankOp.fScalar) {
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf("%s=\"[%g,%g]\" ", info->fName, SkScalarToFloat(op.fScalar), SkScalarToFloat(op2.fScalar));
|
||||
#else
|
||||
SkDebugf("%s=\"[%x,%x]\" ", info->fName, op.fScalar, op2.fScalar);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case SkType_FromPathMode:
|
||||
switch (op.fS32) {
|
||||
case 0:
|
||||
//don't want to print anything for 0, just adding it to remove it from default:
|
||||
break;
|
||||
case 1:
|
||||
SkDebugf("%s=\"%s\" ", info->fName, "angle");
|
||||
break;
|
||||
case 2:
|
||||
SkDebugf("%s=\"%s\" ", info->fName, "position");
|
||||
break;
|
||||
default:
|
||||
SkDebugf("%s=\"INVALID\" ", info->fName);
|
||||
}
|
||||
break;
|
||||
case SkType_MaskFilterBlurStyle:
|
||||
switch (op.fS32) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
SkDebugf("%s=\"%s\" ", info->fName, "solid");
|
||||
break;
|
||||
case 2:
|
||||
SkDebugf("%s=\"%s\" ", info->fName, "outer");
|
||||
break;
|
||||
case 3:
|
||||
SkDebugf("%s=\"%s\" ", info->fName, "inner");
|
||||
break;
|
||||
default:
|
||||
SkDebugf("%s=\"INVALID\" ", info->fName);
|
||||
}
|
||||
break;
|
||||
case SkType_FilterType:
|
||||
if (op.fS32 == 1)
|
||||
SkDebugf("%s=\"%s\" ", info->fName, "bilinear");
|
||||
break;
|
||||
case SkType_PathDirection:
|
||||
SkDebugf("%s=\"%s\" ", info->fName, op.fS32 == 0 ? "cw" : "ccw");
|
||||
break;
|
||||
case SkType_FillType:
|
||||
SkDebugf("%s=\"%s\" ", info->fName, op.fS32 == 0 ? "winding" : "evenOdd");
|
||||
break;
|
||||
case SkType_TileMode:
|
||||
//correct to look at the S32?
|
||||
if (op.fS32 != blankOp.fS32)
|
||||
SkDebugf("%s=\"%s\" ", info->fName, op.fS32 == 0 ? "clamp" : op.fS32 == 1 ? "repeat" : "mirror");
|
||||
break;
|
||||
case SkType_Boolean:
|
||||
if (op.fS32 != blankOp.fS32)
|
||||
SkDebugf("%s=\"%s\" ", info->fName, op.fS32 == 0 ? "false" : "true");
|
||||
break;
|
||||
case SkType_Int:
|
||||
if (op.fS32 != blankOp.fS32)
|
||||
SkDebugf(" %s=\"%d\" ", info->fName, op.fS32);
|
||||
break;
|
||||
case SkType_Float:
|
||||
if (op.fScalar != blankOp.fScalar) { //or /65536?
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf("%s=\"%g\" ", info->fName, SkScalarToFloat(op.fScalar));
|
||||
#else
|
||||
SkDebugf("%s=\"%x\" ", info->fName, op.fScalar);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case SkType_String:
|
||||
case SkType_DynamicString:
|
||||
if (op.fString->size() > 0)
|
||||
SkDebugf("%s=\"%s\" ", info->fName, op.fString->c_str());
|
||||
break;
|
||||
case SkType_MSec:
|
||||
if (op.fS32 != blankOp.fS32) {
|
||||
#ifdef SK_CAN_USE_FLOAT
|
||||
SkDebugf(" %s=\"%g\" ", info->fName, SkScalarToFloat(SkScalarDiv(op.fS32, 1000)));
|
||||
#else
|
||||
SkDebugf(" %s=\"%x\" ", info->fName, SkScalarDiv(op.fS32, 1000));
|
||||
#endif
|
||||
}
|
||||
default:
|
||||
SkDebugf("");
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool SkDisplayable::enable( SkAnimateMaker& ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkDisplayable::enableBounder() {
|
||||
}
|
||||
|
||||
void SkDisplayable::executeFunction(SkDisplayable* , int index,
|
||||
SkTDArray<SkScriptValue>& , SkDisplayTypes, SkScriptValue* ) {
|
||||
SkASSERT(0);
|
||||
}
|
||||
|
||||
void SkDisplayable::executeFunction(SkDisplayable* target,
|
||||
const SkMemberInfo* info, SkTypedArray* values, SkScriptValue* value) {
|
||||
SkTDArray<SkScriptValue> typedValues;
|
||||
for (SkOperand* op = values->begin(); op < values->end(); op++) {
|
||||
SkScriptValue temp;
|
||||
temp.fType = values->getType();
|
||||
temp.fOperand = *op;
|
||||
*typedValues.append() = temp;
|
||||
}
|
||||
executeFunction(target, info->functionIndex(), typedValues, info->getType(), value);
|
||||
}
|
||||
|
||||
void SkDisplayable::executeFunction2(SkDisplayable* , int index,
|
||||
SkOpArray* params, SkDisplayTypes, SkOperand2* ) {
|
||||
SkASSERT(0);
|
||||
}
|
||||
|
||||
void SkDisplayable::getBounds(SkRect* rect) {
|
||||
SkASSERT(rect);
|
||||
rect->fLeft = rect->fTop = SK_ScalarMax;
|
||||
rect->fRight= rect->fBottom = -SK_ScalarMax;
|
||||
}
|
||||
|
||||
const SkFunctionParamType* SkDisplayable::getFunctionsParameters() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const SkMemberInfo* SkDisplayable::getMember(int index) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const SkMemberInfo* SkDisplayable::getMember(const char name[]) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const SkFunctionParamType* SkDisplayable::getParameters(const SkMemberInfo* info,
|
||||
int* paramCount) {
|
||||
const SkFunctionParamType* params = getFunctionsParameters();
|
||||
SkASSERT(params != NULL);
|
||||
int funcIndex = info->functionIndex();
|
||||
// !!! eventually break traversing params into an external function (maybe this whole function)
|
||||
int index = funcIndex;
|
||||
int offset = 0;
|
||||
while (--index >= 0) {
|
||||
while (params[offset] != 0)
|
||||
offset++;
|
||||
offset++;
|
||||
}
|
||||
int count = 0;
|
||||
while (params[offset] != 0) {
|
||||
count++;
|
||||
offset++;
|
||||
}
|
||||
*paramCount = count;
|
||||
return ¶ms[offset - count];
|
||||
}
|
||||
|
||||
SkDisplayable* SkDisplayable::getParent() const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool SkDisplayable::getProperty(int index, SkScriptValue* ) const {
|
||||
// SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDisplayable::getProperty2(int index, SkOperand2* value) const {
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
SkDisplayTypes SkDisplayable::getType() const {
|
||||
return SkType_Unknown;
|
||||
}
|
||||
|
||||
bool SkDisplayable::hasEnable() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDisplayable::isDrawable() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkDisplayable::onEndElement(SkAnimateMaker& ) {}
|
||||
|
||||
const SkMemberInfo* SkDisplayable::preferredChild(SkDisplayTypes type) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool SkDisplayable::resolveIDs(SkAnimateMaker& maker, SkDisplayable* original, SkApply* apply) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//SkDisplayable* SkDisplayable::resolveTarget(SkAnimateMaker& ) {
|
||||
// return this;
|
||||
//}
|
||||
|
||||
void SkDisplayable::setChildHasID() {
|
||||
}
|
||||
|
||||
bool SkDisplayable::setParent(SkDisplayable* ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDisplayable::setProperty(int index, SkScriptValue& ) {
|
||||
//SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkDisplayable::setReference(const SkMemberInfo* info, SkDisplayable* displayable) {
|
||||
if (info->fType == SkType_MemberProperty) {
|
||||
SkScriptValue scriptValue;
|
||||
scriptValue.fOperand.fDisplayable = displayable;
|
||||
scriptValue.fType = displayable->getType();
|
||||
setProperty(info->propertyIndex(), scriptValue);
|
||||
} else if (info->fType == SkType_Array) {
|
||||
SkASSERT(displayable->getType() == SkType_Array);
|
||||
SkDisplayArray* dispArray = (SkDisplayArray*) displayable;
|
||||
SkTDScalarArray* array = (SkTDScalarArray* ) info->memberData(this);
|
||||
array->setCount(dispArray->values.count());
|
||||
memcpy(array->begin(), dispArray->values.begin(), dispArray->values.count() * sizeof(int));
|
||||
//
|
||||
|
||||
// !!! need a way for interpreter engine to own array
|
||||
// !!! probably need to replace all scriptable arrays with single bigger array
|
||||
// that has operand and type on every element -- or
|
||||
// when array is dirtied, need to get parent to reparse to local array
|
||||
} else {
|
||||
void* storage = info->memberData(this);
|
||||
memcpy(storage, &displayable, sizeof(SkDisplayable*));
|
||||
}
|
||||
// !!! unclear why displayable is dirtied here
|
||||
// if this is called, this breaks fromPath.xml
|
||||
// displayable->dirty();
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void SkDisplayable::validate() {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/* libs/graphics/animator/SkDisplayable.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDisplayable_DEFINED
|
||||
#define SkDisplayable_DEFINED
|
||||
|
||||
#include "SkOperand.h"
|
||||
#ifdef SK_DEBUG
|
||||
#include "SkString.h"
|
||||
#endif
|
||||
#include "SkIntArray.h"
|
||||
#include "SkRect.h"
|
||||
#include "SkTDArray.h"
|
||||
|
||||
class SkAnimateMaker;
|
||||
class SkApply;
|
||||
class SkEvents;
|
||||
struct SkMemberInfo;
|
||||
struct SkScriptValue;
|
||||
class SkOpArray; // compiled scripting experiment
|
||||
union SkOperand2; // compiled scripting experiment
|
||||
|
||||
class SkDisplayable {
|
||||
public:
|
||||
#ifdef SK_DEBUG
|
||||
SkDisplayable();
|
||||
#endif
|
||||
virtual ~SkDisplayable();
|
||||
virtual bool add(SkAnimateMaker& , SkDisplayable* child);
|
||||
virtual bool canContainDependents() const;
|
||||
virtual bool childrenNeedDisposing() const;
|
||||
virtual void clearBounder();
|
||||
virtual bool contains(SkDisplayable* );
|
||||
virtual SkDisplayable* contains(const SkString& );
|
||||
virtual SkDisplayable* deepCopy(SkAnimateMaker* );
|
||||
virtual void dirty();
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
void dumpAttrs(SkAnimateMaker* );
|
||||
void dumpBase(SkAnimateMaker* );
|
||||
void dumpChildren(SkAnimateMaker* maker, bool closedAngle = false );
|
||||
void dumpEnd(SkAnimateMaker* );
|
||||
virtual void dumpEvents();
|
||||
#endif
|
||||
virtual bool enable( SkAnimateMaker& );
|
||||
virtual void enableBounder();
|
||||
virtual void executeFunction(SkDisplayable* , int functionIndex,
|
||||
SkTDArray<SkScriptValue>& , SkDisplayTypes , SkScriptValue* );
|
||||
void executeFunction(SkDisplayable* , const SkMemberInfo* ,
|
||||
SkTypedArray* , SkScriptValue* );
|
||||
virtual void executeFunction2(SkDisplayable* , int functionIndex,
|
||||
SkOpArray* params , SkDisplayTypes , SkOperand2* ); // compiled scripting experiment
|
||||
virtual void getBounds(SkRect* );
|
||||
virtual const SkFunctionParamType* getFunctionsParameters();
|
||||
virtual const SkMemberInfo* getMember(int index);
|
||||
virtual const SkMemberInfo* getMember(const char name[]);
|
||||
const SkFunctionParamType* getParameters(const SkMemberInfo* info,
|
||||
int* paramCount);
|
||||
virtual SkDisplayable* getParent() const;
|
||||
virtual bool getProperty(int index, SkScriptValue* value) const;
|
||||
virtual bool getProperty2(int index, SkOperand2* value) const; // compiled scripting experiment
|
||||
virtual SkDisplayTypes getType() const;
|
||||
virtual bool hasEnable() const;
|
||||
bool isAnimate() const {
|
||||
SkDisplayTypes type = getType();
|
||||
return type == SkType_Animate || type == SkType_Set; }
|
||||
bool isApply() const { return getType() == SkType_Apply; }
|
||||
bool isColor() const { return getType() == SkType_Color; }
|
||||
virtual bool isDrawable() const;
|
||||
bool isGroup() const { return getType() == SkType_Group ||
|
||||
getType() == SkType_Save || getType() == SkType_DrawTo ||
|
||||
getType() == SkType_SaveLayer; }
|
||||
bool isMatrix() const { return getType() == SkType_Matrix; }
|
||||
virtual bool isPaint() const { return getType() == SkType_Paint; }
|
||||
virtual bool isPath() const { return false; }
|
||||
bool isPost() const { return getType() == SkType_Post; }
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
virtual const SkMemberInfo* preferredChild(SkDisplayTypes type);
|
||||
virtual bool resolveIDs(SkAnimateMaker& maker, SkDisplayable* original, SkApply* );
|
||||
virtual void setChildHasID();
|
||||
virtual bool setParent(SkDisplayable* );
|
||||
virtual bool setProperty(int index, SkScriptValue& );
|
||||
void setReference(const SkMemberInfo* info, SkDisplayable* ref);
|
||||
#ifdef SK_DEBUG
|
||||
bool isData() const { return getType() == SkType_Data; };
|
||||
bool isEvent() const { return getType() == SkType_Event; }
|
||||
virtual bool isMatrixPart() const { return false; }
|
||||
bool isPatch() const { return getType() == SkType_3D_Patch; }
|
||||
virtual bool isPaintPart() const { return false; }
|
||||
virtual bool isPathPart() const { return false; }
|
||||
virtual void validate();
|
||||
SkString _id;
|
||||
const char* id;
|
||||
// static int fAllocationCount;
|
||||
static SkTDDisplayableArray fAllocations;
|
||||
#else
|
||||
void validate() {}
|
||||
#endif
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
private:
|
||||
void dumpValues(const SkMemberInfo* info, SkDisplayTypes type, SkOperand op, SkOperand blankOp,
|
||||
SkOperand op2, SkOperand blankOp2);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // SkDisplayable_DEFINED
|
||||
@@ -0,0 +1,117 @@
|
||||
/* libs/graphics/animator/SkDraw3D.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDraw3D.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkTypedArray.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo Sk3D_Point::fInfo[] = {
|
||||
SK_MEMBER_ALIAS(x, fPoint.fX, Float),
|
||||
SK_MEMBER_ALIAS(y, fPoint.fY, Float),
|
||||
SK_MEMBER_ALIAS(z, fPoint.fZ, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_NO_VIRTUALS_GET_MEMBER(Sk3D_Point);
|
||||
|
||||
Sk3D_Point::Sk3D_Point() {
|
||||
fPoint.set(0, 0, 0);
|
||||
}
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo Sk3D_Camera::fInfo[] = {
|
||||
SK_MEMBER_ALIAS(axis, fCamera.fAxis, 3D_Point),
|
||||
SK_MEMBER(hackHeight, Float),
|
||||
SK_MEMBER(hackWidth, Float),
|
||||
SK_MEMBER_ALIAS(location, fCamera.fLocation, 3D_Point),
|
||||
SK_MEMBER_ALIAS(observer, fCamera.fObserver, 3D_Point),
|
||||
SK_MEMBER(patch, 3D_Patch),
|
||||
SK_MEMBER_ALIAS(zenith, fCamera.fZenith, 3D_Point),
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(Sk3D_Camera);
|
||||
|
||||
Sk3D_Camera::Sk3D_Camera() : hackWidth(0), hackHeight(0), patch(NULL) {
|
||||
}
|
||||
|
||||
Sk3D_Camera::~Sk3D_Camera() {
|
||||
}
|
||||
|
||||
bool Sk3D_Camera::draw(SkAnimateMaker& maker) {
|
||||
fCamera.update();
|
||||
SkMatrix matrix;
|
||||
fCamera.patchToMatrix(patch->fPatch, &matrix);
|
||||
matrix.preTranslate(hackWidth / 2, -hackHeight / 2);
|
||||
matrix.postTranslate(hackWidth / 2, hackHeight / 2);
|
||||
maker.fCanvas->concat(matrix);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
enum Sk3D_Patch_Functions {
|
||||
SK_FUNCTION(rotateDegrees)
|
||||
};
|
||||
|
||||
const SkFunctionParamType Sk3D_Patch::fFunctionParameters[] = {
|
||||
(SkFunctionParamType) SkType_Float,
|
||||
(SkFunctionParamType) SkType_Float,
|
||||
(SkFunctionParamType) SkType_Float,
|
||||
(SkFunctionParamType) 0 // terminator for parameter list (there may be multiple parameter lists)
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo Sk3D_Patch::fInfo[] = {
|
||||
SK_MEMBER_ALIAS(origin, fPatch.fOrigin, 3D_Point),
|
||||
SK_MEMBER_FUNCTION(rotateDegrees, Float),
|
||||
SK_MEMBER_ALIAS(u, fPatch.fU, 3D_Point),
|
||||
SK_MEMBER_ALIAS(v, fPatch.fV, 3D_Point)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(Sk3D_Patch);
|
||||
|
||||
void Sk3D_Patch::executeFunction(SkDisplayable* target, int index,
|
||||
SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
|
||||
SkScriptValue* ) {
|
||||
SkASSERT(target == this);
|
||||
switch (index) {
|
||||
case SK_FUNCTION(rotateDegrees):
|
||||
SkASSERT(parameters.count() == 3);
|
||||
SkASSERT(type == SkType_Float);
|
||||
fPatch.rotateDegrees(parameters[0].fOperand.fScalar,
|
||||
parameters[1].fOperand.fScalar, parameters[2].fOperand.fScalar);
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
const SkFunctionParamType* Sk3D_Patch::getFunctionsParameters() {
|
||||
return fFunctionParameters;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/* libs/graphics/animator/SkDraw3D.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDraw3D_DEFINED
|
||||
#define SkDraw3D_DEFINED
|
||||
|
||||
#include "SkCamera.h"
|
||||
#include "SkDrawable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
|
||||
class Sk3D_Patch;
|
||||
|
||||
struct Sk3D_Point {
|
||||
DECLARE_NO_VIRTUALS_MEMBER_INFO(3D_Point);
|
||||
Sk3D_Point();
|
||||
private:
|
||||
SkPoint3D fPoint;
|
||||
};
|
||||
|
||||
class Sk3D_Camera : public SkDrawable {
|
||||
DECLARE_MEMBER_INFO(3D_Camera);
|
||||
Sk3D_Camera();
|
||||
virtual ~Sk3D_Camera();
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
private:
|
||||
SkScalar hackWidth;
|
||||
SkScalar hackHeight;
|
||||
SkCamera3D fCamera;
|
||||
Sk3D_Patch* patch;
|
||||
};
|
||||
|
||||
class Sk3D_Patch : public SkDisplayable {
|
||||
DECLARE_MEMBER_INFO(3D_Patch);
|
||||
private:
|
||||
virtual void executeFunction(SkDisplayable* , int index,
|
||||
SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
|
||||
SkScriptValue* );
|
||||
virtual const SkFunctionParamType* getFunctionsParameters();
|
||||
SkPatch3D fPatch;
|
||||
static const SkFunctionParamType fFunctionParameters[];
|
||||
friend class Sk3D_Camera;
|
||||
};
|
||||
|
||||
#endif // SkDraw3D_DEFINED
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
/* libs/graphics/animator/SkDrawBitmap.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawBitmap.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkImageDecoder.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkStream.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkBaseBitmap::fInfo[] = {
|
||||
SK_MEMBER(x, Float),
|
||||
SK_MEMBER(y, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkBaseBitmap);
|
||||
|
||||
SkBaseBitmap::SkBaseBitmap() : x(0), y(0) {
|
||||
}
|
||||
|
||||
SkBaseBitmap::~SkBaseBitmap() {
|
||||
}
|
||||
|
||||
bool SkBaseBitmap::draw(SkAnimateMaker& maker) {
|
||||
SkBoundableAuto boundable(this, maker);
|
||||
maker.fCanvas->drawBitmap(fBitmap, x, y, maker.fPaint);
|
||||
return false;
|
||||
}
|
||||
|
||||
enum SkDrawBitmap_Properties {
|
||||
SK_PROPERTY(erase)
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawBitmap::fInfo[] = {
|
||||
SK_MEMBER_INHERITED,
|
||||
SK_MEMBER_PROPERTY(erase, ARGB),
|
||||
SK_MEMBER(format, BitmapFormat),
|
||||
SK_MEMBER(height, Int),
|
||||
SK_MEMBER(rowBytes, Int),
|
||||
SK_MEMBER(width, Int),
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawBitmap);
|
||||
|
||||
SkDrawBitmap::SkDrawBitmap() : format((SkBitmap::Config) -1), height(-1),
|
||||
rowBytes(0), width(-1), fColor(0), fColorSet(false) {
|
||||
}
|
||||
|
||||
SkDrawBitmap::~SkDrawBitmap() {
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkDrawBitmap::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
dumpAttrs(maker);
|
||||
if (fColorSet)
|
||||
SkDebugf("erase=\"argb(%d,%d,%d,%d)\" ", SkColorGetA(fColor)/255, SkColorGetR(fColor),
|
||||
SkColorGetG(fColor), SkColorGetB(fColor));
|
||||
if (rowBytes > 0)
|
||||
SkDebugf("rowBytes=\"%d\" ", rowBytes);
|
||||
const char* formatName;
|
||||
switch (format) {
|
||||
case 0: formatName = "none"; break;
|
||||
case 1: formatName = "A1"; break;
|
||||
case 2: formatName = "A8"; break;
|
||||
case 3: formatName = "Index8"; break;
|
||||
case 4: formatName = "RGB16"; break;
|
||||
case 5: formatName = "RGB32"; break;
|
||||
}
|
||||
SkDebugf("format=\"%s\" />\n", formatName);
|
||||
}
|
||||
#endif
|
||||
|
||||
void SkDrawBitmap::onEndElement(SkAnimateMaker& maker) {
|
||||
SkASSERT(format != (SkBitmap::Config) -1);
|
||||
SkASSERT(width != -1);
|
||||
SkASSERT(height != -1);
|
||||
SkASSERT(rowBytes >= 0);
|
||||
fBitmap.setConfig((SkBitmap::Config) format, width, height, rowBytes);
|
||||
fBitmap.allocPixels();
|
||||
if (fColorSet)
|
||||
fBitmap.eraseColor(fColor);
|
||||
}
|
||||
|
||||
bool SkDrawBitmap::setProperty(int index, SkScriptValue& value)
|
||||
{
|
||||
switch (index) {
|
||||
case SK_PROPERTY(erase):
|
||||
SkASSERT(value.fType == SkType_ARGB);
|
||||
fColor = value.fOperand.fS32;
|
||||
fColorSet = true;
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
enum SkImage_Properties {
|
||||
SK_PROPERTY(height),
|
||||
SK_PROPERTY(width)
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkImage::fInfo[] = {
|
||||
SK_MEMBER_INHERITED,
|
||||
SK_MEMBER(base64, Base64),
|
||||
SK_MEMBER_PROPERTY(height, Int),
|
||||
SK_MEMBER(src, String),
|
||||
SK_MEMBER_PROPERTY(width, Int)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkImage);
|
||||
|
||||
SkImage::SkImage() : fDirty(true), fUriBase(NULL) {
|
||||
base64.fData = NULL;
|
||||
base64.fLength = 0;
|
||||
}
|
||||
|
||||
SkImage::~SkImage() {
|
||||
delete[] base64.fData;
|
||||
}
|
||||
|
||||
SkDisplayable* SkImage::deepCopy(SkAnimateMaker* maker) {
|
||||
SkDisplayable* copy = INHERITED::deepCopy(maker);
|
||||
((SkImage*) copy)->fUriBase = ((SkImage*) this)->fUriBase;
|
||||
return copy;
|
||||
}
|
||||
|
||||
void SkImage::dirty() {
|
||||
fDirty = true;
|
||||
}
|
||||
|
||||
bool SkImage::draw(SkAnimateMaker& maker) {
|
||||
if (fDirty)
|
||||
resolve();
|
||||
return INHERITED::draw(maker);
|
||||
}
|
||||
|
||||
bool SkImage::getProperty(int index, SkScriptValue* value) const {
|
||||
if (fDirty)
|
||||
resolve();
|
||||
switch (index) {
|
||||
case SK_PROPERTY(height):
|
||||
value->fOperand.fS32 = fBitmap.height();
|
||||
break;
|
||||
case SK_PROPERTY(width):
|
||||
value->fOperand.fS32 = fBitmap.width();
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
value->fType = SkType_Int;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkImage::onEndElement(SkAnimateMaker& maker) {
|
||||
fUriBase = maker.fPrefix.c_str();
|
||||
}
|
||||
|
||||
void SkImage::resolve() {
|
||||
fDirty = false;
|
||||
if (base64.fData) {
|
||||
fBitmap.reset();
|
||||
SkImageDecoder::DecodeMemory(base64.fData, base64.fLength, &fBitmap);
|
||||
} else if (src.size()) {
|
||||
if (fLast.equals(src))
|
||||
return;
|
||||
fLast.set(src);
|
||||
fBitmap.reset();
|
||||
|
||||
//SkStream* stream = SkStream::GetURIStream(fUriBase, src.c_str());
|
||||
SkStream* stream = new SkFILEStream(src.c_str());
|
||||
|
||||
SkAutoTDelete<SkStream> autoDel(stream);
|
||||
SkImageDecoder::DecodeStream(stream, &fBitmap);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/* libs/graphics/animator/SkDrawBitmap.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawBitmap_DEFINED
|
||||
#define SkDrawBitmap_DEFINED
|
||||
|
||||
#include "SkBoundable.h"
|
||||
#include "SkBase64.h"
|
||||
#include "SkBitmap.h"
|
||||
// #include "SkImageDecoder.h"
|
||||
#include "SkMemberInfo.h"
|
||||
|
||||
class SkBaseBitmap : public SkBoundable {
|
||||
DECLARE_MEMBER_INFO(BaseBitmap);
|
||||
SkBaseBitmap();
|
||||
virtual ~SkBaseBitmap();
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
protected:
|
||||
SkBitmap fBitmap;
|
||||
SkScalar x;
|
||||
SkScalar y;
|
||||
private:
|
||||
friend class SkDrawTo;
|
||||
friend class SkDrawBitmapShader;
|
||||
typedef SkBoundable INHERITED;
|
||||
};
|
||||
|
||||
class SkDrawBitmap : public SkBaseBitmap {
|
||||
DECLARE_DRAW_MEMBER_INFO(Bitmap);
|
||||
SkDrawBitmap();
|
||||
virtual ~SkDrawBitmap();
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
virtual bool setProperty(int index, SkScriptValue& value);
|
||||
protected:
|
||||
int /*SkBitmap::Config*/ format;
|
||||
int32_t height;
|
||||
int32_t rowBytes;
|
||||
int32_t width;
|
||||
SkColor fColor;
|
||||
SkBool fColorSet;
|
||||
typedef SkBaseBitmap INHERITED;
|
||||
};
|
||||
|
||||
class SkImage : public SkBaseBitmap {
|
||||
DECLARE_MEMBER_INFO(Image);
|
||||
SkImage();
|
||||
virtual ~SkImage();
|
||||
virtual SkDisplayable* deepCopy(SkAnimateMaker* );
|
||||
virtual void dirty();
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
virtual bool getProperty(int index, SkScriptValue* value) const;
|
||||
virtual void onEndElement(SkAnimateMaker& maker);
|
||||
private:
|
||||
void resolve() const { (const_cast<SkImage*>(this))->resolve(); }
|
||||
void resolve();
|
||||
protected:
|
||||
SkBase64 base64;
|
||||
SkString src;
|
||||
SkString fLast; // cache of src so that stream isn't unnecessarily decoded
|
||||
SkBool fDirty;
|
||||
const char* fUriBase;
|
||||
typedef SkBaseBitmap INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDrawBitmap_DEFINED
|
||||
@@ -0,0 +1,40 @@
|
||||
/* libs/graphics/animator/SkDrawBlur.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawBlur.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawBlur::fInfo[] = {
|
||||
SK_MEMBER(blurStyle, MaskFilterBlurStyle),
|
||||
SK_MEMBER(radius, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawBlur);
|
||||
|
||||
SkDrawBlur::SkDrawBlur() : radius(-1),
|
||||
blurStyle(SkBlurMaskFilter::kNormal_BlurStyle) {
|
||||
}
|
||||
|
||||
SkMaskFilter* SkDrawBlur::getMaskFilter() {
|
||||
if (radius < 0)
|
||||
return NULL;
|
||||
return SkBlurMaskFilter::Create(radius, (SkBlurMaskFilter::BlurStyle) blurStyle);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/* libs/graphics/animator/SkDrawBlur.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawBlur_DEFINED
|
||||
#define SkDrawBlur_DEFINED
|
||||
|
||||
#include "SkPaintParts.h"
|
||||
#include "SkBlurMaskFilter.h"
|
||||
|
||||
class SkDrawBlur : public SkDrawMaskFilter {
|
||||
DECLARE_DRAW_MEMBER_INFO(Blur);
|
||||
SkDrawBlur();
|
||||
virtual SkMaskFilter* getMaskFilter();
|
||||
protected:
|
||||
SkScalar radius;
|
||||
int /*SkBlurMaskFilter::BlurStyle*/ blurStyle;
|
||||
};
|
||||
|
||||
#endif // SkDrawBlur_DEFINED
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/* libs/graphics/animator/SkDrawClip.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawClip.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkDrawRectangle.h"
|
||||
#include "SkDrawPath.h"
|
||||
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawClip::fInfo[] = {
|
||||
SK_MEMBER(path, Path),
|
||||
SK_MEMBER(rect, Rect)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawClip);
|
||||
|
||||
SkDrawClip::SkDrawClip() : rect(NULL), path(NULL) {
|
||||
}
|
||||
|
||||
bool SkDrawClip::draw(SkAnimateMaker& maker ) {
|
||||
if (rect != NULL)
|
||||
maker.fCanvas->clipRect(rect->fRect);
|
||||
else {
|
||||
SkASSERT(path != NULL);
|
||||
maker.fCanvas->clipPath(path->fPath);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/* libs/graphics/animator/SkDrawClip.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawClip_DEFINED
|
||||
#define SkDrawClip_DEFINED
|
||||
|
||||
#include "SkDrawable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkRegion.h"
|
||||
|
||||
class SkDrawPath;
|
||||
class SkDrawRect;
|
||||
|
||||
class SkDrawClip : public SkDrawable {
|
||||
DECLARE_DRAW_MEMBER_INFO(Clip);
|
||||
SkDrawClip();
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
private:
|
||||
SkDrawRect* rect;
|
||||
SkDrawPath* path;
|
||||
};
|
||||
|
||||
#endif // SkDrawClip_DEFINED
|
||||
@@ -0,0 +1,278 @@
|
||||
/* libs/graphics/animator/SkDrawColor.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawColor.h"
|
||||
#ifdef SK_DEBUG
|
||||
#include "SkDisplayList.h"
|
||||
#endif
|
||||
#include "SkDrawPaint.h"
|
||||
#include "SkParse.h"
|
||||
#include "SkScript.h"
|
||||
|
||||
enum HSV_Choice {
|
||||
kGetHue,
|
||||
kGetSaturation,
|
||||
kGetValue
|
||||
};
|
||||
|
||||
static SkScalar RGB_to_HSV(SkColor color, HSV_Choice choice) {
|
||||
SkScalar red = SkIntToScalar(SkColorGetR(color));
|
||||
SkScalar green = SkIntToScalar(SkColorGetG(color));
|
||||
SkScalar blue = SkIntToScalar(SkColorGetB(color));
|
||||
SkScalar min = SkMinScalar(SkMinScalar(red, green), blue);
|
||||
SkScalar value = SkMaxScalar(SkMaxScalar(red, green), blue);
|
||||
if (choice == kGetValue)
|
||||
return value/255;
|
||||
SkScalar delta = value - min;
|
||||
SkScalar saturation = value == 0 ? 0 : SkScalarDiv(delta, value);
|
||||
if (choice == kGetSaturation)
|
||||
return saturation;
|
||||
SkScalar hue;
|
||||
if (saturation == 0)
|
||||
hue = 0;
|
||||
else {
|
||||
SkScalar part60 = SkScalarDiv(60 * SK_Scalar1, delta);
|
||||
if (red == value) {
|
||||
hue = SkScalarMul(green - blue, part60);
|
||||
if (hue < 0)
|
||||
hue += 360 * SK_Scalar1;
|
||||
}
|
||||
else if (green == value)
|
||||
hue = 120 * SK_Scalar1 + SkScalarMul(blue - red, part60);
|
||||
else // blue == value
|
||||
hue = 240 * SK_Scalar1 + SkScalarMul(red - green, part60);
|
||||
}
|
||||
SkASSERT(choice == kGetHue);
|
||||
return hue;
|
||||
}
|
||||
|
||||
#if defined _WIN32 && _MSC_VER >= 1300 // disable 'red', etc. may be used without having been initialized
|
||||
#pragma warning ( push )
|
||||
#pragma warning ( disable : 4701 )
|
||||
#endif
|
||||
|
||||
static SkColor HSV_to_RGB(SkColor color, HSV_Choice choice, SkScalar hsv) {
|
||||
SkScalar hue = choice == kGetHue ? hsv : RGB_to_HSV(color, kGetHue);
|
||||
SkScalar saturation = choice == kGetSaturation ? hsv : RGB_to_HSV(color, kGetSaturation);
|
||||
SkScalar value = choice == kGetValue ? hsv : RGB_to_HSV(color, kGetValue);
|
||||
value *= 255;
|
||||
SkScalar red SK_INIT_TO_AVOID_WARNING;
|
||||
SkScalar green SK_INIT_TO_AVOID_WARNING;
|
||||
SkScalar blue SK_INIT_TO_AVOID_WARNING;
|
||||
if (saturation == 0) // color is on black-and-white center line
|
||||
red = green = blue = value;
|
||||
else {
|
||||
//SkScalar fraction = SkScalarMod(hue, 60 * SK_Scalar1);
|
||||
int sextant = SkScalarFloor(hue / 60);
|
||||
SkScalar fraction = hue / 60 - SkIntToScalar(sextant);
|
||||
SkScalar p = SkScalarMul(value , SK_Scalar1 - saturation);
|
||||
SkScalar q = SkScalarMul(value, SK_Scalar1 - SkScalarMul(saturation, fraction));
|
||||
SkScalar t = SkScalarMul(value, SK_Scalar1 -
|
||||
SkScalarMul(saturation, SK_Scalar1 - fraction));
|
||||
switch (sextant % 6) {
|
||||
case 0: red = value; green = t; blue = p; break;
|
||||
case 1: red = q; green = value; blue = p; break;
|
||||
case 2: red = p; green = value; blue = t; break;
|
||||
case 3: red = p; green = q; blue = value; break;
|
||||
case 4: red = t; green = p; blue = value; break;
|
||||
case 5: red = value; green = p; blue = q; break;
|
||||
}
|
||||
}
|
||||
//used to say SkToU8((U8CPU) red) etc
|
||||
return SkColorSetARGB(SkColorGetA(color), SkScalarRound(red),
|
||||
SkScalarRound(green), SkScalarRound(blue));
|
||||
}
|
||||
|
||||
#if defined _WIN32 && _MSC_VER >= 1300
|
||||
#pragma warning ( pop )
|
||||
#endif
|
||||
|
||||
enum SkDrawColor_Properties {
|
||||
SK_PROPERTY(alpha),
|
||||
SK_PROPERTY(blue),
|
||||
SK_PROPERTY(green),
|
||||
SK_PROPERTY(hue),
|
||||
SK_PROPERTY(red),
|
||||
SK_PROPERTY(saturation),
|
||||
SK_PROPERTY(value)
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawColor::fInfo[] = {
|
||||
SK_MEMBER_PROPERTY(alpha, Float),
|
||||
SK_MEMBER_PROPERTY(blue, Float),
|
||||
SK_MEMBER(color, ARGB),
|
||||
SK_MEMBER_PROPERTY(green, Float),
|
||||
SK_MEMBER_PROPERTY(hue, Float),
|
||||
SK_MEMBER_PROPERTY(red, Float),
|
||||
SK_MEMBER_PROPERTY(saturation, Float),
|
||||
SK_MEMBER_PROPERTY(value, Float),
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawColor);
|
||||
|
||||
SkDrawColor::SkDrawColor() : fDirty(false) {
|
||||
color = SK_ColorBLACK;
|
||||
fHue = fSaturation = fValue = SK_ScalarNaN;
|
||||
}
|
||||
|
||||
bool SkDrawColor::add() {
|
||||
if (fPaint->color != NULL)
|
||||
return true; // error (probably color in paint as attribute as well)
|
||||
fPaint->color = this;
|
||||
fPaint->fOwnsColor = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
SkDisplayable* SkDrawColor::deepCopy(SkAnimateMaker* maker) {
|
||||
SkDrawColor* copy = new SkDrawColor();
|
||||
copy->color = color;
|
||||
copy->fHue = fHue;
|
||||
copy->fSaturation = fSaturation;
|
||||
copy->fValue = fValue;
|
||||
copy->fDirty = fDirty;
|
||||
return copy;
|
||||
}
|
||||
|
||||
void SkDrawColor::dirty(){
|
||||
fDirty = true;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkDrawColor::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
SkDebugf("alpha=\"%d\" red=\"%d\" green=\"%d\" blue=\"%d\" />\n",
|
||||
SkColorGetA(color)/255, SkColorGetR(color),
|
||||
SkColorGetG(color), SkColorGetB(color));
|
||||
}
|
||||
#endif
|
||||
|
||||
SkColor SkDrawColor::getColor() {
|
||||
if (fDirty) {
|
||||
if (SkScalarIsNaN(fValue) == false)
|
||||
color = HSV_to_RGB(color, kGetValue, fValue);
|
||||
if (SkScalarIsNaN(fSaturation) == false)
|
||||
color = HSV_to_RGB(color, kGetSaturation, fSaturation);
|
||||
if (SkScalarIsNaN(fHue) == false)
|
||||
color = HSV_to_RGB(color, kGetHue, fHue);
|
||||
fDirty = false;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
SkDisplayable* SkDrawColor::getParent() const {
|
||||
return fPaint;
|
||||
}
|
||||
|
||||
bool SkDrawColor::getProperty(int index, SkScriptValue* value) const {
|
||||
value->fType = SkType_Float;
|
||||
SkScalar result;
|
||||
switch(index) {
|
||||
case SK_PROPERTY(alpha):
|
||||
result = SkIntToScalar(SkColorGetA(color)) / 255;
|
||||
break;
|
||||
case SK_PROPERTY(blue):
|
||||
result = SkIntToScalar(SkColorGetB(color));
|
||||
break;
|
||||
case SK_PROPERTY(green):
|
||||
result = SkIntToScalar(SkColorGetG(color));
|
||||
break;
|
||||
case SK_PROPERTY(hue):
|
||||
result = RGB_to_HSV(color, kGetHue);
|
||||
break;
|
||||
case SK_PROPERTY(red):
|
||||
result = SkIntToScalar(SkColorGetR(color));
|
||||
break;
|
||||
case SK_PROPERTY(saturation):
|
||||
result = RGB_to_HSV(color, kGetSaturation);
|
||||
break;
|
||||
case SK_PROPERTY(value):
|
||||
result = RGB_to_HSV(color, kGetValue);
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
value->fOperand.fScalar = result;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkDrawColor::onEndElement(SkAnimateMaker& maker){
|
||||
fDirty = true;
|
||||
}
|
||||
|
||||
bool SkDrawColor::setParent(SkDisplayable* parent) {
|
||||
SkASSERT(parent != NULL);
|
||||
if (parent->getType() == SkType_LinearGradient || parent->getType() == SkType_RadialGradient)
|
||||
return false;
|
||||
if (parent->isPaint() == false)
|
||||
return true;
|
||||
fPaint = (SkDrawPaint*) parent;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDrawColor::setProperty(int index, SkScriptValue& value) {
|
||||
SkASSERT(value.fType == SkType_Float);
|
||||
SkScalar scalar = value.fOperand.fScalar;
|
||||
switch (index) {
|
||||
case SK_PROPERTY(alpha):
|
||||
uint8_t alpha;
|
||||
#ifdef SK_SCALAR_IS_FLOAT
|
||||
alpha = scalar == SK_Scalar1 ? 255 : SkToU8((U8CPU) (scalar * 256));
|
||||
#else
|
||||
alpha = SkToU8((scalar - (scalar >= SK_ScalarHalf)) >> 8);
|
||||
#endif
|
||||
color = SkColorSetARGB(alpha, SkColorGetR(color),
|
||||
SkColorGetG(color), SkColorGetB(color));
|
||||
break;
|
||||
case SK_PROPERTY(blue):
|
||||
scalar = SkScalarClampMax(scalar, 255 * SK_Scalar1);
|
||||
color = SkColorSetARGB(SkColorGetA(color), SkColorGetR(color),
|
||||
SkColorGetG(color), SkToU8((U8CPU) scalar));
|
||||
break;
|
||||
case SK_PROPERTY(green):
|
||||
scalar = SkScalarClampMax(scalar, 255 * SK_Scalar1);
|
||||
color = SkColorSetARGB(SkColorGetA(color), SkColorGetR(color),
|
||||
SkToU8((U8CPU) scalar), SkColorGetB(color));
|
||||
break;
|
||||
case SK_PROPERTY(hue):
|
||||
fHue = scalar;//RGB_to_HSV(color, kGetHue);
|
||||
fDirty = true;
|
||||
break;
|
||||
case SK_PROPERTY(red):
|
||||
scalar = SkScalarClampMax(scalar, 255 * SK_Scalar1);
|
||||
color = SkColorSetARGB(SkColorGetA(color), SkToU8((U8CPU) scalar),
|
||||
SkColorGetG(color), SkColorGetB(color));
|
||||
break;
|
||||
case SK_PROPERTY(saturation):
|
||||
fSaturation = scalar;//RGB_to_HSV(color, kGetSaturation);
|
||||
fDirty = true;
|
||||
break;
|
||||
case SK_PROPERTY(value):
|
||||
fValue = scalar;//RGB_to_HSV(color, kGetValue);
|
||||
fDirty = true;
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/* libs/graphics/animator/SkDrawColor.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawColor_DEFINED
|
||||
#define SkDrawColor_DEFINED
|
||||
|
||||
#include "SkPaintParts.h"
|
||||
#include "SkColor.h"
|
||||
|
||||
class SkDrawColor : public SkPaintPart {
|
||||
DECLARE_DRAW_MEMBER_INFO(Color);
|
||||
SkDrawColor();
|
||||
virtual bool add();
|
||||
virtual void dirty();
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
SkColor getColor();
|
||||
virtual SkDisplayable* deepCopy(SkAnimateMaker* );
|
||||
virtual SkDisplayable* getParent() const;
|
||||
virtual bool getProperty(int index, SkScriptValue* value) const;
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
virtual bool setParent(SkDisplayable* parent);
|
||||
virtual bool setProperty(int index, SkScriptValue&);
|
||||
protected:
|
||||
SkColor color;
|
||||
SkScalar fHue;
|
||||
SkScalar fSaturation;
|
||||
SkScalar fValue;
|
||||
SkBool fDirty;
|
||||
private:
|
||||
friend class SkGradient;
|
||||
typedef SkPaintPart INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDrawColor_DEFINED
|
||||
@@ -0,0 +1,44 @@
|
||||
/* libs/graphics/animator/SkDrawDash.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawDash.h"
|
||||
#include "SkDashPathEffect.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDash::fInfo[] = {
|
||||
SK_MEMBER_ARRAY(intervals, Float),
|
||||
SK_MEMBER(phase, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDash);
|
||||
|
||||
SkDash::SkDash() : phase(0) {
|
||||
}
|
||||
|
||||
SkDash::~SkDash() {
|
||||
}
|
||||
|
||||
SkPathEffect* SkDash::getPathEffect() {
|
||||
int count = intervals.count();
|
||||
if (count == 0)
|
||||
return NULL;
|
||||
return new SkDashPathEffect(intervals.begin(), count, phase);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/* libs/graphics/animator/SkDrawDash.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawDash_DEFINED
|
||||
#define SkDrawDash_DEFINED
|
||||
|
||||
#include "SkPaintParts.h"
|
||||
#include "SkIntArray.h"
|
||||
|
||||
class SkDash : public SkDrawPathEffect {
|
||||
DECLARE_MEMBER_INFO(Dash);
|
||||
SkDash();
|
||||
virtual ~SkDash();
|
||||
virtual SkPathEffect* getPathEffect();
|
||||
private:
|
||||
SkTDScalarArray intervals;
|
||||
SkScalar phase;
|
||||
};
|
||||
|
||||
#endif // SkDrawDash_DEFINED
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/* libs/graphics/animator/SkDrawDiscrete.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawDiscrete.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkDiscretePathEffect.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDiscrete::fInfo[] = {
|
||||
SK_MEMBER(deviation, Float),
|
||||
SK_MEMBER(segLength, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDiscrete);
|
||||
|
||||
SkDiscrete::SkDiscrete() : deviation(0), segLength(0) {
|
||||
}
|
||||
|
||||
SkPathEffect* SkDiscrete::getPathEffect() {
|
||||
if (deviation <= 0 || segLength <= 0)
|
||||
return NULL;
|
||||
else
|
||||
return new SkDiscretePathEffect(segLength, deviation);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/* libs/graphics/animator/SkDrawDiscrete.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawDiscrete_DEFINED
|
||||
#define SkDrawDiscrete_DEFINED
|
||||
|
||||
#include "SkPaintParts.h"
|
||||
|
||||
class SkDiscrete : public SkDrawPathEffect {
|
||||
DECLARE_MEMBER_INFO(Discrete);
|
||||
SkDiscrete();
|
||||
virtual SkPathEffect* getPathEffect();
|
||||
private:
|
||||
SkScalar deviation;
|
||||
SkScalar segLength;
|
||||
};
|
||||
|
||||
#endif //SkDrawDiscrete_DEFINED
|
||||
@@ -0,0 +1,42 @@
|
||||
/* libs/graphics/animator/SkDrawEmboss.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawEmboss.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawEmboss::fInfo[] = {
|
||||
SK_MEMBER(ambient, Float),
|
||||
SK_MEMBER_ARRAY(direction, Float),
|
||||
SK_MEMBER(radius, Float),
|
||||
SK_MEMBER(specular, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawEmboss);
|
||||
|
||||
SkDrawEmboss::SkDrawEmboss() : radius(-1) {
|
||||
direction.setCount(3);
|
||||
}
|
||||
|
||||
SkMaskFilter* SkDrawEmboss::getMaskFilter() {
|
||||
if (radius < 0 || direction.count() !=3)
|
||||
return NULL;
|
||||
return SkBlurMaskFilter::CreateEmboss(direction.begin(), ambient, specular, radius);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/* libs/graphics/animator/SkDrawEmboss.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawEmboss_DEFINED
|
||||
#define SkDrawEmboss_DEFINED
|
||||
|
||||
#include "SkDrawBlur.h"
|
||||
|
||||
class SkDrawEmboss : public SkDrawMaskFilter {
|
||||
DECLARE_DRAW_MEMBER_INFO(Emboss);
|
||||
SkDrawEmboss();
|
||||
virtual SkMaskFilter* getMaskFilter();
|
||||
protected:
|
||||
SkTDScalarArray direction;
|
||||
SkScalar radius, ambient, specular;
|
||||
};
|
||||
|
||||
#endif // SkDrawEmboss_DEFINED
|
||||
|
||||
@@ -0,0 +1,519 @@
|
||||
/* libs/graphics/animator/SkDrawExtraPathEffect.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawExtraPathEffect.h"
|
||||
#include "SkDrawPath.h"
|
||||
#include "Sk1DPathEffect.h"
|
||||
#include "Sk2DPathEffect.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkPaintParts.h"
|
||||
#include "SkPathEffect.h"
|
||||
#include "SkCornerPathEffect.h"
|
||||
|
||||
#include "SkDashPathEffect.h"
|
||||
|
||||
class SkDrawShapePathEffect : public SkDrawPathEffect {
|
||||
DECLARE_PRIVATE_MEMBER_INFO(DrawShapePathEffect);
|
||||
SkDrawShapePathEffect();
|
||||
virtual ~SkDrawShapePathEffect();
|
||||
virtual bool add(SkAnimateMaker& , SkDisplayable* );
|
||||
virtual SkPathEffect* getPathEffect();
|
||||
protected:
|
||||
SkDrawable* addPath;
|
||||
SkDrawable* addMatrix;
|
||||
SkDrawPath* path;
|
||||
SkPathEffect* fPathEffect;
|
||||
friend class SkShape1DPathEffect;
|
||||
friend class SkShape2DPathEffect;
|
||||
};
|
||||
|
||||
class SkDrawShape1DPathEffect : public SkDrawShapePathEffect {
|
||||
DECLARE_EXTRAS_MEMBER_INFO(SkDrawShape1DPathEffect);
|
||||
SkDrawShape1DPathEffect(SkDisplayTypes );
|
||||
virtual ~SkDrawShape1DPathEffect();
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
private:
|
||||
SkString phase;
|
||||
SkString spacing;
|
||||
friend class SkShape1DPathEffect;
|
||||
typedef SkDrawShapePathEffect INHERITED;
|
||||
};
|
||||
|
||||
class SkDrawShape2DPathEffect : public SkDrawShapePathEffect {
|
||||
DECLARE_EXTRAS_MEMBER_INFO(SkDrawShape2DPathEffect);
|
||||
SkDrawShape2DPathEffect(SkDisplayTypes );
|
||||
virtual ~SkDrawShape2DPathEffect();
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
private:
|
||||
SkDrawMatrix* matrix;
|
||||
friend class SkShape2DPathEffect;
|
||||
typedef SkDrawShapePathEffect INHERITED;
|
||||
};
|
||||
|
||||
class SkDrawComposePathEffect : public SkDrawPathEffect {
|
||||
DECLARE_EXTRAS_MEMBER_INFO(SkDrawComposePathEffect);
|
||||
SkDrawComposePathEffect(SkDisplayTypes );
|
||||
virtual ~SkDrawComposePathEffect();
|
||||
virtual bool add(SkAnimateMaker& , SkDisplayable* );
|
||||
virtual SkPathEffect* getPathEffect();
|
||||
virtual bool isPaint() const;
|
||||
private:
|
||||
SkDrawPathEffect* effect1;
|
||||
SkDrawPathEffect* effect2;
|
||||
};
|
||||
|
||||
class SkDrawCornerPathEffect : public SkDrawPathEffect {
|
||||
DECLARE_EXTRAS_MEMBER_INFO(SkDrawCornerPathEffect);
|
||||
SkDrawCornerPathEffect(SkDisplayTypes );
|
||||
virtual ~SkDrawCornerPathEffect();
|
||||
virtual SkPathEffect* getPathEffect();
|
||||
private:
|
||||
SkScalar radius;
|
||||
};
|
||||
|
||||
//////////// SkShape1DPathEffect
|
||||
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkAnimatorScript.h"
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkDrawMatrix.h"
|
||||
#include "SkPaint.h"
|
||||
|
||||
class SkShape1DPathEffect : public Sk1DPathEffect {
|
||||
public:
|
||||
SkShape1DPathEffect(SkDrawShape1DPathEffect* draw, SkAnimateMaker* maker) :
|
||||
fDraw(draw), fMaker(maker) {
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkScalar begin(SkScalar contourLength)
|
||||
{
|
||||
SkScriptValue value;
|
||||
SkAnimatorScript engine(*fMaker, NULL, SkType_Float);
|
||||
engine.propertyCallBack(GetContourLength, &contourLength);
|
||||
value.fOperand.fScalar = 0;
|
||||
engine.evaluate(fDraw->phase.c_str(), &value, SkType_Float);
|
||||
return value.fOperand.fScalar;
|
||||
}
|
||||
|
||||
virtual SkScalar next(SkPath* dst, SkScalar distance, SkPathMeasure& )
|
||||
{
|
||||
fMaker->setExtraPropertyCallBack(fDraw->fType, GetDistance, &distance);
|
||||
SkDrawPath* drawPath = NULL;
|
||||
if (fDraw->addPath->isPath()) {
|
||||
drawPath = (SkDrawPath*) fDraw->addPath;
|
||||
} else {
|
||||
SkApply* apply = (SkApply*) fDraw->addPath;
|
||||
apply->refresh(*fMaker);
|
||||
apply->activate(*fMaker);
|
||||
apply->interpolate(*fMaker, SkScalarMulRound(distance, 1000));
|
||||
drawPath = (SkDrawPath*) apply->getScope();
|
||||
}
|
||||
SkMatrix m;
|
||||
m.reset();
|
||||
if (fDraw->addMatrix) {
|
||||
SkDrawMatrix* matrix;
|
||||
if (fDraw->addMatrix->getType() == SkType_Matrix)
|
||||
matrix = (SkDrawMatrix*) fDraw->addMatrix;
|
||||
else {
|
||||
SkApply* apply = (SkApply*) fDraw->addMatrix;
|
||||
apply->refresh(*fMaker);
|
||||
apply->activate(*fMaker);
|
||||
apply->interpolate(*fMaker, SkScalarMulRound(distance, 1000));
|
||||
matrix = (SkDrawMatrix*) apply->getScope();
|
||||
}
|
||||
}
|
||||
SkScalar result = 0;
|
||||
SkAnimatorScript::EvaluateFloat(*fMaker, NULL, fDraw->spacing.c_str(), &result);
|
||||
if (drawPath)
|
||||
dst->addPath(drawPath->getPath(), m);
|
||||
fMaker->clearExtraPropertyCallBack(fDraw->fType);
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void flatten(SkFlattenableWriteBuffer& ) {}
|
||||
virtual Factory getFactory() { return NULL; }
|
||||
|
||||
static bool GetContourLength(const char* token, size_t len, void* clen, SkScriptValue* value) {
|
||||
if (SK_LITERAL_STR_EQUAL("contourLength", token, len)) {
|
||||
value->fOperand.fScalar = *(SkScalar*) clen;
|
||||
value->fType = SkType_Float;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool GetDistance(const char* token, size_t len, void* dist, SkScriptValue* value) {
|
||||
if (SK_LITERAL_STR_EQUAL("distance", token, len)) {
|
||||
value->fOperand.fScalar = *(SkScalar*) dist;
|
||||
value->fType = SkType_Float;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SkDrawShape1DPathEffect* fDraw;
|
||||
SkAnimateMaker* fMaker;
|
||||
};
|
||||
|
||||
//////////// SkDrawShapePathEffect
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawShapePathEffect::fInfo[] = {
|
||||
SK_MEMBER(addMatrix, Drawable), // either matrix or apply
|
||||
SK_MEMBER(addPath, Drawable), // either path or apply
|
||||
SK_MEMBER(path, Path),
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawShapePathEffect);
|
||||
|
||||
SkDrawShapePathEffect::SkDrawShapePathEffect() :
|
||||
addPath(NULL), addMatrix(NULL), path(NULL), fPathEffect(NULL) {
|
||||
}
|
||||
|
||||
SkDrawShapePathEffect::~SkDrawShapePathEffect() {
|
||||
fPathEffect->safeUnref();
|
||||
}
|
||||
|
||||
bool SkDrawShapePathEffect::add(SkAnimateMaker& , SkDisplayable* child) {
|
||||
path = (SkDrawPath*) child;
|
||||
return true;
|
||||
}
|
||||
|
||||
SkPathEffect* SkDrawShapePathEffect::getPathEffect() {
|
||||
fPathEffect->ref();
|
||||
return fPathEffect;
|
||||
}
|
||||
|
||||
//////////// SkDrawShape1DPathEffect
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawShape1DPathEffect::fInfo[] = {
|
||||
SK_MEMBER_INHERITED,
|
||||
SK_MEMBER(phase, String),
|
||||
SK_MEMBER(spacing, String),
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawShape1DPathEffect);
|
||||
|
||||
SkDrawShape1DPathEffect::SkDrawShape1DPathEffect(SkDisplayTypes type) : fType(type) {
|
||||
}
|
||||
|
||||
SkDrawShape1DPathEffect::~SkDrawShape1DPathEffect() {
|
||||
}
|
||||
|
||||
void SkDrawShape1DPathEffect::onEndElement(SkAnimateMaker& maker) {
|
||||
if (addPath == NULL || (addPath->isPath() == false && addPath->isApply() == false))
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kUnknownError); // !!! add error
|
||||
else
|
||||
fPathEffect = new SkShape1DPathEffect(this, &maker);
|
||||
}
|
||||
|
||||
////////// SkShape2DPathEffect
|
||||
|
||||
class SkShape2DPathEffect : public Sk2DPathEffect {
|
||||
public:
|
||||
SkShape2DPathEffect(SkDrawShape2DPathEffect* draw, SkAnimateMaker* maker,
|
||||
const SkMatrix& matrix) : Sk2DPathEffect(matrix), fDraw(draw), fMaker(maker) {
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void begin(const SkIRect& uvBounds, SkPath* )
|
||||
{
|
||||
fUVBounds.set(SkIntToScalar(uvBounds.fLeft), SkIntToScalar(uvBounds.fTop),
|
||||
SkIntToScalar(uvBounds.fRight), SkIntToScalar(uvBounds.fBottom));
|
||||
}
|
||||
|
||||
virtual void next(const SkPoint& loc, int u, int v, SkPath* dst)
|
||||
{
|
||||
fLoc = loc;
|
||||
fU = u;
|
||||
fV = v;
|
||||
SkDrawPath* drawPath;
|
||||
fMaker->setExtraPropertyCallBack(fDraw->fType, Get2D, this);
|
||||
if (fDraw->addPath->isPath()) {
|
||||
drawPath = (SkDrawPath*) fDraw->addPath;
|
||||
} else {
|
||||
SkApply* apply = (SkApply*) fDraw->addPath;
|
||||
apply->refresh(*fMaker);
|
||||
apply->activate(*fMaker);
|
||||
apply->interpolate(*fMaker, v);
|
||||
drawPath = (SkDrawPath*) apply->getScope();
|
||||
}
|
||||
if (drawPath == NULL)
|
||||
goto clearCallBack;
|
||||
if (fDraw->matrix) {
|
||||
SkDrawMatrix* matrix;
|
||||
if (fDraw->matrix->getType() == SkType_Matrix)
|
||||
matrix = (SkDrawMatrix*) fDraw->matrix;
|
||||
else {
|
||||
SkApply* apply = (SkApply*) fDraw->matrix;
|
||||
apply->activate(*fMaker);
|
||||
apply->interpolate(*fMaker, v);
|
||||
matrix = (SkDrawMatrix*) apply->getScope();
|
||||
}
|
||||
if (matrix) {
|
||||
dst->addPath(drawPath->getPath(), matrix->getMatrix());
|
||||
goto clearCallBack;
|
||||
}
|
||||
}
|
||||
dst->addPath(drawPath->getPath());
|
||||
clearCallBack:
|
||||
fMaker->clearExtraPropertyCallBack(fDraw->fType);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static bool Get2D(const char* token, size_t len, void* s2D, SkScriptValue* value) {
|
||||
static const char match[] = "locX|locY|left|top|right|bottom|u|v" ;
|
||||
SkShape2DPathEffect* shape2D = (SkShape2DPathEffect*) s2D;
|
||||
int index;
|
||||
if (SkAnimatorScript::MapEnums(match, token, len, &index) == false)
|
||||
return false;
|
||||
SkASSERT((sizeof(SkPoint) + sizeof(SkRect)) / sizeof(SkScalar) == 6);
|
||||
if (index < 6) {
|
||||
value->fType = SkType_Float;
|
||||
value->fOperand.fScalar = (&shape2D->fLoc.fX)[index];
|
||||
} else {
|
||||
value->fType = SkType_Int;
|
||||
value->fOperand.fS32 = (&shape2D->fU)[index - 6];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
SkPoint fLoc;
|
||||
SkRect fUVBounds;
|
||||
int32_t fU;
|
||||
int32_t fV;
|
||||
SkDrawShape2DPathEffect* fDraw;
|
||||
SkAnimateMaker* fMaker;
|
||||
|
||||
// illegal
|
||||
SkShape2DPathEffect(const SkShape2DPathEffect&);
|
||||
SkShape2DPathEffect& operator=(const SkShape2DPathEffect&);
|
||||
};
|
||||
|
||||
////////// SkDrawShape2DPathEffect
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawShape2DPathEffect::fInfo[] = {
|
||||
SK_MEMBER_INHERITED,
|
||||
SK_MEMBER(matrix, Matrix)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawShape2DPathEffect);
|
||||
|
||||
SkDrawShape2DPathEffect::SkDrawShape2DPathEffect(SkDisplayTypes type) : fType(type) {
|
||||
}
|
||||
|
||||
SkDrawShape2DPathEffect::~SkDrawShape2DPathEffect() {
|
||||
}
|
||||
|
||||
void SkDrawShape2DPathEffect::onEndElement(SkAnimateMaker& maker) {
|
||||
if (addPath == NULL || (addPath->isPath() == false && addPath->isApply() == false) ||
|
||||
matrix == NULL)
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kUnknownError); // !!! add error
|
||||
else
|
||||
fPathEffect = new SkShape2DPathEffect(this, &maker, matrix->getMatrix());
|
||||
}
|
||||
|
||||
////////// SkDrawComposePathEffect
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawComposePathEffect::fInfo[] = {
|
||||
SK_MEMBER(effect1, PathEffect),
|
||||
SK_MEMBER(effect2, PathEffect)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawComposePathEffect);
|
||||
|
||||
SkDrawComposePathEffect::SkDrawComposePathEffect(SkDisplayTypes type) : fType(type),
|
||||
effect1(NULL), effect2(NULL) {
|
||||
}
|
||||
|
||||
SkDrawComposePathEffect::~SkDrawComposePathEffect() {
|
||||
delete effect1;
|
||||
delete effect2;
|
||||
}
|
||||
|
||||
bool SkDrawComposePathEffect::add(SkAnimateMaker& , SkDisplayable* child) {
|
||||
if (effect1 == NULL)
|
||||
effect1 = (SkDrawPathEffect*) child;
|
||||
else
|
||||
effect2 = (SkDrawPathEffect*) child;
|
||||
return true;
|
||||
}
|
||||
|
||||
SkPathEffect* SkDrawComposePathEffect::getPathEffect() {
|
||||
SkPathEffect* e1 = effect1->getPathEffect();
|
||||
SkPathEffect* e2 = effect2->getPathEffect();
|
||||
SkPathEffect* composite = new SkComposePathEffect(e1, e2);
|
||||
e1->unref();
|
||||
e2->unref();
|
||||
return composite;
|
||||
}
|
||||
|
||||
bool SkDrawComposePathEffect::isPaint() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////// SkDrawCornerPathEffect
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawCornerPathEffect::fInfo[] = {
|
||||
SK_MEMBER(radius, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawCornerPathEffect);
|
||||
|
||||
SkDrawCornerPathEffect::SkDrawCornerPathEffect(SkDisplayTypes type):
|
||||
fType(type), radius(0) {
|
||||
}
|
||||
|
||||
SkDrawCornerPathEffect::~SkDrawCornerPathEffect() {
|
||||
}
|
||||
|
||||
SkPathEffect* SkDrawCornerPathEffect::getPathEffect() {
|
||||
return new SkCornerPathEffect(radius);
|
||||
}
|
||||
|
||||
/////////
|
||||
|
||||
#include "SkExtras.h"
|
||||
|
||||
const char kDrawShape1DPathEffectName[] = "pathEffect:shape1D";
|
||||
const char kDrawShape2DPathEffectName[] = "pathEffect:shape2D";
|
||||
const char kDrawComposePathEffectName[] = "pathEffect:compose";
|
||||
const char kDrawCornerPathEffectName[] = "pathEffect:corner";
|
||||
|
||||
class SkExtraPathEffects : public SkExtras {
|
||||
public:
|
||||
SkExtraPathEffects(SkAnimator* animator) :
|
||||
skDrawShape1DPathEffectType(SkType_Unknown),
|
||||
skDrawShape2DPathEffectType(SkType_Unknown),
|
||||
skDrawComposePathEffectType(SkType_Unknown),
|
||||
skDrawCornerPathEffectType(SkType_Unknown) {
|
||||
}
|
||||
|
||||
virtual SkDisplayable* createInstance(SkDisplayTypes type) {
|
||||
SkDisplayable* result = NULL;
|
||||
if (skDrawShape1DPathEffectType == type)
|
||||
result = new SkDrawShape1DPathEffect(type);
|
||||
else if (skDrawShape2DPathEffectType == type)
|
||||
result = new SkDrawShape2DPathEffect(type);
|
||||
else if (skDrawComposePathEffectType == type)
|
||||
result = new SkDrawComposePathEffect(type);
|
||||
else if (skDrawCornerPathEffectType == type)
|
||||
result = new SkDrawCornerPathEffect(type);
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual bool definesType(SkDisplayTypes type) {
|
||||
return type == skDrawShape1DPathEffectType ||
|
||||
type == skDrawShape2DPathEffectType ||
|
||||
type == skDrawComposePathEffectType ||
|
||||
type == skDrawCornerPathEffectType;
|
||||
}
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
virtual const SkMemberInfo* getMembers(SkDisplayTypes type, int* infoCountPtr) {
|
||||
const SkMemberInfo* info = NULL;
|
||||
int infoCount = 0;
|
||||
if (skDrawShape1DPathEffectType == type) {
|
||||
info = SkDrawShape1DPathEffect::fInfo;
|
||||
infoCount = SkDrawShape1DPathEffect::fInfoCount;
|
||||
} else if (skDrawShape2DPathEffectType == type) {
|
||||
info = SkDrawShape2DPathEffect::fInfo;
|
||||
infoCount = SkDrawShape2DPathEffect::fInfoCount;
|
||||
} else if (skDrawComposePathEffectType == type) {
|
||||
info = SkDrawComposePathEffect::fInfo;
|
||||
infoCount = SkDrawShape1DPathEffect::fInfoCount;
|
||||
} else if (skDrawCornerPathEffectType == type) {
|
||||
info = SkDrawCornerPathEffect::fInfo;
|
||||
infoCount = SkDrawCornerPathEffect::fInfoCount;
|
||||
}
|
||||
if (infoCountPtr)
|
||||
*infoCountPtr = infoCount;
|
||||
return info;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
virtual const char* getName(SkDisplayTypes type) {
|
||||
if (skDrawShape1DPathEffectType == type)
|
||||
return kDrawShape1DPathEffectName;
|
||||
else if (skDrawShape2DPathEffectType == type)
|
||||
return kDrawShape2DPathEffectName;
|
||||
else if (skDrawComposePathEffectType == type)
|
||||
return kDrawComposePathEffectName;
|
||||
else if (skDrawCornerPathEffectType == type)
|
||||
return kDrawCornerPathEffectName;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual SkDisplayTypes getType(const char name[], size_t len ) {
|
||||
SkDisplayTypes* type = NULL;
|
||||
if (SK_LITERAL_STR_EQUAL(kDrawShape1DPathEffectName, name, len))
|
||||
type = &skDrawShape1DPathEffectType;
|
||||
else if (SK_LITERAL_STR_EQUAL(kDrawShape2DPathEffectName, name, len))
|
||||
type = &skDrawShape2DPathEffectType;
|
||||
else if (SK_LITERAL_STR_EQUAL(kDrawComposePathEffectName, name, len))
|
||||
type = &skDrawComposePathEffectType;
|
||||
else if (SK_LITERAL_STR_EQUAL(kDrawCornerPathEffectName, name, len))
|
||||
type = &skDrawCornerPathEffectType;
|
||||
if (type) {
|
||||
if (*type == SkType_Unknown)
|
||||
*type = SkDisplayType::RegisterNewType();
|
||||
return *type;
|
||||
}
|
||||
return SkType_Unknown;
|
||||
}
|
||||
|
||||
private:
|
||||
SkDisplayTypes skDrawShape1DPathEffectType;
|
||||
SkDisplayTypes skDrawShape2DPathEffectType;
|
||||
SkDisplayTypes skDrawComposePathEffectType;
|
||||
SkDisplayTypes skDrawCornerPathEffectType;
|
||||
};
|
||||
|
||||
|
||||
void InitializeSkExtraPathEffects(SkAnimator* animator) {
|
||||
animator->addExtras(new SkExtraPathEffects(animator));
|
||||
}
|
||||
|
||||
////////////////
|
||||
|
||||
|
||||
SkExtras::SkExtras() : fExtraCallBack(NULL), fExtraStorage(NULL) {
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/* libs/graphics/animator/SkDrawFull.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawFull.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkCanvas.h"
|
||||
|
||||
bool SkFull::draw(SkAnimateMaker& maker) {
|
||||
SkBoundableAuto boundable(this, maker);
|
||||
maker.fCanvas->drawPaint(*maker.fPaint);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/* libs/graphics/animator/SkDrawFull.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawFull_DEFINED
|
||||
#define SkDrawFull_DEFINED
|
||||
|
||||
#include "SkBoundable.h"
|
||||
|
||||
class SkFull : public SkBoundable {
|
||||
DECLARE_EMPTY_MEMBER_INFO(Full);
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
private:
|
||||
typedef SkBoundable INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDrawFull_DEFINED
|
||||
@@ -0,0 +1,235 @@
|
||||
/* libs/graphics/animator/SkDrawGradient.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawGradient.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkAnimatorScript.h"
|
||||
#include "SkGradientShader.h"
|
||||
#include "SkUnitMapper.h"
|
||||
|
||||
SkScalar SkUnitToScalar(U16CPU x) {
|
||||
#ifdef SK_SCALAR_IS_FLOAT
|
||||
return x / 65535.0f;
|
||||
#else
|
||||
return x + (x >> 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
U16CPU SkScalarToUnit(SkScalar x) {
|
||||
SkScalar pin = SkScalarPin(x, 0, SK_Scalar1);
|
||||
#ifdef SK_SCALAR_IS_FLOAT
|
||||
return (int) (pin * 65535.0f);
|
||||
#else
|
||||
return pin - (pin >= 32768);
|
||||
#endif
|
||||
}
|
||||
|
||||
class SkGradientUnitMapper : public SkUnitMapper {
|
||||
public:
|
||||
SkGradientUnitMapper(SkAnimateMaker* maker, const char* script) : fMaker(maker), fScript(script) {
|
||||
}
|
||||
|
||||
// overrides for SkFlattenable
|
||||
virtual Factory getFactory() { return NULL; }
|
||||
|
||||
protected:
|
||||
virtual uint16_t mapUnit16(uint16_t x) {
|
||||
fUnit = SkUnitToScalar(x);
|
||||
SkScriptValue value;
|
||||
SkAnimatorScript engine(*fMaker, NULL, SkType_Float);
|
||||
engine.propertyCallBack(GetUnitValue, &fUnit);
|
||||
if (engine.evaluate(fScript, &value, SkType_Float))
|
||||
x = SkScalarToUnit(value.fOperand.fScalar);
|
||||
return x;
|
||||
}
|
||||
|
||||
static bool GetUnitValue(const char* token, size_t len, void* unitPtr, SkScriptValue* value) {
|
||||
if (SK_LITERAL_STR_EQUAL("unit", token, len)) {
|
||||
value->fOperand.fScalar = *(SkScalar*) unitPtr;
|
||||
value->fType = SkType_Float;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SkAnimateMaker* fMaker;
|
||||
const char* fScript;
|
||||
SkScalar fUnit;
|
||||
};
|
||||
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkGradient::fInfo[] = {
|
||||
SK_MEMBER_INHERITED,
|
||||
SK_MEMBER_ARRAY(offsets, Float),
|
||||
SK_MEMBER(unitMapper, String)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkGradient);
|
||||
|
||||
SkGradient::SkGradient() : fUnitMapper(NULL) {
|
||||
}
|
||||
|
||||
SkGradient::~SkGradient() {
|
||||
for (int index = 0; index < fDrawColors.count(); index++)
|
||||
delete fDrawColors[index];
|
||||
delete fUnitMapper;
|
||||
}
|
||||
|
||||
bool SkGradient::add(SkAnimateMaker& , SkDisplayable* child) {
|
||||
SkASSERT(child);
|
||||
if (child->isColor()) {
|
||||
SkDrawColor* color = (SkDrawColor*) child;
|
||||
*fDrawColors.append() = color;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int SkGradient::addPrelude() {
|
||||
int count = fDrawColors.count();
|
||||
fColors.setCount(count);
|
||||
for (int index = 0; index < count; index++)
|
||||
fColors[index] = fDrawColors[index]->color;
|
||||
return count;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkGradient::dumpRest(SkAnimateMaker* maker) {
|
||||
dumpAttrs(maker);
|
||||
//can a gradient have no colors?
|
||||
bool closedYet = false;
|
||||
SkDisplayList::fIndent += 4;
|
||||
for (SkDrawColor** ptr = fDrawColors.begin(); ptr < fDrawColors.end(); ptr++) {
|
||||
if (closedYet == false) {
|
||||
SkDebugf(">\n");
|
||||
closedYet = true;
|
||||
}
|
||||
SkDrawColor* color = *ptr;
|
||||
color->dump(maker);
|
||||
}
|
||||
SkDisplayList::fIndent -= 4;
|
||||
dumpChildren(maker, closedYet); //dumps the matrix if it has one
|
||||
}
|
||||
#endif
|
||||
|
||||
void SkGradient::onEndElement(SkAnimateMaker& maker) {
|
||||
if (offsets.count() != 0) {
|
||||
if (offsets.count() != fDrawColors.count()) {
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kGradientOffsetsDontMatchColors);
|
||||
return;
|
||||
}
|
||||
if (offsets[0] != 0) {
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kGradientOffsetsMustStartWithZero);
|
||||
return;
|
||||
}
|
||||
if (offsets[offsets.count()-1] != SK_Scalar1) {
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kGradientOffsetsMustEndWithOne);
|
||||
return;
|
||||
}
|
||||
for (int i = 1; i < offsets.count(); i++) {
|
||||
if (offsets[i] <= offsets[i-1]) {
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kGradientOffsetsMustIncrease);
|
||||
return;
|
||||
}
|
||||
if (offsets[i] > SK_Scalar1) {
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kGradientOffsetsMustBeNoMoreThanOne);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (unitMapper.size() > 0)
|
||||
fUnitMapper = new SkGradientUnitMapper(&maker, unitMapper.c_str());
|
||||
INHERITED::onEndElement(maker);
|
||||
}
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkLinearGradient::fInfo[] = {
|
||||
SK_MEMBER_INHERITED,
|
||||
SK_MEMBER_ARRAY(points, Float),
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkLinearGradient);
|
||||
|
||||
SkLinearGradient::SkLinearGradient() {
|
||||
}
|
||||
|
||||
void SkLinearGradient::onEndElement(SkAnimateMaker& maker)
|
||||
{
|
||||
if (points.count() != 4)
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kGradientPointsLengthMustBeFour);
|
||||
INHERITED::onEndElement(maker);
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkLinearGradient::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
dumpRest(maker);
|
||||
}
|
||||
#endif
|
||||
|
||||
SkShader* SkLinearGradient::getShader() {
|
||||
if (addPrelude() == 0 || points.count() != 4)
|
||||
return NULL;
|
||||
SkShader* shader = SkGradientShader::CreateLinear((SkPoint*)points.begin(),
|
||||
fColors.begin(), offsets.begin(), fColors.count(), (SkShader::TileMode) tileMode, fUnitMapper);
|
||||
SkAutoTDelete<SkShader> autoDel(shader);
|
||||
addPostlude(shader);
|
||||
(void)autoDel.detach();
|
||||
return shader;
|
||||
}
|
||||
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkRadialGradient::fInfo[] = {
|
||||
SK_MEMBER_INHERITED,
|
||||
SK_MEMBER(center, Point),
|
||||
SK_MEMBER(radius, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkRadialGradient);
|
||||
|
||||
SkRadialGradient::SkRadialGradient() : radius(0) {
|
||||
center.set(0, 0);
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkRadialGradient::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
dumpRest(maker);
|
||||
}
|
||||
#endif
|
||||
|
||||
SkShader* SkRadialGradient::getShader() {
|
||||
if (addPrelude() == 0)
|
||||
return NULL;
|
||||
SkShader* shader = SkGradientShader::CreateRadial(center,
|
||||
radius, fColors.begin(), offsets.begin(), fColors.count(), (SkShader::TileMode) tileMode, fUnitMapper);
|
||||
SkAutoTDelete<SkShader> autoDel(shader);
|
||||
addPostlude(shader);
|
||||
(void)autoDel.detach();
|
||||
return shader;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/* libs/graphics/animator/SkDrawGradient.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawGradient_DEFINED
|
||||
#define SkDrawGradient_DEFINED
|
||||
|
||||
#include "SkDrawColor.h"
|
||||
#include "SkDrawShader.h"
|
||||
#include "SkIntArray.h"
|
||||
|
||||
class SkUnitMapper;
|
||||
|
||||
class SkGradient : public SkDrawShader {
|
||||
DECLARE_PRIVATE_MEMBER_INFO(Gradient);
|
||||
SkGradient();
|
||||
virtual ~SkGradient();
|
||||
virtual bool add(SkAnimateMaker& , SkDisplayable* child);
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dumpRest(SkAnimateMaker*);
|
||||
#endif
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
protected:
|
||||
SkTDScalarArray offsets;
|
||||
SkString unitMapper;
|
||||
SkTDColorArray fColors;
|
||||
SkTDDrawColorArray fDrawColors;
|
||||
SkUnitMapper* fUnitMapper;
|
||||
int addPrelude();
|
||||
private:
|
||||
typedef SkDrawShader INHERITED;
|
||||
};
|
||||
|
||||
class SkLinearGradient : public SkGradient {
|
||||
DECLARE_MEMBER_INFO(LinearGradient);
|
||||
SkLinearGradient();
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker*);
|
||||
#endif
|
||||
virtual SkShader* getShader();
|
||||
protected:
|
||||
SkTDScalarArray points;
|
||||
private:
|
||||
typedef SkGradient INHERITED;
|
||||
};
|
||||
|
||||
class SkRadialGradient : public SkGradient {
|
||||
DECLARE_MEMBER_INFO(RadialGradient);
|
||||
SkRadialGradient();
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker*);
|
||||
#endif
|
||||
virtual SkShader* getShader();
|
||||
protected:
|
||||
SkPoint center;
|
||||
SkScalar radius;
|
||||
private:
|
||||
typedef SkGradient INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDrawGradient_DEFINED
|
||||
|
||||
@@ -0,0 +1,331 @@
|
||||
/* libs/graphics/animator/SkDrawGroup.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawGroup.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkAnimatorScript.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkDisplayApply.h"
|
||||
#include "SkPaint.h"
|
||||
#ifdef SK_DEBUG
|
||||
#include "SkDisplayList.h"
|
||||
#endif
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkGroup::fInfo[] = {
|
||||
SK_MEMBER(condition, String),
|
||||
SK_MEMBER(enableCondition, String)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkGroup);
|
||||
|
||||
SkGroup::SkGroup() : fParentList(NULL), fOriginal(NULL) {
|
||||
}
|
||||
|
||||
SkGroup::~SkGroup() {
|
||||
if (fOriginal) // has been copied
|
||||
return;
|
||||
int index = 0;
|
||||
int max = fCopies.count() << 5;
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
if (index >= max || markedForDelete(index))
|
||||
delete *ptr;
|
||||
// else {
|
||||
// SkApply* apply = (SkApply*) *ptr;
|
||||
// SkASSERT(apply->isApply());
|
||||
// SkASSERT(apply->getScope());
|
||||
// delete apply->getScope();
|
||||
// }
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
bool SkGroup::add(SkAnimateMaker& , SkDisplayable* child) {
|
||||
SkASSERT(child);
|
||||
// SkASSERT(child->isDrawable());
|
||||
*fChildren.append() = (SkDrawable*) child;
|
||||
if (child->isGroup()) {
|
||||
SkGroup* groupie = (SkGroup*) child;
|
||||
SkASSERT(groupie->fParentList == NULL);
|
||||
groupie->fParentList = &fChildren;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkGroup::contains(SkDisplayable* match) {
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
SkDrawable* drawable = *ptr;
|
||||
if (drawable == match || drawable->contains(match))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SkGroup* SkGroup::copy() {
|
||||
SkGroup* result = new SkGroup();
|
||||
result->fOriginal = this;
|
||||
result->fChildren = fChildren;
|
||||
return result;
|
||||
}
|
||||
|
||||
SkBool SkGroup::copySet(int index) {
|
||||
return (fCopies[index >> 5] & 1 << (index & 0x1f)) != 0;
|
||||
}
|
||||
|
||||
SkDisplayable* SkGroup::deepCopy(SkAnimateMaker* maker) {
|
||||
SkDisplayable* copy = INHERITED::deepCopy(maker);
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
SkDisplayable* displayable = (SkDisplayable*)*ptr;
|
||||
SkDisplayable* deeperCopy = displayable->deepCopy(maker);
|
||||
((SkGroup*)copy)->add(*maker, deeperCopy);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
bool SkGroup::doEvent(SkDisplayEvent::Kind kind, SkEventState* state) {
|
||||
bool handled = false;
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
SkDrawable* drawable = *ptr;
|
||||
if (drawable->isDrawable() == false)
|
||||
continue;
|
||||
handled |= drawable->doEvent(kind, state);
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
bool SkGroup::draw(SkAnimateMaker& maker) {
|
||||
bool conditionTrue = ifCondition(maker, this, condition);
|
||||
bool result = false;
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
SkDrawable* drawable = *ptr;
|
||||
if (drawable->isDrawable() == false)
|
||||
continue;
|
||||
if (conditionTrue == false) {
|
||||
if (drawable->isApply())
|
||||
((SkApply*) drawable)->disable();
|
||||
continue;
|
||||
}
|
||||
maker.validate();
|
||||
result |= drawable->draw(maker);
|
||||
maker.validate();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkGroup::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
if (condition.size() > 0)
|
||||
SkDebugf("condition=\"%s\" ", condition.c_str());
|
||||
if (enableCondition.size() > 0)
|
||||
SkDebugf("enableCondition=\"%s\" ", enableCondition.c_str());
|
||||
dumpDrawables(maker);
|
||||
}
|
||||
|
||||
void SkGroup::dumpDrawables(SkAnimateMaker* maker) {
|
||||
SkDisplayList::fIndent += 4;
|
||||
int save = SkDisplayList::fDumpIndex;
|
||||
SkDisplayList::fDumpIndex = 0;
|
||||
bool closedYet = false;
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
if (closedYet == false) {
|
||||
closedYet = true;
|
||||
SkDebugf(">\n");
|
||||
}
|
||||
SkDrawable* drawable = *ptr;
|
||||
drawable->dump(maker);
|
||||
SkDisplayList::fDumpIndex++;
|
||||
}
|
||||
SkDisplayList::fIndent -= 4;
|
||||
SkDisplayList::fDumpIndex = save;
|
||||
if (closedYet) //we had children, now it's time to close the group
|
||||
dumpEnd(maker);
|
||||
else //no children
|
||||
SkDebugf("/>\n");
|
||||
}
|
||||
|
||||
void SkGroup::dumpEvents() {
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
SkDrawable* drawable = *ptr;
|
||||
drawable->dumpEvents();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SkGroup::enable(SkAnimateMaker& maker ) {
|
||||
reset();
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
SkDrawable* drawable = *ptr;
|
||||
if (ifCondition(maker, drawable, enableCondition) == false)
|
||||
continue;
|
||||
drawable->enable(maker);
|
||||
}
|
||||
return true; // skip add; already added so that scope is findable by children
|
||||
}
|
||||
|
||||
int SkGroup::findGroup(SkDrawable* match, SkTDDrawableArray** list,
|
||||
SkGroup** parent, SkGroup** found, SkTDDrawableArray** grandList) {
|
||||
*list = &fChildren;
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
SkDrawable* drawable = *ptr;
|
||||
if (drawable->isGroup()) {
|
||||
SkGroup* childGroup = (SkGroup*) drawable;
|
||||
if (childGroup->fOriginal == match)
|
||||
goto foundMatch;
|
||||
}
|
||||
if (drawable == match) {
|
||||
foundMatch:
|
||||
*parent = this;
|
||||
return (int) (ptr - fChildren.begin());
|
||||
}
|
||||
}
|
||||
*grandList = &fChildren;
|
||||
return SkDisplayList::SearchForMatch(match, list, parent, found, grandList);
|
||||
}
|
||||
|
||||
bool SkGroup::hasEnable() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkGroup::ifCondition(SkAnimateMaker& maker, SkDrawable* drawable,
|
||||
SkString& conditionString) {
|
||||
if (conditionString.size() == 0)
|
||||
return true;
|
||||
int32_t result;
|
||||
bool success = SkAnimatorScript::EvaluateInt(maker, this, conditionString.c_str(), &result);
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
if (maker.fDumpGConditions) {
|
||||
SkDebugf("group: ");
|
||||
dumpBase(&maker);
|
||||
SkDebugf("condition=%s ", conditionString.c_str());
|
||||
if (success == false)
|
||||
SkDebugf("(script failed)\n");
|
||||
else
|
||||
SkDebugf("success=%s\n", result != 0 ? "true" : "false");
|
||||
}
|
||||
#endif
|
||||
return success && result != 0;
|
||||
}
|
||||
|
||||
void SkGroup::initialize() {
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
SkDrawable* drawable = *ptr;
|
||||
if (drawable->isDrawable() == false)
|
||||
continue;
|
||||
drawable->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
void SkGroup::markCopyClear(int index) {
|
||||
if (index < 0)
|
||||
index = fChildren.count();
|
||||
fCopies[index >> 5] &= ~(1 << (index & 0x1f));
|
||||
}
|
||||
|
||||
void SkGroup::markCopySet(int index) {
|
||||
if (index < 0)
|
||||
index = fChildren.count();
|
||||
fCopies[index >> 5] |= 1 << (index & 0x1f);
|
||||
}
|
||||
|
||||
void SkGroup::markCopySize(int index) {
|
||||
if (index < 0)
|
||||
index = fChildren.count() + 1;
|
||||
int oldLongs = fCopies.count();
|
||||
int newLongs = (index >> 5) + 1;
|
||||
if (oldLongs < newLongs) {
|
||||
fCopies.setCount(newLongs);
|
||||
memset(&fCopies[oldLongs], 0, (newLongs - oldLongs) << 2);
|
||||
}
|
||||
}
|
||||
|
||||
void SkGroup::reset() {
|
||||
if (fOriginal) // has been copied
|
||||
return;
|
||||
int index = 0;
|
||||
int max = fCopies.count() << 5;
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
if (index >= max || copySet(index) == false)
|
||||
continue;
|
||||
SkApply* apply = (SkApply*) *ptr;
|
||||
SkASSERT(apply->isApply());
|
||||
SkASSERT(apply->getScope());
|
||||
*ptr = apply->getScope();
|
||||
markCopyClear(index);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
bool SkGroup::resolveIDs(SkAnimateMaker& maker, SkDisplayable* orig, SkApply* apply) {
|
||||
SkGroup* original = (SkGroup*) orig;
|
||||
SkTDDrawableArray& originalChildren = original->fChildren;
|
||||
SkDrawable** originalPtr = originalChildren.begin();
|
||||
SkDrawable** ptr = fChildren.begin();
|
||||
SkDrawable** end = fChildren.end();
|
||||
SkDrawable** origChild = ((SkGroup*) orig)->fChildren.begin();
|
||||
while (ptr < end) {
|
||||
SkDrawable* drawable = *ptr++;
|
||||
maker.resolveID(drawable, *origChild++);
|
||||
if (drawable->resolveIDs(maker, *originalPtr++, apply) == true)
|
||||
return true; // failed
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkGroup::setSteps(int steps) {
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
SkDrawable* drawable = *ptr;
|
||||
if (drawable->isDrawable() == false)
|
||||
continue;
|
||||
drawable->setSteps(steps);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void SkGroup::validate() {
|
||||
for (SkDrawable** ptr = fChildren.begin(); ptr < fChildren.end(); ptr++) {
|
||||
SkDrawable* drawable = *ptr;
|
||||
drawable->validate();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkSave::fInfo[] = {
|
||||
SK_MEMBER_INHERITED
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkSave);
|
||||
|
||||
bool SkSave::draw(SkAnimateMaker& maker) {
|
||||
maker.fCanvas->save();
|
||||
SkPaint* save = maker.fPaint;
|
||||
SkPaint local = SkPaint(*maker.fPaint);
|
||||
maker.fPaint = &local;
|
||||
bool result = INHERITED::draw(maker);
|
||||
maker.fPaint = save;
|
||||
maker.fCanvas->restore();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/* libs/graphics/animator/SkDrawGroup.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawGroup_DEFINED
|
||||
#define SkDrawGroup_DEFINED
|
||||
|
||||
#include "SkDrawable.h"
|
||||
#include "SkIntArray.h"
|
||||
#include "SkMemberInfo.h"
|
||||
|
||||
class SkGroup : public SkDrawable { //interface for schema element <g>
|
||||
public:
|
||||
DECLARE_MEMBER_INFO(Group);
|
||||
SkGroup();
|
||||
virtual ~SkGroup();
|
||||
virtual bool add(SkAnimateMaker& , SkDisplayable* child);
|
||||
virtual bool contains(SkDisplayable* );
|
||||
SkGroup* copy();
|
||||
SkBool copySet(int index);
|
||||
virtual SkDisplayable* deepCopy(SkAnimateMaker* );
|
||||
virtual bool doEvent(SkDisplayEvent::Kind , SkEventState* state );
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
virtual void dumpDrawables(SkAnimateMaker* );
|
||||
virtual void dumpEvents();
|
||||
#endif
|
||||
int findGroup(SkDrawable* drawable, SkTDDrawableArray** list,
|
||||
SkGroup** parent, SkGroup** found, SkTDDrawableArray** grandList);
|
||||
virtual bool enable(SkAnimateMaker& );
|
||||
SkTDDrawableArray* getChildren() { return &fChildren; }
|
||||
SkGroup* getOriginal() { return fOriginal; }
|
||||
virtual bool hasEnable() const;
|
||||
virtual void initialize();
|
||||
SkBool isACopy() { return fOriginal != NULL; }
|
||||
void markCopyClear(int index);
|
||||
void markCopySet(int index);
|
||||
void markCopySize(int index);
|
||||
bool markedForDelete(int index) const { return (fCopies[index >> 5] & 1 << (index & 0x1f)) == 0; }
|
||||
void reset();
|
||||
bool resolveIDs(SkAnimateMaker& maker, SkDisplayable* original, SkApply* );
|
||||
virtual void setSteps(int steps);
|
||||
#ifdef SK_DEBUG
|
||||
virtual void validate();
|
||||
#endif
|
||||
protected:
|
||||
bool ifCondition(SkAnimateMaker& maker, SkDrawable* drawable,
|
||||
SkString& conditionString);
|
||||
SkString condition;
|
||||
SkString enableCondition;
|
||||
SkTDDrawableArray fChildren;
|
||||
SkTDDrawableArray* fParentList;
|
||||
SkTDIntArray fCopies;
|
||||
SkGroup* fOriginal;
|
||||
private:
|
||||
typedef SkDrawable INHERITED;
|
||||
};
|
||||
|
||||
class SkSave: public SkGroup {
|
||||
DECLARE_MEMBER_INFO(Save);
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
private:
|
||||
typedef SkGroup INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDrawGroup_DEFINED
|
||||
@@ -0,0 +1,43 @@
|
||||
/* libs/graphics/animator/SkDrawLine.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawLine.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkPaint.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkLine::fInfo[] = {
|
||||
SK_MEMBER(x1, Float),
|
||||
SK_MEMBER(x2, Float),
|
||||
SK_MEMBER(y1, Float),
|
||||
SK_MEMBER(y2, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkLine);
|
||||
|
||||
SkLine::SkLine() : x1(0), x2(0), y1(0), y2(0) {
|
||||
}
|
||||
|
||||
bool SkLine::draw(SkAnimateMaker& maker) {
|
||||
SkBoundableAuto boundable(this, maker);
|
||||
maker.fCanvas->drawLine(x1, y1, x2, y2, *maker.fPaint);
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/* libs/graphics/animator/SkDrawLine.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawLine_DEFINED
|
||||
#define SkDrawLine_DEFINED
|
||||
|
||||
#include "SkBoundable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
|
||||
class SkLine : public SkBoundable {
|
||||
DECLARE_MEMBER_INFO(Line);
|
||||
SkLine();
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
private:
|
||||
SkScalar x1;
|
||||
SkScalar x2;
|
||||
SkScalar y1;
|
||||
SkScalar y2;
|
||||
typedef SkBoundable INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDrawLine_DEFINED
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
/* libs/graphics/animator/SkDrawMatrix.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawMatrix.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkParse.h"
|
||||
#include "SkMatrixParts.h"
|
||||
#include "SkScript.h"
|
||||
#include "SkTypedArray.h"
|
||||
|
||||
enum SkDrawMatrix_Properties {
|
||||
SK_PROPERTY(perspectX),
|
||||
SK_PROPERTY(perspectY),
|
||||
SK_PROPERTY(rotate),
|
||||
SK_PROPERTY(scale),
|
||||
SK_PROPERTY(scaleX),
|
||||
SK_PROPERTY(scaleY),
|
||||
SK_PROPERTY(skewX),
|
||||
SK_PROPERTY(skewY),
|
||||
SK_PROPERTY(translate),
|
||||
SK_PROPERTY(translateX),
|
||||
SK_PROPERTY(translateY)
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawMatrix::fInfo[] = {
|
||||
SK_MEMBER_ARRAY(matrix, Float),
|
||||
SK_MEMBER_PROPERTY(perspectX, Float),
|
||||
SK_MEMBER_PROPERTY(perspectY, Float),
|
||||
SK_MEMBER_PROPERTY(rotate, Float),
|
||||
SK_MEMBER_PROPERTY(scale, Float),
|
||||
SK_MEMBER_PROPERTY(scaleX, Float),
|
||||
SK_MEMBER_PROPERTY(scaleY, Float),
|
||||
SK_MEMBER_PROPERTY(skewX, Float),
|
||||
SK_MEMBER_PROPERTY(skewY, Float),
|
||||
SK_MEMBER_PROPERTY(translate, Point),
|
||||
SK_MEMBER_PROPERTY(translateX, Float),
|
||||
SK_MEMBER_PROPERTY(translateY, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawMatrix);
|
||||
|
||||
SkDrawMatrix::SkDrawMatrix() : fChildHasID(false), fDirty(false) {
|
||||
fConcat.reset();
|
||||
fMatrix.reset();
|
||||
}
|
||||
|
||||
SkDrawMatrix::~SkDrawMatrix() {
|
||||
for (SkMatrixPart** part = fParts.begin(); part < fParts.end(); part++)
|
||||
delete *part;
|
||||
}
|
||||
|
||||
bool SkDrawMatrix::add(SkAnimateMaker& maker, SkDisplayable* child) {
|
||||
SkASSERT(child && child->isMatrixPart());
|
||||
SkMatrixPart* part = (SkMatrixPart*) child;
|
||||
*fParts.append() = part;
|
||||
if (part->add())
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kErrorAddingToMatrix);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkDrawMatrix::childrenNeedDisposing() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
SkDisplayable* SkDrawMatrix::deepCopy(SkAnimateMaker* maker) {
|
||||
SkDrawMatrix* copy = (SkDrawMatrix*)
|
||||
SkDisplayType::CreateInstance(maker, SkType_Matrix);
|
||||
SkASSERT(fParts.count() == 0);
|
||||
copy->fMatrix = fMatrix;
|
||||
copy->fConcat = fConcat;
|
||||
return copy;
|
||||
}
|
||||
|
||||
void SkDrawMatrix::dirty() {
|
||||
fDirty = true;
|
||||
}
|
||||
|
||||
bool SkDrawMatrix::draw(SkAnimateMaker& maker) {
|
||||
SkMatrix& concat = getMatrix();
|
||||
maker.fCanvas->concat(concat);
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkDrawMatrix::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
if (fMatrix.isIdentity()) {
|
||||
SkDebugf("matrix=\"identity\"/>\n");
|
||||
return;
|
||||
}
|
||||
SkScalar result;
|
||||
result = fMatrix[SkMatrix::kMScaleX];
|
||||
if (result != SK_Scalar1)
|
||||
SkDebugf("sx=\"%g\" ", SkScalarToFloat(result));
|
||||
result = fMatrix.getScaleY();
|
||||
if (result != SK_Scalar1)
|
||||
SkDebugf("sy=\"%g\" ", SkScalarToFloat(result));
|
||||
result = fMatrix.getSkewX();
|
||||
if (result)
|
||||
SkDebugf("skew-x=\"%g\" ", SkScalarToFloat(result));
|
||||
result = fMatrix.getSkewY();
|
||||
if (result)
|
||||
SkDebugf("skew-y=\"%g\" ", SkScalarToFloat(result));
|
||||
result = fMatrix.getTranslateX();
|
||||
if (result)
|
||||
SkDebugf("tx=\"%g\" ", SkScalarToFloat(result));
|
||||
result = fMatrix.getTranslateY();
|
||||
if (result)
|
||||
SkDebugf("ty=\"%g\" ", SkScalarToFloat(result));
|
||||
result = fMatrix.getPerspX();
|
||||
if (result)
|
||||
SkDebugf("perspect-x=\"%g\" ", SkScalarToFloat(result));
|
||||
result = fMatrix.getPerspY();
|
||||
if (result)
|
||||
SkDebugf("perspect-y=\"%g\" ", SkScalarToFloat(result));
|
||||
SkDebugf("/>\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
SkMatrix& SkDrawMatrix::getMatrix() {
|
||||
if (fDirty == false)
|
||||
return fConcat;
|
||||
fMatrix.reset();
|
||||
for (SkMatrixPart** part = fParts.begin(); part < fParts.end(); part++) {
|
||||
(*part)->add();
|
||||
fConcat = fMatrix;
|
||||
}
|
||||
fDirty = false;
|
||||
return fConcat;
|
||||
}
|
||||
|
||||
bool SkDrawMatrix::getProperty(int index, SkScriptValue* value) const {
|
||||
value->fType = SkType_Float;
|
||||
SkScalar result;
|
||||
switch (index) {
|
||||
case SK_PROPERTY(perspectX):
|
||||
result = fMatrix.getPerspX();
|
||||
break;
|
||||
case SK_PROPERTY(perspectY):
|
||||
result = fMatrix.getPerspY();
|
||||
break;
|
||||
case SK_PROPERTY(scaleX):
|
||||
result = fMatrix.getScaleX();
|
||||
break;
|
||||
case SK_PROPERTY(scaleY):
|
||||
result = fMatrix.getScaleY();
|
||||
break;
|
||||
case SK_PROPERTY(skewX):
|
||||
result = fMatrix.getSkewX();
|
||||
break;
|
||||
case SK_PROPERTY(skewY):
|
||||
result = fMatrix.getSkewY();
|
||||
break;
|
||||
case SK_PROPERTY(translateX):
|
||||
result = fMatrix.getTranslateX();
|
||||
break;
|
||||
case SK_PROPERTY(translateY):
|
||||
result = fMatrix.getTranslateY();
|
||||
break;
|
||||
default:
|
||||
// SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
value->fOperand.fScalar = result;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkDrawMatrix::initialize() {
|
||||
fConcat = fMatrix;
|
||||
}
|
||||
|
||||
void SkDrawMatrix::onEndElement(SkAnimateMaker& ) {
|
||||
if (matrix.count() > 0) {
|
||||
SkScalar* vals = matrix.begin();
|
||||
fMatrix.setScaleX(vals[0]);
|
||||
fMatrix.setSkewX(vals[1]);
|
||||
fMatrix.setTranslateX(vals[2]);
|
||||
fMatrix.setSkewY(vals[3]);
|
||||
fMatrix.setScaleY(vals[4]);
|
||||
fMatrix.setTranslateY(vals[5]);
|
||||
#ifdef SK_SCALAR_IS_FIXED
|
||||
fMatrix.setPerspX(SkFixedToFract(vals[6]));
|
||||
fMatrix.setPerspY(SkFixedToFract(vals[7]));
|
||||
#else
|
||||
fMatrix.setPerspX(vals[6]);
|
||||
fMatrix.setPerspY(vals[7]);
|
||||
#endif
|
||||
// fMatrix.setPerspW(vals[8]);
|
||||
goto setConcat;
|
||||
}
|
||||
if (fChildHasID == false) {
|
||||
{
|
||||
for (SkMatrixPart** part = fParts.begin(); part < fParts.end(); part++)
|
||||
delete *part;
|
||||
}
|
||||
fParts.reset();
|
||||
setConcat:
|
||||
fConcat = fMatrix;
|
||||
fDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void SkDrawMatrix::setChildHasID() {
|
||||
fChildHasID = true;
|
||||
}
|
||||
|
||||
bool SkDrawMatrix::setProperty(int index, SkScriptValue& scriptValue) {
|
||||
SkScalar number = scriptValue.fOperand.fScalar;
|
||||
switch (index) {
|
||||
case SK_PROPERTY(translate):
|
||||
// SkScalar xy[2];
|
||||
SkASSERT(scriptValue.fType == SkType_Array);
|
||||
SkASSERT(scriptValue.fOperand.fArray->getType() == SkType_Float);
|
||||
SkASSERT(scriptValue.fOperand.fArray->count() == 2);
|
||||
// SkParse::FindScalars(scriptValue.fOperand.fString->c_str(), xy, 2);
|
||||
fMatrix.setTranslateX((*scriptValue.fOperand.fArray)[0].fScalar);
|
||||
fMatrix.setTranslateY((*scriptValue.fOperand.fArray)[1].fScalar);
|
||||
return true;
|
||||
case SK_PROPERTY(perspectX):
|
||||
#ifdef SK_SCALAR_IS_FIXED
|
||||
fMatrix.setPerspX(SkFixedToFract(number));
|
||||
#else
|
||||
fMatrix.setPerspX(number);
|
||||
#endif
|
||||
break;
|
||||
case SK_PROPERTY(perspectY):
|
||||
#ifdef SK_SCALAR_IS_FIXED
|
||||
fMatrix.setPerspY(SkFixedToFract(number));
|
||||
#else
|
||||
fMatrix.setPerspY(number);
|
||||
#endif
|
||||
break;
|
||||
case SK_PROPERTY(rotate): {
|
||||
SkMatrix temp;
|
||||
temp.setRotate(number, 0, 0);
|
||||
fMatrix.setScaleX(temp.getScaleX());
|
||||
fMatrix.setScaleY(temp.getScaleY());
|
||||
fMatrix.setSkewX(temp.getSkewX());
|
||||
fMatrix.setSkewY(temp.getSkewY());
|
||||
} break;
|
||||
case SK_PROPERTY(scale):
|
||||
fMatrix.setScaleX(number);
|
||||
fMatrix.setScaleY(number);
|
||||
break;
|
||||
case SK_PROPERTY(scaleX):
|
||||
fMatrix.setScaleX(number);
|
||||
break;
|
||||
case SK_PROPERTY(scaleY):
|
||||
fMatrix.setScaleY(number);
|
||||
break;
|
||||
case SK_PROPERTY(skewX):
|
||||
fMatrix.setSkewX(number);
|
||||
break;
|
||||
case SK_PROPERTY(skewY):
|
||||
fMatrix.setSkewY(number);
|
||||
break;
|
||||
case SK_PROPERTY(translateX):
|
||||
fMatrix.setTranslateX(number);
|
||||
break;
|
||||
case SK_PROPERTY(translateY):
|
||||
fMatrix.setTranslateY(number);
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
fConcat = fMatrix;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/* libs/graphics/animator/SkDrawMatrix.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawMatrix_DEFINED
|
||||
#define SkDrawMatrix_DEFINED
|
||||
|
||||
#include "SkDrawable.h"
|
||||
#include "SkMatrix.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkIntArray.h"
|
||||
|
||||
class SkMatrixPart;
|
||||
|
||||
class SkDrawMatrix : public SkDrawable {
|
||||
DECLARE_DRAW_MEMBER_INFO(Matrix);
|
||||
SkDrawMatrix();
|
||||
virtual ~SkDrawMatrix();
|
||||
virtual bool add(SkAnimateMaker& , SkDisplayable* child);
|
||||
virtual bool childrenNeedDisposing() const;
|
||||
virtual void dirty();
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
SkMatrix& getMatrix();
|
||||
virtual bool getProperty(int index, SkScriptValue* value) const;
|
||||
virtual void initialize();
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
virtual void setChildHasID();
|
||||
virtual bool setProperty(int index, SkScriptValue& );
|
||||
|
||||
void concat(SkMatrix& inMatrix) {
|
||||
fConcat.preConcat(inMatrix);
|
||||
}
|
||||
|
||||
virtual SkDisplayable* deepCopy(SkAnimateMaker* );
|
||||
|
||||
|
||||
void rotate(SkScalar degrees, SkPoint& center) {
|
||||
fMatrix.preRotate(degrees, center.fX, center.fY);
|
||||
}
|
||||
|
||||
void set(SkMatrix& src) {
|
||||
fMatrix.preConcat(src);
|
||||
}
|
||||
|
||||
void scale(SkScalar scaleX, SkScalar scaleY, SkPoint& center) {
|
||||
fMatrix.preScale(scaleX, scaleY, center.fX, center.fY);
|
||||
}
|
||||
|
||||
void skew(SkScalar skewX, SkScalar skewY, SkPoint& center) {
|
||||
fMatrix.preSkew(skewX, skewY, center.fX, center.fY);
|
||||
}
|
||||
|
||||
void translate(SkScalar x, SkScalar y) {
|
||||
fMatrix.preTranslate(x, y);
|
||||
}
|
||||
private:
|
||||
SkTDScalarArray matrix;
|
||||
SkMatrix fConcat;
|
||||
SkMatrix fMatrix;
|
||||
SkTDMatrixPartArray fParts;
|
||||
SkBool8 fChildHasID;
|
||||
SkBool8 fDirty;
|
||||
typedef SkDrawable INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDrawMatrix_DEFINED
|
||||
@@ -0,0 +1,37 @@
|
||||
/* libs/graphics/animator/SkDrawOval.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawOval.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkCanvas.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkOval::fInfo[] = {
|
||||
SK_MEMBER_INHERITED,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkOval);
|
||||
|
||||
bool SkOval::draw(SkAnimateMaker& maker) {
|
||||
SkBoundableAuto boundable(this, maker);
|
||||
maker.fCanvas->drawOval(fRect, *maker.fPaint);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/* libs/graphics/animator/SkDrawOval.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawOval_DEFINED
|
||||
#define SkDrawOval_DEFINED
|
||||
|
||||
#include "SkDrawRectangle.h"
|
||||
|
||||
class SkOval : public SkDrawRect {
|
||||
DECLARE_MEMBER_INFO(Oval);
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
private:
|
||||
typedef SkDrawRect INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDrawOval_DEFINED
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
/* libs/graphics/animator/SkDrawPaint.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawPaint.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkDrawColor.h"
|
||||
#include "SkDrawShader.h"
|
||||
#include "SkMaskFilter.h"
|
||||
#include "SkPaintParts.h"
|
||||
#include "SkPathEffect.h"
|
||||
|
||||
enum SkPaint_Functions {
|
||||
SK_FUNCTION(measureText)
|
||||
};
|
||||
|
||||
enum SkPaint_Properties {
|
||||
SK_PROPERTY(ascent),
|
||||
SK_PROPERTY(descent)
|
||||
};
|
||||
|
||||
// !!! in the future, this could be compiled by build-condensed-info into an array of parameters
|
||||
// with a lookup table to find the first parameter -- for now, it is iteratively searched through
|
||||
const SkFunctionParamType SkDrawPaint::fFunctionParameters[] = {
|
||||
(SkFunctionParamType) SkType_String,
|
||||
(SkFunctionParamType) 0 // terminator for parameter list (there may be multiple parameter lists)
|
||||
};
|
||||
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawPaint::fInfo[] = {
|
||||
SK_MEMBER(antiAlias, Boolean),
|
||||
SK_MEMBER_PROPERTY(ascent, Float),
|
||||
SK_MEMBER(color, Color),
|
||||
SK_MEMBER_PROPERTY(descent, Float),
|
||||
SK_MEMBER(fakeBold, Boolean),
|
||||
SK_MEMBER(filterBitmap, Boolean),
|
||||
SK_MEMBER(linearText, Boolean),
|
||||
SK_MEMBER(maskFilter, MaskFilter),
|
||||
SK_MEMBER_FUNCTION(measureText, Float),
|
||||
SK_MEMBER(pathEffect, PathEffect),
|
||||
SK_MEMBER(shader, Shader),
|
||||
SK_MEMBER(strikeThru, Boolean),
|
||||
SK_MEMBER(stroke, Boolean),
|
||||
SK_MEMBER(strokeCap, Cap),
|
||||
SK_MEMBER(strokeJoin, Join),
|
||||
SK_MEMBER(strokeMiter, Float),
|
||||
SK_MEMBER(strokeWidth, Float),
|
||||
SK_MEMBER(style, Style),
|
||||
SK_MEMBER(textAlign, Align),
|
||||
SK_MEMBER(textScaleX, Float),
|
||||
SK_MEMBER(textSize, Float),
|
||||
SK_MEMBER(textSkewX, Float),
|
||||
SK_MEMBER(typeface, Typeface),
|
||||
SK_MEMBER(underline, Boolean),
|
||||
SK_MEMBER(xfermode, Xfermode)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawPaint);
|
||||
|
||||
SkDrawPaint::SkDrawPaint() : antiAlias(-1), color(NULL), fakeBold(-1), filterBitmap(-1),
|
||||
linearText(-1), maskFilter((SkDrawMaskFilter*) -1), pathEffect((SkDrawPathEffect*) -1),
|
||||
shader((SkDrawShader*) -1), strikeThru(-1), stroke(-1),
|
||||
strokeCap((SkPaint::Cap) -1), strokeJoin((SkPaint::Join) -1), strokeMiter(SK_ScalarNaN),
|
||||
strokeWidth(SK_ScalarNaN), style((SkPaint::Style) -1),
|
||||
textAlign((SkPaint::Align) -1), textScaleX(SK_ScalarNaN), textSize(SK_ScalarNaN),
|
||||
textSkewX(SK_ScalarNaN), typeface((SkDrawTypeface*) -1),
|
||||
underline(-1), xfermode((SkPorterDuff::Mode) -1), fOwnsColor(false), fOwnsMaskFilter(false),
|
||||
fOwnsPathEffect(false), fOwnsShader(false), fOwnsTypeface(false) {
|
||||
}
|
||||
|
||||
SkDrawPaint::~SkDrawPaint() {
|
||||
if (fOwnsColor)
|
||||
delete color;
|
||||
if (fOwnsMaskFilter)
|
||||
delete maskFilter;
|
||||
if (fOwnsPathEffect)
|
||||
delete pathEffect;
|
||||
if (fOwnsShader)
|
||||
delete shader;
|
||||
if (fOwnsTypeface)
|
||||
delete typeface;
|
||||
}
|
||||
|
||||
bool SkDrawPaint::add(SkAnimateMaker& maker, SkDisplayable* child) {
|
||||
SkASSERT(child && child->isPaintPart());
|
||||
SkPaintPart* part = (SkPaintPart*) child;
|
||||
if (part->add())
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kErrorAddingToPaint);
|
||||
return true;
|
||||
}
|
||||
|
||||
SkDisplayable* SkDrawPaint::deepCopy(SkAnimateMaker* maker) {
|
||||
SkDrawColor* tempColor = color;
|
||||
color = NULL;
|
||||
SkDrawPaint* copy = (SkDrawPaint*) INHERITED::deepCopy(maker);
|
||||
color = tempColor;
|
||||
tempColor = (SkDrawColor*) color->deepCopy(maker);
|
||||
tempColor->setParent(copy);
|
||||
tempColor->add();
|
||||
copy->fOwnsColor = true;
|
||||
return copy;
|
||||
}
|
||||
|
||||
bool SkDrawPaint::draw(SkAnimateMaker& maker) {
|
||||
SkPaint* paint = maker.fPaint;
|
||||
setupPaint(paint);
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkDrawPaint::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
dumpAttrs(maker);
|
||||
bool closedYet = false;
|
||||
SkDisplayList::fIndent +=4;
|
||||
//should i say if (maskFilter && ...?
|
||||
if (maskFilter != (SkDrawMaskFilter*)-1) {
|
||||
SkDebugf(">\n");
|
||||
maskFilter->dump(maker);
|
||||
closedYet = true;
|
||||
}
|
||||
if (pathEffect != (SkDrawPathEffect*) -1) {
|
||||
if (closedYet == false) {
|
||||
SkDebugf(">\n");
|
||||
closedYet = true;
|
||||
}
|
||||
pathEffect->dump(maker);
|
||||
}
|
||||
if (fOwnsTypeface) {
|
||||
if (closedYet == false) {
|
||||
SkDebugf(">\n");
|
||||
closedYet = true;
|
||||
}
|
||||
typeface->dump(maker);
|
||||
}
|
||||
SkDisplayList::fIndent -= 4;
|
||||
dumpChildren(maker, closedYet);
|
||||
}
|
||||
#endif
|
||||
|
||||
void SkDrawPaint::executeFunction(SkDisplayable* target, int index,
|
||||
SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
|
||||
SkScriptValue* scriptValue) {
|
||||
if (scriptValue == NULL)
|
||||
return;
|
||||
SkASSERT(target == this);
|
||||
switch (index) {
|
||||
case SK_FUNCTION(measureText): {
|
||||
SkASSERT(parameters.count() == 1);
|
||||
SkASSERT(type == SkType_Float);
|
||||
SkPaint paint;
|
||||
setupPaint(&paint);
|
||||
scriptValue->fType = SkType_Float;
|
||||
SkASSERT(parameters[0].fType == SkType_String);
|
||||
scriptValue->fOperand.fScalar = paint.measureText(parameters[0].fOperand.fString->c_str(),
|
||||
parameters[0].fOperand.fString->size());
|
||||
// SkDebugf("measureText: %s = %g\n", parameters[0].fOperand.fString->c_str(),
|
||||
// scriptValue->fOperand.fScalar / 65536.0f);
|
||||
} break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
const SkFunctionParamType* SkDrawPaint::getFunctionsParameters() {
|
||||
return fFunctionParameters;
|
||||
}
|
||||
|
||||
bool SkDrawPaint::getProperty(int index, SkScriptValue* value) const {
|
||||
SkPaint::FontMetrics metrics;
|
||||
SkPaint paint;
|
||||
setupPaint(&paint);
|
||||
paint.getFontMetrics(&metrics);
|
||||
switch (index) {
|
||||
case SK_PROPERTY(ascent):
|
||||
value->fOperand.fScalar = metrics.fAscent;
|
||||
break;
|
||||
case SK_PROPERTY(descent):
|
||||
value->fOperand.fScalar = metrics.fDescent;
|
||||
break;
|
||||
// should consider returning fLeading as well (or roll it into ascent/descent somehow <reed>
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
value->fType = SkType_Float;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkDrawPaint::resolveIDs(SkAnimateMaker& maker, SkDisplayable* origDisp, SkApply* ) {
|
||||
SkASSERT(origDisp->isPaint());
|
||||
SkDrawPaint* original = (SkDrawPaint*) origDisp;
|
||||
if (fOwnsColor && maker.resolveID(color, original->color) == false)
|
||||
return true;
|
||||
if (fOwnsMaskFilter && maker.resolveID(maskFilter, original->maskFilter) == false)
|
||||
return true;
|
||||
if (fOwnsPathEffect && maker.resolveID(pathEffect, original->pathEffect) == false)
|
||||
return true;
|
||||
if (fOwnsShader && maker.resolveID(shader, original->shader) == false)
|
||||
return true;
|
||||
if (fOwnsTypeface && maker.resolveID(typeface, original->typeface) == false)
|
||||
return true;
|
||||
return false; // succeeded
|
||||
}
|
||||
|
||||
void SkDrawPaint::setupPaint(SkPaint* paint) const {
|
||||
if (antiAlias != -1)
|
||||
paint->setAntiAlias(SkToBool(antiAlias));
|
||||
if (color != NULL)
|
||||
paint->setColor(color->getColor());
|
||||
if (fakeBold != -1)
|
||||
paint->setFakeBoldText(SkToBool(fakeBold));
|
||||
if (filterBitmap != -1)
|
||||
paint->setFilterBitmap(SkToBool(filterBitmap));
|
||||
// stroke is legacy; style setting if present overrides stroke
|
||||
if (stroke != -1)
|
||||
paint->setStyle(SkToBool(stroke) ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
|
||||
if (style != (SkPaint::Style) -1)
|
||||
paint->setStyle((SkPaint::Style) style);
|
||||
if (linearText != -1)
|
||||
paint->setLinearText(SkToBool(linearText));
|
||||
if (maskFilter == NULL)
|
||||
paint->setMaskFilter(NULL);
|
||||
else if (maskFilter != (SkDrawMaskFilter*) -1)
|
||||
paint->setMaskFilter(maskFilter->getMaskFilter())->safeUnref();
|
||||
if (pathEffect == NULL)
|
||||
paint->setPathEffect(NULL);
|
||||
else if (pathEffect != (SkDrawPathEffect*) -1)
|
||||
paint->setPathEffect(pathEffect->getPathEffect())->safeUnref();
|
||||
if (shader == NULL)
|
||||
paint->setShader(NULL);
|
||||
else if (shader != (SkDrawShader*) -1)
|
||||
paint->setShader(shader->getShader())->safeUnref();
|
||||
if (strikeThru != -1)
|
||||
paint->setStrikeThruText(SkToBool(strikeThru));
|
||||
if (strokeCap != (SkPaint::Cap) -1)
|
||||
paint->setStrokeCap((SkPaint::Cap) strokeCap);
|
||||
if (strokeJoin != (SkPaint::Join) -1)
|
||||
paint->setStrokeJoin((SkPaint::Join) strokeJoin);
|
||||
if (SkScalarIsNaN(strokeMiter) == false)
|
||||
paint->setStrokeMiter(strokeMiter);
|
||||
if (SkScalarIsNaN(strokeWidth) == false)
|
||||
paint->setStrokeWidth(strokeWidth);
|
||||
if (textAlign != (SkPaint::Align) -1)
|
||||
paint->setTextAlign((SkPaint::Align) textAlign);
|
||||
if (SkScalarIsNaN(textScaleX) == false)
|
||||
paint->setTextScaleX(textScaleX);
|
||||
if (SkScalarIsNaN(textSize) == false)
|
||||
paint->setTextSize(textSize);
|
||||
if (SkScalarIsNaN(textSkewX) == false)
|
||||
paint->setTextSkewX(textSkewX);
|
||||
if (typeface == NULL)
|
||||
paint->setTypeface(NULL);
|
||||
else if (typeface != (SkDrawTypeface*) -1)
|
||||
paint->setTypeface(typeface->getTypeface())->safeUnref();
|
||||
if (underline != -1)
|
||||
paint->setUnderlineText(SkToBool(underline));
|
||||
if (xfermode != (SkPorterDuff::Mode) -1)
|
||||
paint->setPorterDuffXfermode((SkPorterDuff::Mode) xfermode);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/* libs/graphics/animator/SkDrawPaint.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawPaint_DEFINED
|
||||
#define SkDrawPaint_DEFINED
|
||||
|
||||
#include "SkDrawable.h"
|
||||
#include "SkIntArray.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkXfermode.h"
|
||||
|
||||
class SkDrawMaskFilter;
|
||||
class SkDrawPathEffect;
|
||||
class SkDrawShader;
|
||||
class SkTransferMode;
|
||||
class SkDrawTypeface;
|
||||
|
||||
class SkDrawPaint : public SkDrawable {
|
||||
DECLARE_DRAW_MEMBER_INFO(Paint);
|
||||
SkDrawPaint();
|
||||
virtual ~SkDrawPaint();
|
||||
virtual bool add(SkAnimateMaker& , SkDisplayable* child);
|
||||
virtual SkDisplayable* deepCopy(SkAnimateMaker* );
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
virtual void executeFunction(SkDisplayable* target, int index,
|
||||
SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
|
||||
SkScriptValue* );
|
||||
virtual const SkFunctionParamType* getFunctionsParameters();
|
||||
virtual bool getProperty(int index, SkScriptValue* value) const;
|
||||
virtual bool resolveIDs(SkAnimateMaker& maker, SkDisplayable* original, SkApply* apply);
|
||||
protected:
|
||||
static const SkFunctionParamType fFunctionParameters[];
|
||||
void setupPaint(SkPaint* paint) const;
|
||||
public:
|
||||
SkBool antiAlias;
|
||||
SkDrawColor* color;
|
||||
SkBool fakeBold;
|
||||
SkBool filterBitmap;
|
||||
SkBool linearText;
|
||||
SkDrawMaskFilter* maskFilter;
|
||||
SkDrawPathEffect* pathEffect;
|
||||
SkDrawShader* shader;
|
||||
SkBool strikeThru;
|
||||
SkBool stroke;
|
||||
int /*SkPaint::Cap*/ strokeCap;
|
||||
int /*SkPaint::Join */ strokeJoin;
|
||||
SkScalar strokeMiter;
|
||||
SkScalar strokeWidth;
|
||||
int /* SkPaint::Style */ style;
|
||||
int /* SkPaint::Align */ textAlign;
|
||||
SkScalar textScaleX;
|
||||
SkScalar textSize;
|
||||
SkScalar textSkewX;
|
||||
SkDrawTypeface* typeface;
|
||||
SkBool underline;
|
||||
int /*SkXfermode::Modes*/ xfermode;
|
||||
SkBool8 fOwnsColor;
|
||||
SkBool8 fOwnsMaskFilter;
|
||||
SkBool8 fOwnsPathEffect;
|
||||
SkBool8 fOwnsShader;
|
||||
SkBool8 fOwnsTransferMode;
|
||||
SkBool8 fOwnsTypeface;
|
||||
private:
|
||||
typedef SkDrawable INHERITED;
|
||||
friend class SkTextToPath;
|
||||
friend class SkSaveLayer;
|
||||
};
|
||||
|
||||
#endif // SkDrawPaint_DEFINED
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
/* libs/graphics/animator/SkDrawPath.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawPath.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkMath.h"
|
||||
#include "SkMatrixParts.h"
|
||||
#include "SkPaint.h"
|
||||
#include "SkPathParts.h"
|
||||
|
||||
enum SkPath_Properties {
|
||||
SK_PROPERTY(fillType),
|
||||
SK_PROPERTY(length)
|
||||
};
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawPath::fInfo[] = {
|
||||
SK_MEMBER(d, String),
|
||||
SK_MEMBER_PROPERTY(fillType, FillType),
|
||||
SK_MEMBER_PROPERTY(length, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawPath);
|
||||
|
||||
SkDrawPath::SkDrawPath()
|
||||
{
|
||||
fParent = NULL;
|
||||
fLength = SK_ScalarNaN;
|
||||
fChildHasID = false;
|
||||
fDirty = false;
|
||||
}
|
||||
|
||||
SkDrawPath::~SkDrawPath() {
|
||||
for (SkPathPart** part = fParts.begin(); part < fParts.end(); part++)
|
||||
delete *part;
|
||||
}
|
||||
|
||||
bool SkDrawPath::add(SkAnimateMaker& maker, SkDisplayable* child) {
|
||||
SkASSERT(child && child->isPathPart());
|
||||
SkPathPart* part = (SkPathPart*) child;
|
||||
*fParts.append() = part;
|
||||
if (part->add())
|
||||
maker.setErrorCode(SkDisplayXMLParserError::kErrorAddingToPath);
|
||||
fDirty = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SkDrawPath::childrenNeedDisposing() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkDrawPath::dirty() {
|
||||
fDirty = true;
|
||||
fLength = SK_ScalarNaN;
|
||||
if (fParent)
|
||||
fParent->dirty();
|
||||
}
|
||||
|
||||
bool SkDrawPath::draw(SkAnimateMaker& maker) {
|
||||
SkPath& path = getPath();
|
||||
SkBoundableAuto boundable(this, maker);
|
||||
maker.fCanvas->drawPath(path, *maker.fPaint);
|
||||
return false;
|
||||
}
|
||||
|
||||
SkDisplayable* SkDrawPath::getParent() const {
|
||||
return fParent;
|
||||
}
|
||||
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
void SkDrawPath::dump(SkAnimateMaker* maker) {
|
||||
dumpBase(maker);
|
||||
dumpAttrs(maker);
|
||||
bool closedYet = false;
|
||||
SkDisplayList::fIndent += 4;
|
||||
for(SkPathPart** part = fParts.begin(); part < fParts.end(); part++) {
|
||||
if (closedYet == false) {
|
||||
SkDebugf(">\n");
|
||||
closedYet = true;
|
||||
}
|
||||
(*part)->dump(maker);
|
||||
}
|
||||
SkDisplayList::fIndent -= 4;
|
||||
if (closedYet)
|
||||
dumpEnd(maker);
|
||||
else
|
||||
SkDebugf("/>\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
SkPath& SkDrawPath::getPath() {
|
||||
if (fDirty == false)
|
||||
return fPath;
|
||||
if (d.size() > 0)
|
||||
{
|
||||
parseSVG();
|
||||
d.reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
fPath.reset();
|
||||
for (SkPathPart** part = fParts.begin(); part < fParts.end(); part++)
|
||||
(*part)->add();
|
||||
}
|
||||
fDirty = false;
|
||||
return fPath;
|
||||
}
|
||||
|
||||
void SkDrawPath::onEndElement(SkAnimateMaker& ) {
|
||||
if (d.size() > 0) {
|
||||
parseSVG();
|
||||
d.reset();
|
||||
fDirty = false;
|
||||
return;
|
||||
}
|
||||
if (fChildHasID == false) {
|
||||
for (SkPathPart** part = fParts.begin(); part < fParts.end(); part++)
|
||||
delete *part;
|
||||
fParts.reset();
|
||||
fDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool SkDrawPath::getProperty(int index, SkScriptValue* value) const {
|
||||
switch (index) {
|
||||
case SK_PROPERTY(length):
|
||||
if (SkScalarIsNaN(fLength)) {
|
||||
const SkPath& path = ((SkDrawPath*) this)->getPath();
|
||||
SkPathMeasure pathMeasure(path, false);
|
||||
fLength = pathMeasure.getLength();
|
||||
}
|
||||
value->fType = SkType_Float;
|
||||
value->fOperand.fScalar = fLength;
|
||||
break;
|
||||
case SK_PROPERTY(fillType):
|
||||
value->fType = SkType_FillType;
|
||||
value->fOperand.fS32 = (int) fPath.getFillType();
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkDrawPath::setChildHasID() {
|
||||
fChildHasID = true;
|
||||
}
|
||||
|
||||
bool SkDrawPath::setParent(SkDisplayable* parent) {
|
||||
fParent = parent;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SkDrawPath::setProperty(int index, SkScriptValue& value)
|
||||
{
|
||||
switch (index) {
|
||||
case SK_PROPERTY(fillType):
|
||||
SkASSERT(value.fType == SkType_FillType);
|
||||
SkASSERT(value.fOperand.fS32 >= SkPath::kWinding_FillType &&
|
||||
value.fOperand.fS32 <= SkPath::kEvenOdd_FillType);
|
||||
fPath.setFillType((SkPath::FillType) value.fOperand.fS32);
|
||||
break;
|
||||
default:
|
||||
SkASSERT(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkPolyline::fInfo[] = {
|
||||
SK_MEMBER_ARRAY(points, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkPolyline);
|
||||
|
||||
bool SkPolyline::add(SkAnimateMaker& , SkDisplayable*) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SkPolyline::onEndElement(SkAnimateMaker& maker) {
|
||||
INHERITED::onEndElement(maker);
|
||||
if (points.count() <= 0)
|
||||
return;
|
||||
fPath.reset();
|
||||
fPath.moveTo(points[0], points[1]);
|
||||
int count = points.count();
|
||||
for (int index = 2; index < count; index += 2)
|
||||
fPath.lineTo(points[index], points[index+1]);
|
||||
}
|
||||
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkPolygon::fInfo[] = {
|
||||
SK_MEMBER_INHERITED
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkPolygon);
|
||||
|
||||
void SkPolygon::onEndElement(SkAnimateMaker& maker) {
|
||||
INHERITED::onEndElement(maker);
|
||||
fPath.close();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/* libs/graphics/animator/SkDrawPath.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawPath_DEFINED
|
||||
#define SkDrawPath_DEFINED
|
||||
|
||||
#include "SkBoundable.h"
|
||||
#include "SkIntArray.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkPath.h"
|
||||
|
||||
class SkDrawPath : public SkBoundable {
|
||||
DECLARE_DRAW_MEMBER_INFO(Path);
|
||||
SkDrawPath();
|
||||
virtual ~SkDrawPath();
|
||||
virtual bool add(SkAnimateMaker& , SkDisplayable* child);
|
||||
bool childHasID() { return SkToBool(fChildHasID); }
|
||||
virtual bool childrenNeedDisposing() const;
|
||||
virtual void dirty();
|
||||
virtual bool draw(SkAnimateMaker& );
|
||||
virtual SkDisplayable* getParent() const;
|
||||
#ifdef SK_DUMP_ENABLED
|
||||
virtual void dump(SkAnimateMaker* );
|
||||
#endif
|
||||
SkPath& getPath();
|
||||
virtual bool getProperty(int index, SkScriptValue* value) const;
|
||||
virtual bool setProperty(int index, SkScriptValue& value);
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
virtual void setChildHasID();
|
||||
virtual bool setParent(SkDisplayable* parent);
|
||||
virtual bool isPath() const { return true; }
|
||||
public:
|
||||
SkPath fPath;
|
||||
protected:
|
||||
void parseSVG();
|
||||
SkString d;
|
||||
SkTDPathPartArray fParts;
|
||||
mutable SkScalar fLength;
|
||||
SkDisplayable* fParent; // SkPolyToPoly or SkFromPath, for instance
|
||||
SkBool8 fChildHasID;
|
||||
SkBool8 fDirty;
|
||||
private:
|
||||
typedef SkBoundable INHERITED;
|
||||
};
|
||||
|
||||
class SkPolyline : public SkDrawPath {
|
||||
DECLARE_MEMBER_INFO(Polyline);
|
||||
virtual bool add(SkAnimateMaker& , SkDisplayable*) const;
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
protected:
|
||||
SkTDScalarArray points;
|
||||
private:
|
||||
typedef SkDrawPath INHERITED;
|
||||
};
|
||||
|
||||
class SkPolygon : public SkPolyline {
|
||||
DECLARE_MEMBER_INFO(Polygon);
|
||||
virtual void onEndElement(SkAnimateMaker& );
|
||||
private:
|
||||
typedef SkPolyline INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDrawPath_DEFINED
|
||||
@@ -0,0 +1,54 @@
|
||||
/* libs/graphics/animator/SkDrawPoint.cpp
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#include "SkDrawPoint.h"
|
||||
#include "SkAnimateMaker.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkPaint.h"
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo Sk_Point::fInfo[] = {
|
||||
SK_MEMBER_ALIAS(x, fPoint.fX, Float),
|
||||
SK_MEMBER_ALIAS(y, fPoint.fY, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_NO_VIRTUALS_GET_MEMBER(Sk_Point);
|
||||
|
||||
#if SK_USE_CONDENSED_INFO == 0
|
||||
|
||||
const SkMemberInfo SkDrawPoint::fInfo[] = {
|
||||
SK_MEMBER_ALIAS(x, fPoint.fX, Float),
|
||||
SK_MEMBER_ALIAS(y, fPoint.fY, Float)
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
DEFINE_GET_MEMBER(SkDrawPoint);
|
||||
|
||||
SkDrawPoint::SkDrawPoint() {
|
||||
fPoint.set(0, 0);
|
||||
}
|
||||
|
||||
void SkDrawPoint::getBounds(SkRect* rect ) {
|
||||
rect->fLeft = rect->fRight = fPoint.fX;
|
||||
rect->fTop = rect->fBottom = fPoint.fY;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/* libs/graphics/animator/SkDrawPoint.h
|
||||
**
|
||||
** Copyright 2006, Google Inc.
|
||||
**
|
||||
** 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.
|
||||
*/
|
||||
|
||||
#ifndef SkDrawPoint_DEFINED
|
||||
#define SkDrawPoint_DEFINED
|
||||
|
||||
#include "SkBoundable.h"
|
||||
#include "SkMemberInfo.h"
|
||||
#include "SkPoint.h"
|
||||
|
||||
struct Sk_Point {
|
||||
DECLARE_NO_VIRTUALS_MEMBER_INFO(_Point);
|
||||
Sk_Point();
|
||||
private:
|
||||
SkPoint fPoint;
|
||||
};
|
||||
|
||||
class SkDrawPoint : public SkDisplayable {
|
||||
DECLARE_MEMBER_INFO(DrawPoint);
|
||||
SkDrawPoint();
|
||||
virtual void getBounds(SkRect* );
|
||||
private:
|
||||
SkPoint fPoint;
|
||||
typedef SkDisplayable INHERITED;
|
||||
};
|
||||
|
||||
#endif // SkDrawPoint_DEFINED
|
||||
Alguns arquivos não foram exibidos porque demasiados arquivos foram alterados neste diff Mostrar Mais
Referência em uma Nova Issue
Bloquear um usuário