-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize: performance of desktop viewer on Windows
- Loading branch information
XZB-1248
committed
Sep 20, 2022
1 parent
1a365ab
commit bc63722
Showing
8 changed files
with
177 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package desktop | ||
|
||
import ( | ||
"github.com/kbinani/screenshot" | ||
"image" | ||
) | ||
|
||
type screen struct { | ||
displayIndex int | ||
} | ||
|
||
func (s *screen) init(displayIndex int) { | ||
s.displayIndex = displayIndex | ||
} | ||
|
||
func (s *screen) capture(img *image.RGBA, _ image.Rectangle) error { | ||
var err error | ||
img, err = screenshot.CaptureDisplay(displayIndex) | ||
return err | ||
} | ||
|
||
func (s *screen) release() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package desktop | ||
|
||
import ( | ||
"github.com/kirides/screencapture/d3d" | ||
"github.com/kirides/screencapture/screenshot" | ||
"github.com/kirides/screencapture/win" | ||
"image" | ||
) | ||
|
||
type screen struct { | ||
dxgi bool | ||
ddup *d3d.OutputDuplicator | ||
device *d3d.ID3D11Device | ||
deviceCtx *d3d.ID3D11DeviceContext | ||
displayIndex int | ||
} | ||
|
||
func (s *screen) init(displayIndex int) { | ||
var err error | ||
s.displayIndex = displayIndex | ||
s.dxgi = false | ||
return | ||
if win.IsValidDpiAwarenessContext(win.DpiAwarenessContextPerMonitorAwareV2) { | ||
_, err = win.SetThreadDpiAwarenessContext(win.DpiAwarenessContextPerMonitorAwareV2) | ||
s.dxgi = err == nil | ||
} | ||
if s.dxgi { | ||
s.device, s.deviceCtx, err = d3d.NewD3D11Device() | ||
s.ddup, err = d3d.NewIDXGIOutputDuplication(s.device, s.deviceCtx, uint(displayIndex)) | ||
if err != nil { | ||
s.dxgi = false | ||
s.device.Release() | ||
s.deviceCtx.Release() | ||
} | ||
} | ||
} | ||
|
||
func (s *screen) capture(img *image.RGBA, bounds image.Rectangle) error { | ||
var err error | ||
if s.dxgi { | ||
err = s.ddup.GetImage(img, 100) | ||
if err != nil { | ||
if err == d3d.ErrNoImageYet { | ||
return ErrNoImage | ||
} | ||
return err | ||
} | ||
return nil | ||
} | ||
return screenshot.CaptureImg(img, 0, 0, bounds.Dx(), bounds.Dy()) | ||
} | ||
|
||
func (s *screen) release() { | ||
if s.ddup != nil { | ||
s.ddup.Release() | ||
} | ||
if s.device != nil { | ||
s.device.Release() | ||
} | ||
if s.deviceCtx != nil { | ||
s.deviceCtx.Release() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.