180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2006 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkDisplayRandom.h" 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkInterpolator.h" 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruenum SkDisplayRandom_Properties { 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_PROPERTY(random), 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_PROPERTY(seed) 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#if SK_USE_CONDENSED_INFO == 0 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruconst SkMemberInfo SkDisplayRandom::fInfo[] = { 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER(blend, Float), 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER(max, Float), 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER(min, Float), 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_DYNAMIC_PROPERTY(random, Float), 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SK_MEMBER_PROPERTY(seed, Int) 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruDEFINE_GET_MEMBER(SkDisplayRandom); 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste QueruSkDisplayRandom::SkDisplayRandom() : blend(0), min(0), max(SK_Scalar1) { 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifdef SK_DUMP_ENABLED 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruvoid SkDisplayRandom::dump(SkAnimateMaker* maker) { 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru dumpBase(maker); 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("min=\"%g\" ", SkScalarToFloat(min)); 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("max=\"%g\" ", SkScalarToFloat(max)); 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("blend=\"%g\" ", SkScalarToFloat(blend)); 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkDebugf("/>\n"); 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkDisplayRandom::getProperty(int index, SkScriptValue* value) const { 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru switch(index) { 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru case SK_PROPERTY(random): { 4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar random = fRandom.nextUScalar1(); 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkScalar relativeT = SkUnitCubicInterp(random, SK_Scalar1 - blend, 0, 0, SK_Scalar1 - blend); 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru value->fOperand.fScalar = min + SkScalarMul(max - min, relativeT); 5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru value->fType = SkType_Float; 5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru default: 5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(0); 5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkDisplayRandom::setProperty(int index, SkScriptValue& value) { 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(index == SK_PROPERTY(seed)); 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkASSERT(value.fType == SkType_Int); 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru fRandom.setSeed(value.fOperand.fS32); 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return true; 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 66