1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/animator/SkDraw3D.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#include "SkDraw3D.h" 1.14 +#include "SkAnimateMaker.h" 1.15 +#include "SkCanvas.h" 1.16 +#include "SkTypedArray.h" 1.17 + 1.18 +#if SK_USE_CONDENSED_INFO == 0 1.19 + 1.20 +const SkMemberInfo Sk3D_Point::fInfo[] = { 1.21 + SK_MEMBER_ALIAS(x, fPoint.fX, Float), 1.22 + SK_MEMBER_ALIAS(y, fPoint.fY, Float), 1.23 + SK_MEMBER_ALIAS(z, fPoint.fZ, Float) 1.24 +}; 1.25 + 1.26 +#endif 1.27 + 1.28 +DEFINE_NO_VIRTUALS_GET_MEMBER(Sk3D_Point); 1.29 + 1.30 +Sk3D_Point::Sk3D_Point() { 1.31 + fPoint.set(0, 0, 0); 1.32 +} 1.33 + 1.34 +#if SK_USE_CONDENSED_INFO == 0 1.35 + 1.36 +const SkMemberInfo Sk3D_Camera::fInfo[] = { 1.37 + SK_MEMBER_ALIAS(axis, fCamera.fAxis, 3D_Point), 1.38 + SK_MEMBER(hackHeight, Float), 1.39 + SK_MEMBER(hackWidth, Float), 1.40 + SK_MEMBER_ALIAS(location, fCamera.fLocation, 3D_Point), 1.41 + SK_MEMBER_ALIAS(observer, fCamera.fObserver, 3D_Point), 1.42 + SK_MEMBER(patch, 3D_Patch), 1.43 + SK_MEMBER_ALIAS(zenith, fCamera.fZenith, 3D_Point), 1.44 +}; 1.45 + 1.46 +#endif 1.47 + 1.48 +DEFINE_GET_MEMBER(Sk3D_Camera); 1.49 + 1.50 +Sk3D_Camera::Sk3D_Camera() : hackWidth(0), hackHeight(0), patch(NULL) { 1.51 +} 1.52 + 1.53 +Sk3D_Camera::~Sk3D_Camera() { 1.54 +} 1.55 + 1.56 +bool Sk3D_Camera::draw(SkAnimateMaker& maker) { 1.57 + fCamera.update(); 1.58 + SkMatrix matrix; 1.59 + fCamera.patchToMatrix(patch->fPatch, &matrix); 1.60 + matrix.preTranslate(hackWidth / 2, -hackHeight / 2); 1.61 + matrix.postTranslate(hackWidth / 2, hackHeight / 2); 1.62 + maker.fCanvas->concat(matrix); 1.63 + return false; 1.64 +} 1.65 + 1.66 + 1.67 +enum Sk3D_Patch_Functions { 1.68 + SK_FUNCTION(rotateDegrees) 1.69 +}; 1.70 + 1.71 +const SkFunctionParamType Sk3D_Patch::fFunctionParameters[] = { 1.72 + (SkFunctionParamType) SkType_Float, 1.73 + (SkFunctionParamType) SkType_Float, 1.74 + (SkFunctionParamType) SkType_Float, 1.75 + (SkFunctionParamType) 0 // terminator for parameter list (there may be multiple parameter lists) 1.76 +}; 1.77 + 1.78 +#if SK_USE_CONDENSED_INFO == 0 1.79 + 1.80 +const SkMemberInfo Sk3D_Patch::fInfo[] = { 1.81 + SK_MEMBER_ALIAS(origin, fPatch.fOrigin, 3D_Point), 1.82 + SK_MEMBER_FUNCTION(rotateDegrees, Float), 1.83 + SK_MEMBER_ALIAS(u, fPatch.fU, 3D_Point), 1.84 + SK_MEMBER_ALIAS(v, fPatch.fV, 3D_Point) 1.85 +}; 1.86 + 1.87 +#endif 1.88 + 1.89 +DEFINE_GET_MEMBER(Sk3D_Patch); 1.90 + 1.91 +void Sk3D_Patch::executeFunction(SkDisplayable* target, int index, 1.92 + SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type, 1.93 + SkScriptValue* ) { 1.94 + SkASSERT(target == this); 1.95 + switch (index) { 1.96 + case SK_FUNCTION(rotateDegrees): 1.97 + SkASSERT(parameters.count() == 3); 1.98 + SkASSERT(type == SkType_Float); 1.99 + fPatch.rotateDegrees(parameters[0].fOperand.fScalar, 1.100 + parameters[1].fOperand.fScalar, parameters[2].fOperand.fScalar); 1.101 + break; 1.102 + default: 1.103 + SkASSERT(0); 1.104 + } 1.105 +} 1.106 + 1.107 +const SkFunctionParamType* Sk3D_Patch::getFunctionsParameters() { 1.108 + return fFunctionParameters; 1.109 +}