Files
gio/internal/opconst/ops.go
T
Elias Naur 97299dc2f9 op/paint: make every ImageOp unique
The gioui.org/commit/74407a50d598bfd27e8f8e48b6832cc5df04de77
added a NewImageOp constructor that always copies the supplied
image. It does that for two reasons:

First, the image.Image reference is used in the image=>texture
map of cached textures. Without a copy, we wouldn't detect a
modified image even if a new ImageOp was created.

Second, we don't want the program to touch the image while the GPU
is uploading it.

The second reason was removed in a previous change that blocks
FrameEvent.Frame until we're done with the operations, including
uploading images to the GPU.

The first reason is easily fixed by using a unique per ImageOp,
as pointed out by Alessandro Arzilli.

This change switches to using the unique key. Alessandro's patch
avoids the copy when possible.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-07 18:27:06 +01:00

85 lines
1.5 KiB
Go

// SPDX-License-Identifier: Unlicense OR MIT
package opconst
type OpType byte
// Start at a high number for easier debugging.
const firstOpIndex = 200
const (
TypeMacroDef OpType = iota + firstOpIndex
TypeMacro
TypeTransform
TypeLayer
TypeInvalidate
TypeImage
TypePaint
TypeColor
TypeArea
TypePointerInput
TypePass
TypeKeyInput
TypeHideInput
TypePush
TypePop
TypeAux
TypeClip
TypeProfile
)
const (
TypeMacroDefLen = 1 + 4 + 4
TypeMacroLen = 1 + 4 + 4 + 4
TypeTransformLen = 1 + 4*2
TypeLayerLen = 1
TypeRedrawLen = 1 + 8
TypeImageLen = 1
TypePaintLen = 1 + 4*4
TypeColorLen = 1 + 4
TypeAreaLen = 1 + 1 + 4*4
TypePointerInputLen = 1 + 1
TypePassLen = 1 + 1
TypeKeyInputLen = 1 + 1
TypeHideInputLen = 1
TypePushLen = 1
TypePopLen = 1
TypeAuxLen = 1
TypeClipLen = 1 + 4*4
TypeProfileLen = 1
)
func (t OpType) Size() int {
return [...]int{
TypeMacroDefLen,
TypeMacroLen,
TypeTransformLen,
TypeLayerLen,
TypeRedrawLen,
TypeImageLen,
TypePaintLen,
TypeColorLen,
TypeAreaLen,
TypePointerInputLen,
TypePassLen,
TypeKeyInputLen,
TypeHideInputLen,
TypePushLen,
TypePopLen,
TypeAuxLen,
TypeClipLen,
TypeProfileLen,
}[t-firstOpIndex]
}
func (t OpType) NumRefs() int {
switch t {
case TypeMacro, TypeKeyInput, TypePointerInput, TypeProfile:
return 1
case TypeImage:
return 2
default:
return 0
}
}