Skip to content

Commit

Permalink
Add overdraw options to gapit screenshot to display results
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-purcell committed Jun 19, 2018
1 parent 7a00a08 commit d8881f4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
16 changes: 10 additions & 6 deletions cmd/gapit/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,16 @@ type (
ADB string `help:"Path to the adb executable; leave empty to search the environment"`
}
ScreenshotFlags struct {
Gapis GapisFlags
Gapir GapirFlags
At flags.U64Slice `help:"command/subcommand index for the screenshot"`
Frame int64 `help:"frame index for the screenshot. Empty for last"`
Out string `help:"output image file (default 'screenshot.png')"`
NoOpt bool `help:"disables optimization of the replay stream"`
Gapis GapisFlags
Gapir GapirFlags
At flags.U64Slice `help:"command/subcommand index for the screenshot"`
Frame int64 `help:"frame index for the screenshot. Empty for last"`
Out string `help:"output image file (default 'screenshot.png')"`
NoOpt bool `help:"disables optimization of the replay stream"`
Overdraw bool `help:"renders the overdraw instead of the colour framebuffer"`
Max struct {
Overdraw int `help:"the amount of overdraw to map to white in the output"`
}
CommandFilterFlags
}
UnpackFlags struct {
Expand Down
38 changes: 34 additions & 4 deletions cmd/gapit/screenshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (verb *screenshotVerb) Run(ctx context.Context, flags flag.FlagSet) error {
}
}

if frame, err := getSingleFrame(ctx, command, device, client, verb.NoOpt); err == nil {
if frame, err := verb.getSingleFrame(ctx, command, device, client); err == nil {
return verb.writeSingleFrame(flipImg(frame), verb.Out)
} else {
return err
Expand All @@ -107,13 +107,16 @@ func (verb *screenshotVerb) writeSingleFrame(frame image.Image, fn string) error
return png.Encode(out, frame)
}

func getSingleFrame(ctx context.Context, cmd *path.Command, device *path.Device, client service.Service, noOpt bool) (*image.NRGBA, error) {
func (verb *screenshotVerb) getSingleFrame(ctx context.Context, cmd *path.Command, device *path.Device, client service.Service) (*image.NRGBA, error) {
ctx = log.V{"cmd": cmd.Indices}.Bind(ctx)
settings := &service.RenderSettings{MaxWidth: uint32(0xFFFFFFFF), MaxHeight: uint32(0xFFFFFFFF)}
if verb.Overdraw {
settings.DrawMode = service.DrawMode_OVERDRAW
}
iip, err := client.GetFramebufferAttachment(ctx,
&service.ReplaySettings{
Device: device,
DisableReplayOptimization: noOpt,
DisableReplayOptimization: verb.NoOpt,
},
cmd, api.FramebufferAttachment_Color0, settings, nil)
if err != nil {
Expand All @@ -138,7 +141,12 @@ func getSingleFrame(ctx context.Context, cmd *path.Command, device *path.Device,
if ii.Width == 0 || ii.Height == 0 {
return nil, log.Err(ctx, nil, "Framebuffer has zero dimensions")
}
data, err = img.Convert(data, w, h, 1, ii.Format, img.RGBA_U8_NORM)
format := ii.Format
if verb.Overdraw {
format = img.Gray_U8_NORM
rescaleBytes(ctx, data, verb.Max.Overdraw)
}
data, err = img.Convert(data, w, h, 1, format, img.RGBA_U8_NORM)
if err != nil {
return nil, log.Err(ctx, err, "Failed to convert frame to RGBA")
}
Expand Down Expand Up @@ -174,3 +182,25 @@ func (verb *screenshotVerb) frameCommand(ctx context.Context, capture *path.Capt
fmt.Printf("Frame Command: %v\n", eofEvents[verb.Frame].Command.GetIndices())
return eofEvents[verb.Frame].Command, nil
}

func rescaleBytes(ctx context.Context, data []byte, max int) {
if max <= 0 {
for _, b := range data {
if int(b) > max {
max = int(b)
}
}
}
log.D(ctx, "Max overdraw: %v", max)
if max < 1 {
max = 1
}

for i, b := range data {
if int(b) >= max {
data[i] = 255
} else {
data[i] = byte(int(data[i]) * 255 / max)
}
}
}
1 change: 1 addition & 0 deletions core/image/uncompressed.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
RG_U16_NORM = newUncompressed(fmts.RG_U16_NORM)
R_S16_NORM = newUncompressed(fmts.R_S16_NORM)
RG_S16_NORM = newUncompressed(fmts.RG_S16_NORM)
Gray_U8_NORM = newUncompressed(fmts.Gray_U8_NORM)
D_U16_NORM = newUncompressed(fmts.D_U16_NORM)
)

Expand Down

0 comments on commit d8881f4

Please sign in to comment.