-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Android SR Do not send duplicate screens #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
55b00a7
no message
abelonogov-ld 8ddba24
fix size bug
abelonogov-ld 008a414
Recycle bitmap early
abelonogov-ld 4d5536b
Fix feedback
abelonogov-ld ce45b42
address feedback
abelonogov-ld 50aee55
Volatile
abelonogov-ld 04c252e
Unit tests
abelonogov-ld d61361c
Merge branch 'main' into andrey/do-not-send-duplicate-windows
abelonogov-ld 9797c02
Fix style of unit test
abelonogov-ld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
100 changes: 100 additions & 0 deletions
100
...droid/lib/src/main/kotlin/com/launchdarkly/observability/replay/capture/TiledSignature.kt
This file contains hidden or 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,100 @@ | ||
| package com.launchdarkly.observability.replay.capture | ||
|
|
||
| import android.graphics.Bitmap | ||
|
|
||
| data class TiledSignature( | ||
| val tileHashes: LongArray | ||
| ) { | ||
| override fun equals(other: Any?): Boolean { | ||
| if (this === other) return true | ||
| if (javaClass != other?.javaClass) return false | ||
|
|
||
| other as TiledSignature | ||
|
|
||
| if (!tileHashes.contentEquals(other.tileHashes)) { | ||
| return false | ||
| } | ||
|
|
||
| return true | ||
| } | ||
abelonogov-ld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| override fun hashCode(): Int { | ||
| return tileHashes.contentHashCode() | ||
| } | ||
| } | ||
|
|
||
| class TiledSignatureManager { | ||
abelonogov-ld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private var pixelBuffer: IntArray = IntArray(0) | ||
abelonogov-ld marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| fun compute( | ||
| bitmap: Bitmap, | ||
| tileSize: Int | ||
| ): TiledSignature? { | ||
| if (tileSize <= 0) return null | ||
| val width = bitmap.width | ||
| val height = bitmap.height | ||
| if (width <= 0 || height <= 0) { | ||
| return null | ||
| } | ||
|
|
||
| val pixelsNeeded = width * height | ||
| if (pixelBuffer.size < pixelsNeeded) { | ||
| pixelBuffer = IntArray(pixelsNeeded) | ||
| } | ||
| val pixels = pixelBuffer | ||
| bitmap.getPixels(pixels, 0, width, 0, 0, width, height) | ||
|
|
||
| val tilesX = (width + tileSize - 1) / tileSize | ||
| val tilesY = (height + tileSize - 1) / tileSize | ||
| val tileCount = tilesX * tilesY | ||
| val tileHashes = LongArray(tileCount) | ||
|
|
||
| var tileIndex = 0 | ||
| for(ty in 0 until tilesY) { | ||
| val startY = ty * tileSize | ||
| val endY = minOf(startY + tileSize, height) | ||
|
|
||
| for(tx in 0 until tilesX) { | ||
| val startX = tx * tileSize | ||
| val endX = minOf(startX + tileSize, width) | ||
| tileHashes[tileIndex] = hashTile( | ||
| pixels = pixels, | ||
| width = width, | ||
| startX = startX, | ||
| startY = startY, | ||
| endX = endX, | ||
| endY = endY | ||
| ) | ||
| tileIndex++ | ||
| } | ||
| } | ||
|
|
||
| //TODO: optimize memory allocations here to have 2 arrays instead of 1 | ||
| return TiledSignature(tileHashes) | ||
| } | ||
|
|
||
| private fun hashTile( | ||
| pixels: IntArray, | ||
| width: Int, | ||
| startX: Int, | ||
| startY: Int, | ||
| endX: Int, | ||
| endY: Int | ||
| ): Long { | ||
| var hash: Long = 5163949831757626579 | ||
abelonogov-ld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| val prime: Long = 1238197591667094937 // from https://bigprimes.org | ||
abelonogov-ld marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for(y in startY until endY) { | ||
| val rowOffset = y * width | ||
| for(x in startX until endX) { | ||
| val argb = pixels[rowOffset + x] | ||
| hash = (hash xor (argb and 0xFF).toLong()) * prime | ||
| hash = (hash xor ((argb ushr 8) and 0xFF).toLong()) * prime | ||
| hash = (hash xor ((argb ushr 16) and 0xFF).toLong()) * prime | ||
| hash = (hash xor ((argb ushr 24) and 0xFF).toLong()) * prime | ||
| } | ||
| } | ||
| return hash | ||
| } | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.