From f8a3aeda6aa0656efb6bab7978ef381131348519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BA=A2=E5=B2=A9?= Date: Sun, 18 Jun 2023 16:50:45 +0800 Subject: [PATCH] U: dirtyRects, Optimize the way event variables are valued --- cef/events-def.go | 4 ++-- cef/events.go | 22 ++-------------------- cef/types-render-handler.go | 26 ++++---------------------- cef/types.go | 28 ++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 44 deletions(-) diff --git a/cef/events-def.go b/cef/events-def.go index 1fc59804..12030997 100644 --- a/cef/events-def.go +++ b/cef/events-def.go @@ -23,7 +23,7 @@ import ( type chromiumEventOnResult func(sender lcl.IObject, aResultOK bool) // 通用Result bool type chromiumEventOnResultFloat func(sender lcl.IObject, result float64) // 通用Result float -type chromiumEventOnAcceleratedPaint func(sender lcl.IObject, browser *ICefBrowser, kind consts.TCefPaintElementType, dirtyRectsCount uint32, dirtyRects []*TCefRect, sharedHandle uintptr) +type chromiumEventOnAcceleratedPaint func(sender lcl.IObject, browser *ICefBrowser, kind consts.TCefPaintElementType, dirtyRects *TCefRectArray, sharedHandle uintptr) type chromiumEventOnAllConnectionsClosed func(sender lcl.IObject) type chromiumEventOnAudioStreamError func(sender lcl.IObject, browser *ICefBrowser, message string) type chromiumEventOnAudioStreamPacket func(sender lcl.IObject, browser *ICefBrowser, data *uintptr, frames int32, pts int64) @@ -81,7 +81,7 @@ type chromiumEventOnMediaAccessChange func(sender lcl.IObject, browser *ICefBrow type chromiumEventOnMediaRouteCreateFinished func(sender lcl.IObject, result consts.TCefMediaRouterCreateResult, error string, route *ICefMediaRoute) // TODO ICefMediaRoute type chromiumEventOnMediaSinkDeviceInfo func(sender lcl.IObject, ipAddress string, port int32, modelName string) type chromiumEventOnNavigationVisitorResultAvailable func(sender lcl.IObject, entry *ICefNavigationEntry, current bool, index, total int32) bool // TODO ICefNavigationEntry -type chromiumEventOnPaint func(sender lcl.IObject, browser *ICefBrowser, kind consts.TCefPaintElementType, dirtyRectsCount uint32, dirtyRects []*TCefRect, buffer uintptr, width, height int32) +type chromiumEventOnPaint func(sender lcl.IObject, browser *ICefBrowser, kind consts.TCefPaintElementType, dirtyRects *TCefRectArray, buffer uintptr, width, height int32) type chromiumEventOnPdfPrintFinished func(sender lcl.IObject, ok bool) type chromiumEventOnPopupShow func(sender lcl.IObject, browser *ICefBrowser, show bool) type chromiumEventOnPopupSize func(sender lcl.IObject, browser *ICefBrowser, rect *TCefRect) diff --git a/cef/events.go b/cef/events.go index 5832f22b..365b4c3e 100644 --- a/cef/events.go +++ b/cef/events.go @@ -49,17 +49,8 @@ func init() { kind := consts.TCefPaintElementType(getVal(2)) dirtyRectsCount := uint32(getVal(3)) dirtyRectsPtr := getVal(4) - var dirtyRects []*TCefRect - if dirtyRectsCount > 0 { - var rect TCefRect - var rectSize = unsafe.Sizeof(rect) - dirtyRects = make([]*TCefRect, dirtyRectsCount, dirtyRectsCount) - for i := 0; i < int(dirtyRectsCount); i++ { - dirtyRects[i] = (*TCefRect)(common.GetParamPtr(dirtyRectsPtr, i*int(rectSize))) - } - } sharedHandle := getVal(5) - fn.(chromiumEventOnAcceleratedPaint)(lcl.AsObject(getPtr(0)), browser, kind, dirtyRectsCount, dirtyRects, sharedHandle) + fn.(chromiumEventOnAcceleratedPaint)(lcl.AsObject(getPtr(0)), browser, kind, NewTCefRectArray(dirtyRectsPtr, dirtyRectsCount), sharedHandle) case chromiumEventOnAllConnectionsClosed: fn.(chromiumEventOnAllConnectionsClosed)(lcl.AsObject(getPtr(0))) case chromiumEventOnAudioStreamError: @@ -475,18 +466,9 @@ func init() { kind := consts.TCefPaintElementType(getVal(2)) dirtyRectsCount := uint32(getVal(3)) dirtyRectsPtr := getVal(4) - var dirtyRects []*TCefRect - if dirtyRectsCount > 0 { - var rect TCefRect - var rectSize = unsafe.Sizeof(rect) - dirtyRects = make([]*TCefRect, dirtyRectsCount, dirtyRectsCount) - for i := 0; i < int(dirtyRectsCount); i++ { - dirtyRects[i] = (*TCefRect)(common.GetParamPtr(dirtyRectsPtr, i*int(rectSize))) - } - } buffer := getVal(5) width, height := int32(getVal(6)), int32(getVal(7)) - fn.(chromiumEventOnPaint)(lcl.AsObject(getPtr(0)), browser, kind, dirtyRectsCount, dirtyRects, buffer, width, height) + fn.(chromiumEventOnPaint)(lcl.AsObject(getPtr(0)), browser, kind, NewTCefRectArray(dirtyRectsPtr, dirtyRectsCount), buffer, width, height) case chromiumEventOnPdfPrintFinished: fn.(chromiumEventOnPdfPrintFinished)(lcl.AsObject(getPtr(0)), api.GoBool(getVal(1))) case chromiumEventOnPopupShow: diff --git a/cef/types-render-handler.go b/cef/types-render-handler.go index 92c222ad..c3c26592 100644 --- a/cef/types-render-handler.go +++ b/cef/types-render-handler.go @@ -12,7 +12,6 @@ package cef import ( "github.com/energye/energy/v2/cef/internal/def" - "github.com/energye/energy/v2/common" "github.com/energye/energy/v2/common/imports" "github.com/energye/energy/v2/consts" "github.com/energye/golcl/lcl" @@ -172,8 +171,8 @@ type renderHandlerGetScreenPoint func(browser *ICefBrowser, viewX, viewY int32) type renderHandlerGetScreenInfo func(browser *ICefBrowser) (screenInfo *TCefScreenInfo, result bool) type renderHandlerOnPopupShow func(browser *ICefBrowser, show bool) type renderHandlerOnPopupSize func(browser *ICefBrowser, rect *TCefRect) -type renderHandlerOnPaint func(browser *ICefBrowser, kind consts.TCefPaintElementType, dirtyRectsCount uint32, dirtyRects []*TCefRect, buffer uintptr, width, height int32) -type renderHandlerOnAcceleratedPaint func(browser *ICefBrowser, kind consts.TCefPaintElementType, dirtyRectsCount uint32, dirtyRects []*TCefRect, sharedHandle uintptr) +type renderHandlerOnPaint func(browser *ICefBrowser, kind consts.TCefPaintElementType, dirtyRects *TCefRectArray, buffer uintptr, width, height int32) +type renderHandlerOnAcceleratedPaint func(browser *ICefBrowser, kind consts.TCefPaintElementType, dirtyRects *TCefRectArray, sharedHandle uintptr) type renderHandlerGetTouchHandleSize func(browser *ICefBrowser, orientation consts.TCefHorizontalAlignment) *TCefSize type renderHandlerOnTouchHandleStateChanged func(browser *ICefBrowser, state *TCefTouchHandleState) type renderHandlerOnStartDragging func(browser *ICefBrowser, dragData *ICefDragData, allowedOps consts.TCefDragOperations, x, y int32) bool @@ -236,33 +235,16 @@ func init() { kind := consts.TCefPaintElementType(getVal(1)) dirtyRectsCount := uint32(getVal(2)) dirtyRectsPtr := getVal(3) - var dirtyRects []*TCefRect - if dirtyRectsCount > 0 { - var rectSize = unsafe.Sizeof(TCefRect{}) - dirtyRects = make([]*TCefRect, dirtyRectsCount, dirtyRectsCount) - for i := 0; i < int(dirtyRectsCount); i++ { - dirtyRects[i] = (*TCefRect)(common.GetParamPtr(dirtyRectsPtr, i*int(rectSize))) - } - } buffer := getVal(4) width, height := int32(getVal(5)), int32(getVal(6)) - fn.(renderHandlerOnPaint)(browser, kind, dirtyRectsCount, dirtyRects, buffer, width, height) + fn.(renderHandlerOnPaint)(browser, kind, NewTCefRectArray(dirtyRectsPtr, dirtyRectsCount), buffer, width, height) case renderHandlerOnAcceleratedPaint: browser := &ICefBrowser{instance: getPtr(0)} kind := consts.TCefPaintElementType(getVal(1)) dirtyRectsCount := uint32(getVal(2)) dirtyRectsPtr := getVal(3) - var dirtyRects []*TCefRect - if dirtyRectsCount > 0 { - var rect TCefRect - var rectSize = unsafe.Sizeof(rect) - dirtyRects = make([]*TCefRect, dirtyRectsCount, dirtyRectsCount) - for i := 0; i < int(dirtyRectsCount); i++ { - dirtyRects[i] = (*TCefRect)(common.GetParamPtr(dirtyRectsPtr, i*int(rectSize))) - } - } sharedHandle := getVal(4) - fn.(renderHandlerOnAcceleratedPaint)(browser, kind, dirtyRectsCount, dirtyRects, sharedHandle) + fn.(renderHandlerOnAcceleratedPaint)(browser, kind, NewTCefRectArray(dirtyRectsPtr, dirtyRectsCount), sharedHandle) case renderHandlerGetTouchHandleSize: browser := &ICefBrowser{instance: getPtr(0)} orientation := consts.TCefHorizontalAlignment(getVal(1)) diff --git a/cef/types.go b/cef/types.go index 6e702fe9..34433bd5 100644 --- a/cef/types.go +++ b/cef/types.go @@ -15,6 +15,7 @@ package cef import ( + "github.com/energye/energy/v2/common" . "github.com/energye/energy/v2/consts" . "github.com/energye/energy/v2/types" "github.com/energye/golcl/lcl" @@ -171,6 +172,33 @@ type TCefRect struct { Height int32 } +type TCefRectArray struct { + ptr uintptr + sizeOf uintptr + count uint32 +} + +// NewTCefRectArray +// TCefRect 动态数组结构, 通过指针引用取值 +func NewTCefRectArray(ptr uintptr, count uint32) *TCefRectArray { + return &TCefRectArray{ + ptr: ptr, + sizeOf: unsafe.Sizeof(TCefRect{}), + count: count, + } +} + +func (m *TCefRectArray) Count() uint32 { + return m.count +} + +func (m *TCefRectArray) Get(index int) *TCefRect { + if m.count == 0 || index < 0 || index >= int(m.count) { + return nil + } + return (*TCefRect)(common.GetParamPtr(m.ptr, index*int(m.sizeOf))) +} + // TCefSize // /include/internal/cef_types_geometry.h (cef_size_t) type TCefSize struct {