/
framebuffer_changes.go
101 lines (89 loc) · 3.59 KB
/
framebuffer_changes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (C) 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package resolve
import (
"context"
"github.com/google/gapid/core/fault"
"github.com/google/gapid/core/log"
"github.com/google/gapid/gapis/api"
"github.com/google/gapid/gapis/api/sync"
"github.com/google/gapid/gapis/capture"
"github.com/google/gapid/gapis/database"
"github.com/google/gapid/gapis/messages"
"github.com/google/gapid/gapis/service"
"github.com/google/gapid/gapis/service/path"
)
// FramebufferChanges returns the list of attachment changes over the span of
// the entire capture.
func FramebufferChanges(ctx context.Context, c *path.Capture, r *path.ResolveConfig) (*AttachmentFramebufferChanges, error) {
obj, err := database.Build(ctx, &FramebufferChangesResolvable{Capture: c, Config: r})
if err != nil {
return nil, err
}
return obj.(*AttachmentFramebufferChanges), nil
}
// AttachmentFramebufferChanges describes the list of attachment changes over
// the span of the entire capture.
type AttachmentFramebufferChanges struct {
attachments []framebufferAttachmentChanges
}
// Get returns the framebuffer dimensions and format after a given command in
// the given capture, command and attachment.
func (c AttachmentFramebufferChanges) Get(ctx context.Context, after *path.Command, att api.FramebufferAttachment) (FramebufferAttachmentInfo, error) {
info, err := c.attachments[att].after(ctx, api.SubCmdIdx(after.Indices))
if err != nil {
return FramebufferAttachmentInfo{}, err
}
if info.Err != nil {
log.W(ctx, "Framebuffer error after %v: %v", after, info.Err)
return FramebufferAttachmentInfo{}, &service.ErrDataUnavailable{Reason: messages.ErrFramebufferUnavailable()}
}
return info, nil
}
const errNoAPI = fault.Const("Command has no API")
// Resolve implements the database.Resolver interface.
func (r *FramebufferChangesResolvable) Resolve(ctx context.Context) (interface{}, error) {
ctx = SetupContext(ctx, r.Capture, r.Config)
c, err := capture.ResolveGraphics(ctx)
if err != nil {
return nil, err
}
out := &AttachmentFramebufferChanges{
// TODO: Remove hardcoded upper limit
attachments: make([]framebufferAttachmentChanges, api.FramebufferAttachment_Color3+1),
}
postCmdAndSubCmd := func(s *api.GlobalState, subcommandIndex api.SubCmdIdx, cmd api.Cmd) {
api := cmd.API()
idx := append([]uint64(nil), subcommandIndex...)
for _, att := range allFramebufferAttachments {
info := FramebufferAttachmentInfo{After: idx}
if api != nil {
if inf, err := api.GetFramebufferAttachmentInfo(ctx, idx, s, cmd.Thread(), att); err == nil && inf.Format != nil {
info.Width, info.Height, info.Index, info.Format, info.CanResize = inf.Width, inf.Height, inf.Index, inf.Format, inf.CanResize
} else {
info.Err = err
}
} else {
info.Err = errNoAPI
}
if last := out.attachments[att].last(); !last.equal(info) {
attachment := out.attachments[att]
attachment.changes = append(attachment.changes, info)
out.attachments[att] = attachment
}
}
}
sync.MutateWithSubcommands(ctx, r.Capture, c.Commands, postCmdAndSubCmd, nil, postCmdAndSubCmd)
return out, nil
}