NewEnv creates a new execution environment for the given capture.
(ctx context.Context, capture *capture.GraphicsCapture)
| 130 | |
| 131 | // NewEnv creates a new execution environment for the given capture. |
| 132 | func (e *Executor) NewEnv(ctx context.Context, capture *capture.GraphicsCapture) *Env { |
| 133 | var id envID |
| 134 | var env *Env |
| 135 | |
| 136 | func() { |
| 137 | envMutex.Lock() |
| 138 | defer envMutex.Unlock() |
| 139 | |
| 140 | id = nextEnvID |
| 141 | nextEnvID++ |
| 142 | |
| 143 | env = &Env{ |
| 144 | Executor: e, |
| 145 | id: envID(id), |
| 146 | } |
| 147 | envs[id] = env |
| 148 | }() |
| 149 | |
| 150 | // Create the context and initialize the globals. |
| 151 | env.Arena = arena.New() |
| 152 | env.goCtx = ctx |
| 153 | env.cCtx = C.create_context((*C.TCreateContext)(e.createContext), (*C.arena)(env.Arena.Pointer)) |
| 154 | env.cCtx.id = (C.uint32_t)(id) |
| 155 | env.goCtx = nil |
| 156 | |
| 157 | // Allocate buffers for all the observed memory ranges. |
| 158 | for _, r := range capture.Observed { |
| 159 | ptr := env.Arena.Allocate((int)(r.Count), 16) |
| 160 | rng := memory.Range{Base: r.First, Size: r.Count} |
| 161 | env.buffers.add(rng, ptr) |
| 162 | } |
| 163 | |
| 164 | return env |
| 165 | } |
| 166 | |
| 167 | // Execute executes the command cmd. |
| 168 | func (e *Env) Execute(ctx context.Context, cmd api.Cmd, id api.CmdID) error { |