-
-
Notifications
You must be signed in to change notification settings - Fork 10
Add Android Goldfish snapshot style reload test #676
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
93 changes: 93 additions & 0 deletions
93
...lin/src/androidDeviceTest/kotlin/org/maplibre/nativeffi/render/GoldfishStyleReloadTest.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,93 @@ | ||
| package org.maplibre.nativeffi.render | ||
|
|
||
| import kotlin.test.Test | ||
| import kotlin.test.assertContentEquals | ||
| import kotlin.test.assertTrue | ||
| import org.maplibre.nativeffi.map.MapHandle | ||
| import org.maplibre.nativeffi.map.MapMode | ||
| import org.maplibre.nativeffi.runtime.RuntimeEventType | ||
| import org.maplibre.nativeffi.runtime.RuntimeHandle | ||
|
|
||
| class GoldfishStyleReloadTest { | ||
| @Test | ||
| fun repeatedSnapshotStyleReloadRendersComposedLayer() { | ||
| withOwnedTextureSession( | ||
| width = SNAPSHOT_SIZE, | ||
| height = SNAPSHOT_SIZE, | ||
| mapWidth = SNAPSHOT_SIZE, | ||
| mapHeight = SNAPSHOT_SIZE, | ||
| mapMode = MapMode.STATIC, | ||
| ) { runtime, map, owned -> | ||
| loadBaseStyle(runtime, map, BASE_STYLE) | ||
| addComposition(map) | ||
| assertContentEquals(GREEN, captureCenterPixel(runtime, map, owned.session)) | ||
|
|
||
| loadBaseStyle(runtime, map, ALTERNATE_STYLE) | ||
| loadBaseStyle(runtime, map, BASE_STYLE.copyOf()) | ||
| addComposition(map) | ||
|
|
||
| assertContentEquals(GREEN, captureCenterPixel(runtime, map, owned.session)) | ||
| } | ||
| } | ||
|
|
||
| private fun loadBaseStyle(runtime: RuntimeHandle, map: MapHandle, style: ByteArray) { | ||
| map.setStyleJson(style) | ||
| assertTrue(waitForMapEvent(runtime, map, RuntimeEventType.MAP_STYLE_LOADED)) | ||
| } | ||
|
|
||
| private fun addComposition(map: MapHandle) { | ||
| map.addStyleSourceJson(COMPOSED_SOURCE_ID, COMPOSED_SOURCE) | ||
| map.addStyleLayerJson(COMPOSED_LAYER, "") | ||
| } | ||
|
|
||
| private fun captureCenterPixel( | ||
| runtime: RuntimeHandle, | ||
| map: MapHandle, | ||
| session: RenderSessionHandle, | ||
| ): ByteArray { | ||
| map.requestStillImage() | ||
| var captured: ByteArray? = null | ||
| repeat(10_000) { | ||
| runtime.pump(0) | ||
| var finished = false | ||
| for (event in runtime.drainEvents().events.filter { it.mapSource == map }) { | ||
| when (event.type) { | ||
| RuntimeEventType.MAP_RENDER_UPDATE_AVAILABLE -> | ||
| if (session.renderUpdate().result == RenderResult.RENDERED) { | ||
| val info = session.textureImageInfo() | ||
| NativeBuffer.allocate(info.byteLength).use { buffer -> | ||
| session.readPremultipliedRgba8(buffer) | ||
| val centerOffset = SNAPSHOT_SIZE / 2 * info.stride + SNAPSHOT_SIZE / 2 * 4 | ||
| captured = buffer.toByteArray().copyOfRange(centerOffset, centerOffset + 4) | ||
| } | ||
| } | ||
| RuntimeEventType.MAP_STILL_IMAGE_FINISHED -> finished = true | ||
| RuntimeEventType.MAP_STILL_IMAGE_FAILED -> error(event.message) | ||
| } | ||
| } | ||
| if (finished) return captured ?: error("still image finished without a rendered frame") | ||
| runtime.pump(1) | ||
| } | ||
| error("still image did not finish") | ||
| } | ||
|
|
||
| private companion object { | ||
| private const val SNAPSHOT_SIZE = 64 | ||
| private const val COMPOSED_SOURCE_ID = "composed-point" | ||
| private val GREEN = byteArrayOf(0, -1, 0, -1) | ||
| private val BASE_STYLE = | ||
| jsonBytes( | ||
| """{"version":8,"sources":{},"layers":[{"id":"base","type":"background","paint":{"background-color":"#000000"}}]}""" | ||
| ) | ||
| private val ALTERNATE_STYLE = | ||
| jsonBytes( | ||
| """{"version":8,"sources":{},"layers":[{"id":"alternate","type":"background","paint":{"background-color":"#0000ff"}}]}""" | ||
| ) | ||
| private val COMPOSED_SOURCE = | ||
| jsonBytes("""{"type":"geojson","data":{"type":"Point","coordinates":[0,0]}}""") | ||
| private val COMPOSED_LAYER = | ||
| jsonBytes( | ||
| """{"id":"composed-circle","type":"circle","source":"composed-point","paint":{"circle-color":"#00ff00","circle-radius":20}}""" | ||
| ) | ||
| } | ||
| } |
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
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
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
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
108 changes: 108 additions & 0 deletions
108
patches/maplibre-native/0004-opengl-valid-api-calls.patch
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,108 @@ | ||
| diff --git a/src/mln/gl/context.cpp b/src/mln/gl/context.cpp | ||
| index 02efd92..be82bff 100644 | ||
| --- a/src/mln/gl/context.cpp | ||
| +++ b/src/mln/gl/context.cpp | ||
| @@ -151,10 +151,26 @@ void Context::endFrame() { | ||
| void Context::initializeExtensions(const std::function<gl::ProcAddress(const char*)>& getProcAddress) { | ||
| MLN_TRACE_FUNC(); | ||
|
|
||
| - if (const auto* extensions = reinterpret_cast<const char*>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)))) { | ||
| + std::string extensions; | ||
| +#if defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__OHOS__) | ||
| + GLint extensionCount = 0; | ||
| + MBGL_CHECK_ERROR(glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount)); | ||
| + for (GLint index = 0; index < extensionCount; ++index) { | ||
| + if (const auto* extension = reinterpret_cast<const char*>(MBGL_CHECK_ERROR(glGetStringi(GL_EXTENSIONS, index)))) { | ||
|
sargunv marked this conversation as resolved.
|
||
| + extensions.append(extension); | ||
| + extensions.push_back(' '); | ||
| + } | ||
| + } | ||
| +#else | ||
| + if (const auto* extensionList = reinterpret_cast<const char*>(MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)))) { | ||
| + extensions = extensionList; | ||
| + } | ||
| +#endif | ||
| + | ||
| + if (!extensions.empty()) { | ||
| auto fn = [&](std::initializer_list<std::pair<const char*, const char*>> probes) -> ProcAddress { | ||
| for (auto probe : probes) { | ||
| - if (strstr(extensions, probe.first) != nullptr) { | ||
| + if (extensions.find(probe.first) != std::string::npos) { | ||
| if (ProcAddress ptr = getProcAddress(probe.second)) { | ||
| return ptr; | ||
| } | ||
| diff --git a/src/mln/gl/resource_pool.cpp b/src/mln/gl/resource_pool.cpp | ||
| index 5c9fb64..df311df 100644 | ||
| --- a/src/mln/gl/resource_pool.cpp | ||
| +++ b/src/mln/gl/resource_pool.cpp | ||
| @@ -145,15 +145,18 @@ TextureID Texture2DPool::allocateGLMemory(const Texture2DDesc& desc) { | ||
| // Bind to TU 0 and upload | ||
| context->activeTextureUnit = 0; | ||
| context->texture[0] = id; | ||
| - MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, | ||
| - 0, | ||
| - Enum<gfx::TexturePixelType>::sizedFor(desc.pixelFormat, desc.channelType), | ||
| - desc.size.width, | ||
| - desc.size.height, | ||
| - 0, | ||
| - Enum<gfx::TexturePixelType>::to(desc.pixelFormat), | ||
| - Enum<gfx::TextureChannelDataType>::to(desc.channelType), | ||
| - nullptr)); | ||
| + // Attribute only errors from this allocation to allocation failure. | ||
| + while (glGetError() != GL_NO_ERROR) { | ||
| + } | ||
| + glTexImage2D(GL_TEXTURE_2D, | ||
| + 0, | ||
| + Enum<gfx::TexturePixelType>::sizedFor(desc.pixelFormat, desc.channelType), | ||
| + desc.size.width, | ||
| + desc.size.height, | ||
| + 0, | ||
| + Enum<gfx::TexturePixelType>::to(desc.pixelFormat), | ||
| + Enum<gfx::TextureChannelDataType>::to(desc.channelType), | ||
| + nullptr); | ||
| if (glGetError()) { | ||
| throw std::bad_alloc(); | ||
| } | ||
| diff --git a/src/mln/gl/uniform_buffer_gl.cpp b/src/mln/gl/uniform_buffer_gl.cpp | ||
| index 3ebafe8..0797706 100644 | ||
| --- a/src/mln/gl/uniform_buffer_gl.cpp | ||
| +++ b/src/mln/gl/uniform_buffer_gl.cpp | ||
| @@ -89,9 +89,9 @@ UniformBufferGL::UniformBufferGL(const UniformBufferGL& other) | ||
| managedBuffer.allocate(other.managedBuffer.getContents().data(), other.size); | ||
| } else { | ||
| MBGL_CHECK_ERROR(glGenBuffers(1, &localID)); | ||
| - MBGL_CHECK_ERROR(glCopyBufferSubData(other.localID, localID, 0, 0, size)); | ||
| MBGL_CHECK_ERROR(glBindBuffer(GL_COPY_READ_BUFFER, other.localID)); | ||
| MBGL_CHECK_ERROR(glBindBuffer(GL_COPY_WRITE_BUFFER, localID)); | ||
| + MBGL_CHECK_ERROR(glBufferData(GL_COPY_WRITE_BUFFER, size, nullptr, GL_DYNAMIC_DRAW)); | ||
| MBGL_CHECK_ERROR(glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, size)); | ||
|
sargunv marked this conversation as resolved.
|
||
| } | ||
| } | ||
| diff --git a/src/mln/gl/upload_pass.cpp b/src/mln/gl/upload_pass.cpp | ||
| index 2eb6ef7..3940ae2 100644 | ||
| --- a/src/mln/gl/upload_pass.cpp | ||
| +++ b/src/mln/gl/upload_pass.cpp | ||
| @@ -35,7 +35,10 @@ std::unique_ptr<gfx::VertexBufferResource> UploadPass::createVertexBufferResourc | ||
| // NOLINTNEXTLINE(performance-move-const-arg) | ||
| UniqueBuffer result{std::move(id), {commandEncoder.context}}; | ||
| commandEncoder.context.vertexBuffer = result; | ||
| - MBGL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, size, data, Enum<gfx::BufferUsageType>::to(usage))); | ||
| + // Attribute only errors from this allocation to allocation failure. | ||
| + while (glGetError() != GL_NO_ERROR) { | ||
| + } | ||
| + glBufferData(GL_ARRAY_BUFFER, size, data, Enum<gfx::BufferUsageType>::to(usage)); | ||
| if (glGetError()) { | ||
| throw std::bad_alloc(); | ||
| } | ||
| @@ -63,7 +66,10 @@ std::unique_ptr<gfx::IndexBufferResource> UploadPass::createIndexBufferResource( | ||
| UniqueBuffer result{std::move(id), {commandEncoder.context}}; | ||
| commandEncoder.context.bindVertexArray = 0; | ||
| commandEncoder.context.globalVertexArrayState.indexBuffer = result; | ||
| - MBGL_CHECK_ERROR(glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, Enum<gfx::BufferUsageType>::to(usage))); | ||
| + // Attribute only errors from this allocation to allocation failure. | ||
| + while (glGetError() != GL_NO_ERROR) { | ||
| + } | ||
| + glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data, Enum<gfx::BufferUsageType>::to(usage)); | ||
| if (glGetError()) { | ||
| throw std::bad_alloc(); | ||
| } | ||
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
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
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
Oops, something went wrong.
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.