1
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#ifndef SkOperand2_DEFINED
9#define SkOperand2_DEFINED
10
11#include "SkScalar.h"
12
13class SkOpArray;
14class SkString;
15
16union SkOperand2 {
17    enum OpType {
18        kNoType,
19        kS32 = 1,
20        kScalar = 2,
21        kString = 4,
22        kArray = 8,
23        kObject = 16
24    };
25    SkOpArray* fArray;
26    void* fObject;
27    size_t fReference;
28    int32_t fS32;
29    SkScalar fScalar;
30    SkString* fString;
31};
32
33struct SkScriptValue2 {
34    enum IsConstant {
35        kConstant,
36        kVariable
37    };
38    enum IsWritten {
39        kUnwritten,
40        kWritten
41    };
42    SkOperand2 fOperand;
43    SkOperand2::OpType fType : 8;
44    IsConstant fIsConstant : 8;
45    IsWritten fIsWritten : 8;
46    SkOpArray* getArray() { SkASSERT(fType == SkOperand2::kArray); return fOperand.fArray; }
47    void* getObject() { SkASSERT(fType == SkOperand2::kObject); return fOperand.fObject; }
48    int32_t getS32() { SkASSERT(fType == SkOperand2::kS32); return fOperand.fS32; }
49    SkScalar getScalar() { SkASSERT(fType == SkOperand2::kScalar); return fOperand.fScalar; }
50    SkString* getString() { SkASSERT(fType == SkOperand2::kString); return fOperand.fString; }
51        bool isConstant() const { return fIsConstant == kConstant; }
52};
53
54#endif // SkOperand2_DEFINED
55