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
decouple render core & hardware from UI #4580
Conversation
7c2d025
to
7198227
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look like a good refactoring to me, just a couple of minor comments/questions.
frontend/configurable.lua
Outdated
end | ||
end | ||
local prefix = config_defaults.prefix.."_" | ||
for key, value in pairs(config_defaults.options) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: think about this in more detail later.
I'm a bit confused about when I will have to use Well, it looks like some of this stuff may have some sense, but it also looks like it adds indirection, complexity and shuffle a bit what I'm used to :) One thing that bothers me a bit is the separation of the creoptions/koptoptions defaults from the widget definitions and available values. Will make reading both less easy, and harder to notice when a default drift away from the available options (not that we change them that often, but still :). And the name |
0e613c9
to
b134f18
Compare
Short answer is use Screen for UI and RuntimeCtl for document rendering code. Right now, some of the document rendering code still lives with UI code, so it's confusing. It will be clear when we completely separate the UI code (frontend) and document handling code (backend) into two folders, then we can say only use Screen for code inside ui folder.
Same here, I hate unnecessary abstractions so I try to avoid it whenever I can. See below for why I added RuntimeCtl.
I agree, I will see if there is better way to organize this. The problem here is available options are tightly coupled with UI texts, so we can't simply make it part of the defaults. Maybe the defaults should just be part of the UI and not provided by the core.
Yeah, naming is hard, not a fan of this name either. Would love to get some suggestions.
Short answer is no, since RuntimeCtl is not supposed to be used by the UI so changing the value in this module will only affect document rendering result. This module is created to mainly abstract hardware settings. For example, mupdf has a function called The goal of this PR is to make it possible to use the core document parsing & rendering logic as a lua library without having to spin up the whole builtin UI framework or go through any hardware handling code: ...
local Runtimectl = require("runtimectl")
local Device = require("device/dummy/device"):new{
viewport = require("ui/geometry"):new{x=0, y=0, w=600, h=800}
}
Runtimectl:init(Device)
local doc = require("document/documentregistry"):openDocument("path.pdf")
print("page count", doc:getPageCount())
local tile = doc:renderPage(1, {x = 0, y = 0, w = 600, h = 800}, 1, 0, 0, 0)
... With this, you can build powerful CLI tools in LUA to automate any kind of document processing tasks. For example, batch document reflow or metadata indexing. Next PR would be adding headless koreader mode, which exposes the LUA API through RPC interfaces (gRPC for now). This makes is possible to build frontend in any language & framework. Also makes it very easy to run the core rendering logic in a separate process. This is something I started a long time ago to solve two pain points:
I stopped working on this refactoring two years ago due to lack of free time. Recently, I have been thinking of writing a prototype VR reader for fun, so here I am, trying to finish up an old refactoring :) Here is a screenshot of I what I built during the weekend: It's a 150 lines electron reader app powered by koreader core. Disclaimer: I am not a fan of electron at all, it's too bloated for my taste. I am only using it for fast prototyping because I am already very familiar with html canvas. my ultimate goal is to play around with a prototype VR reader and I am definitely not interested in adding VR support to the existing UI framework :P |
Something with a word like render or context?
Funny, I considered replying with that exact example (HTML canvas, that is). I've been entertaining the notion of creating a similar abstraction but I never got around to it. I was thinking less drastically, more in the direction of making the GPU take care of a bunch of stuff that it currently doesn't, using e.g. GL surface textures on Android and SDL, but essentially with the same UI framework even though the abstraction would've made that optional. |
In fact I just noticed you suggestively changed the PR title to |
Thanks for the detailed answer and story.
Why not Regarding your two old pain points (which might not be what you're focusing on these days, just updating you after your long absence):
Memory usage growing is still happening. But I'm not sure it's always the rendering libraries or glue fault. It could very well be the UI/luajit code. Or (my intuition) the interleaving of both in a single process, making freed memory holes often not reused. Having these decoupled in 2 processes would help pinpoint which of them is the most reponsible for that, but I'm not sure a restart of the UI would not be needed at some point too.
Spent a lot of time fixing these last year. I hope we are now past having that distraction.
@Frenzie had shoved most of them in the Size.lua module a year ago too.
I understand. But we should try to not make the current real/existing/used/delivered/active lua/ui/widgets even more abstract (and so, even more hard to learn) in the hope to allow the birth of other frontend code (haven't read anyone wishing to become such a parent before now :)
Thanks ! :) (There is a huge PR in coolreader github repo about something similar, that must make the devs there quite perplexed.) |
My main motivation there was standardization of sizes for UI consistency, but yes, the basic idea is that 9 times out of 10 you shouldn't be touching scaleBySize directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming only the name changed in the most recent update, it's good to go in my book.
No more comment. Tested on my Kobo, no apparent issue. |
The widget builder was broken by <koreader#4580>.
The widget builder was broken by <#4580>.
The widget builder was broken by <koreader#4580>.
All hardware dependent settings are abstracted into a new module called runtimectl.
This PR is just an internal refactoring and adds no new functionality. It should have no end user impact (assuming no bug is introduced). For developers, you will be able to use koreader core as a library without its own UI framework & hardware handling code.
Once this is merged, i will send a follow up PR to enable building a headless koreader with RPC support.
This PR depends on koreader/koreader-base#822.