diff --git a/core/src/main/java/icyllis/modernui/ModernUI.java b/core/src/main/java/icyllis/modernui/ModernUI.java index 55174dcb..9111462a 100644 --- a/core/src/main/java/icyllis/modernui/ModernUI.java +++ b/core/src/main/java/icyllis/modernui/ModernUI.java @@ -155,6 +155,8 @@ public void run(@NonNull Fragment fragment) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_DEPTH_BITS, 0); + glfwWindowHint(GLFW_STENCIL_BITS, 0); glfwWindowHintString(GLFW_X11_CLASS_NAME, NAME_CPT); glfwWindowHintString(GLFW_X11_INSTANCE_NAME, NAME_CPT); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); diff --git a/core/src/main/java/icyllis/modernui/TestFragment.java b/core/src/main/java/icyllis/modernui/TestFragment.java index 701b85c5..790c3d56 100644 --- a/core/src/main/java/icyllis/modernui/TestFragment.java +++ b/core/src/main/java/icyllis/modernui/TestFragment.java @@ -977,7 +977,7 @@ private static class DView extends View { public DView(Context context, TimeInterpolator interpolator) { super(context); - mTextPaint.setTextSize(10); + mTextPaint.setTextSize(13); /*animation = new Animation(200) .applyTo(new Applier(0, 60, () -> offsetY, v -> { offsetY = v; @@ -1002,7 +1002,7 @@ protected void onDraw(@Nonnull Canvas canvas) { Paint paint = Paint.obtain(); paint.setARGB(128, 140, 200, 240); canvas.drawRoundRect(0, 1, getWidth(), getHeight() - 2, 4, paint); - TextUtils.drawTextRun(canvas, "18:52", 0, 5, 0, 5, getWidth() / 2f, offsetY + 24, false, mTextPaint); + TextUtils.drawTextRun(canvas, "18:52 modernui", 0, 14, 0, 14, getWidth() / 2f - 20f, offsetY + 24, false, mTextPaint); paint.recycle(); } diff --git a/core/src/main/java/icyllis/modernui/graphics/GLSurfaceCanvas.java b/core/src/main/java/icyllis/modernui/graphics/GLSurfaceCanvas.java index 1a558cfd..196df901 100644 --- a/core/src/main/java/icyllis/modernui/graphics/GLSurfaceCanvas.java +++ b/core/src/main/java/icyllis/modernui/graphics/GLSurfaceCanvas.java @@ -302,7 +302,8 @@ public GLSurfaceCanvas(GLDevice device) { mRoundRectUBO.allocate(ROUND_RECT_UNIFORM_SIZE); mLinearSampler = Objects.requireNonNull( - device.getResourceProvider().findOrCreateCompatibleSampler(SamplerState.DEFAULT), + device.getResourceProvider().findOrCreateCompatibleSampler( + SamplerState.make(SamplerState.FILTER_LINEAR, SamplerState.MIPMAP_MODE_LINEAR)), "Failed to create font sampler"); { diff --git a/core/src/main/java/icyllis/modernui/graphics/font/GLFontAtlas.java b/core/src/main/java/icyllis/modernui/graphics/font/GLFontAtlas.java index c2156eb8..233b7c8d 100644 --- a/core/src/main/java/icyllis/modernui/graphics/font/GLFontAtlas.java +++ b/core/src/main/java/icyllis/modernui/graphics/font/GLFontAtlas.java @@ -25,11 +25,12 @@ import icyllis.modernui.annotation.*; import icyllis.modernui.core.Core; import icyllis.modernui.graphics.Bitmap; +import icyllis.modernui.text.TextUtils; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; -import org.lwjgl.system.MemoryStack; import java.io.IOException; +import java.io.PrintWriter; import java.nio.file.Path; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -188,8 +189,10 @@ public boolean stitch(@NonNull BakedGlyph glyph, long pixels) { private boolean resize() { if (mTexture == null) { - // initialize 4 chunks - mWidth = mHeight = CHUNK_SIZE * 2; + // initialize 4 or 16 chunks + mWidth = mHeight = mMaskFormat == Engine.MASK_FORMAT_A8 + ? CHUNK_SIZE * 4 + : CHUNK_SIZE * 2; mTexture = createTexture(); for (int x = 0; x < mWidth; x += CHUNK_SIZE) { for (int y = 0; y < mHeight; y += CHUNK_SIZE) { @@ -281,7 +284,6 @@ private boolean resize() { if (mMaskFormat == Engine.MASK_FORMAT_A8) { //XXX: un-premultiplied, so 111r rather than rrrr - // in case of some driver bugs, we don't use GL_TEXTURE_SWIZZLE_RGBA glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_ONE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_ONE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_ONE); @@ -434,6 +436,32 @@ public long getMemorySize() { return mTexture != null ? mTexture.getMemorySize() : 0; } + public void dumpInfo(PrintWriter pw, String name) { + int validGlyphs = 0; + int emptyGlyphs = 0; + int evictedGlyphs = 0; + for (var glyph : mGlyphs.values()) { + if (glyph == null) { + emptyGlyphs++; + } else if (glyph.x == Short.MIN_VALUE) { + evictedGlyphs++; + } else { + validGlyphs++; + } + } + pw.print(name); + pw.printf(": NumGlyphs=%d (in-use: %d, empty: %d, evicted: %d)", + getGlyphCount(), validGlyphs, emptyGlyphs, evictedGlyphs); + pw.print(", Coverage="); + pw.printf("%.4f", getCoverage()); + pw.print(", GPUMemorySize="); + long memorySize = getMemorySize(); + TextUtils.binaryCompact(pw, memorySize); + pw.print(" ("); + pw.print(memorySize); + pw.println(" bytes)"); + } + /** * @return 0..1 */ diff --git a/core/src/main/java/icyllis/modernui/graphics/font/GlyphManager.java b/core/src/main/java/icyllis/modernui/graphics/font/GlyphManager.java index e0a18e59..a328aa08 100644 --- a/core/src/main/java/icyllis/modernui/graphics/font/GlyphManager.java +++ b/core/src/main/java/icyllis/modernui/graphics/font/GlyphManager.java @@ -29,7 +29,6 @@ import icyllis.modernui.graphics.BitmapFactory; import icyllis.modernui.graphics.text.Font; import icyllis.modernui.graphics.text.*; -import icyllis.modernui.text.TextUtils; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.MarkerManager; @@ -354,23 +353,11 @@ private static void debug(GLFontAtlas atlas, String name) { } public void dumpInfo(PrintWriter pw) { - dumpInfo(pw, mFontAtlas, "FontAtlas"); - dumpInfo(pw, mEmojiAtlas, "EmojiAtlas"); - } - - private static void dumpInfo(PrintWriter pw, GLFontAtlas atlas, String name) { - if (atlas != null) { - pw.print(name); - pw.print(": Glyphs="); - pw.print(atlas.getGlyphCount()); - pw.print(", Coverage="); - pw.printf("%.4f", atlas.getCoverage()); - pw.print(", GPUMemorySize="); - long memorySize = atlas.getMemorySize(); - TextUtils.binaryCompact(pw, memorySize); - pw.print(" ("); - pw.print(memorySize); - pw.println(" bytes)"); + if (mFontAtlas != null) { + mFontAtlas.dumpInfo(pw, "FontAtlas"); + } + if (mEmojiAtlas != null) { + mEmojiAtlas.dumpInfo(pw, "EmojiAtlas"); } }