github.com/cybriq/giocore@v0.0.7-0.20210703034601-cfb9cb5f3900/internal/opconst/ops.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  package opconst
     4  
     5  type OpType byte
     6  
     7  // Start at a high number for easier debugging.
     8  const firstOpIndex = 200
     9  
    10  const (
    11  	TypeMacro OpType = iota + firstOpIndex
    12  	TypeCall
    13  	TypeDefer
    14  	TypeTransform
    15  	TypeInvalidate
    16  	TypeImage
    17  	TypePaint
    18  	TypeColor
    19  	TypeLinearGradient
    20  	TypeArea
    21  	TypePointerInput
    22  	TypePass
    23  	TypeClipboardRead
    24  	TypeClipboardWrite
    25  	TypeKeyInput
    26  	TypeKeyFocus
    27  	TypeKeySoftKeyboard
    28  	TypeSave
    29  	TypeLoad
    30  	TypeAux
    31  	TypeClip
    32  	TypeProfile
    33  	TypeCursor
    34  	TypePath
    35  	TypeStroke
    36  )
    37  
    38  const (
    39  	TypeMacroLen           = 1 + 4 + 4
    40  	TypeCallLen            = 1 + 4 + 4
    41  	TypeDeferLen           = 1
    42  	TypeTransformLen       = 1 + 4*6
    43  	TypeRedrawLen          = 1 + 8
    44  	TypeImageLen           = 1
    45  	TypePaintLen           = 1
    46  	TypeColorLen           = 1 + 4
    47  	TypeLinearGradientLen  = 1 + 8*2 + 4*2
    48  	TypeAreaLen            = 1 + 1 + 4*4
    49  	TypePointerInputLen    = 1 + 1 + 1 + 2*4 + 2*4
    50  	TypePassLen            = 1 + 1
    51  	TypeClipboardReadLen   = 1
    52  	TypeClipboardWriteLen  = 1
    53  	TypeKeyInputLen        = 1 + 1
    54  	TypeKeyFocusLen        = 1 + 1
    55  	TypeKeySoftKeyboardLen = 1 + 1
    56  	TypeSaveLen            = 1 + 4
    57  	TypeLoadLen            = 1 + 1 + 4
    58  	TypeAuxLen             = 1
    59  	TypeClipLen            = 1 + 4*4 + 1
    60  	TypeProfileLen         = 1
    61  	TypeCursorLen          = 1 + 1
    62  	TypePathLen            = 1
    63  	TypeStrokeLen          = 1 + 4
    64  )
    65  
    66  // StateMask is a bitmask of state types a load operation
    67  // should restore.
    68  type StateMask uint8
    69  
    70  const (
    71  	TransformState StateMask = 1 << iota
    72  
    73  	AllState = ^StateMask(0)
    74  )
    75  
    76  // InitialStateID is the ID for saving and loading
    77  // the initial operation state.
    78  const InitialStateID = 0
    79  
    80  func (t OpType) Size() int {
    81  	return [...]int{
    82  		TypeMacroLen,
    83  		TypeCallLen,
    84  		TypeDeferLen,
    85  		TypeTransformLen,
    86  		TypeRedrawLen,
    87  		TypeImageLen,
    88  		TypePaintLen,
    89  		TypeColorLen,
    90  		TypeLinearGradientLen,
    91  		TypeAreaLen,
    92  		TypePointerInputLen,
    93  		TypePassLen,
    94  		TypeClipboardReadLen,
    95  		TypeClipboardWriteLen,
    96  		TypeKeyInputLen,
    97  		TypeKeyFocusLen,
    98  		TypeKeySoftKeyboardLen,
    99  		TypeSaveLen,
   100  		TypeLoadLen,
   101  		TypeAuxLen,
   102  		TypeClipLen,
   103  		TypeProfileLen,
   104  		TypeCursorLen,
   105  		TypePathLen,
   106  		TypeStrokeLen,
   107  	}[t-firstOpIndex]
   108  }
   109  
   110  func (t OpType) NumRefs() int {
   111  	switch t {
   112  	case TypeKeyInput, TypeKeyFocus, TypePointerInput, TypeProfile, TypeCall, TypeClipboardRead, TypeClipboardWrite, TypeCursor:
   113  		return 1
   114  	case TypeImage:
   115  		return 2
   116  	default:
   117  		return 0
   118  	}
   119  }