Stash enableCPUCores in CanvasContext

Avoids requring Device direction in Document.

The method needs complete access to the Device object, though, so it's
just another layer of indirection, with an extra reference on the Device
object stashed in CanvasContext...
(much like it already does for Screen)
reviewable/pr8694/r1
NiLuJe 2 years ago committed by poire-z
parent 5e3790677e
commit 7018853940

@ -35,6 +35,7 @@ The following key is required for a device object:
* isColorEnabled() -> boolean
]]--
function CanvasContext:init(device)
self.device = device
self.screen = device.screen
self.isAndroid = device.isAndroid
self.isDesktop = device.isDesktop
@ -45,7 +46,7 @@ function CanvasContext:init(device)
self.hasSystemFonts = device.hasSystemFonts
self:setColorRenderingEnabled(device.screen.isColorEnabled())
-- NOTE: Kobo's fb is BGR, not RGB. Handle the conversion in MuPDF if needed.
-- NOTE: At 32bpp, Kobo's fb is BGR, not RGB. Handle the conversion in MuPDF if needed.
if device:hasBGRFrameBuffer() then
self.is_bgr = true
Mupdf.bgr = true
@ -77,4 +78,8 @@ function CanvasContext:scaleBySize(px)
return self.screen:scaleBySize(px)
end
function CanvasContext:enableCPUCores(amount)
return self.device:enableCPUCores(amount)
end
return CanvasContext

@ -1,7 +1,6 @@
local Blitbuffer = require("ffi/blitbuffer")
local CacheItem = require("cacheitem")
local Configurable = require("configurable")
local Device = require("device")
local DocCache = require("document/doccache")
local DrawContext = require("ffi/drawcontext")
local CanvasContext = require("document/canvascontext")
@ -413,7 +412,7 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode, h
end
if hinting then
Device:enableCPUCores(2)
CanvasContext:enableCPUCores(2)
end
self:preRenderPage()
@ -429,7 +428,7 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode, h
logger.warn("aborting, since we do not have a specification for that part")
-- required part not given, so abort
if hinting then
Device:enableCPUCores(1)
CanvasContext:enableCPUCores(1)
end
return
end
@ -474,7 +473,7 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode, h
self:postRenderPage()
if hinting then
Device:enableCPUCores(1)
CanvasContext:enableCPUCores(1)
end
return tile
end

@ -6,7 +6,6 @@ local CacheItem = require("cacheitem")
local CanvasContext = require("document/canvascontext")
local DataStorage = require("datastorage")
local DEBUG = require("dbg")
local Device = require("device")
local DocCache = require("document/doccache")
local Document = require("document/document")
local FFIUtil = require("ffi/util")
@ -111,7 +110,7 @@ function KoptInterface:waitForContext(kc)
if waited or self.bg_thread then
-- Background thread is done, go back to a single CPU core.
Device:enableCPUCores(1)
CanvasContext:enableCPUCores(1)
self.bg_thread = nil
end
@ -392,7 +391,7 @@ function KoptInterface:renderOptimizedPage(doc, pageno, rect, zoom, rotation, re
local cached = DocCache:check(hash, TileCacheItem)
if not cached then
if hinting then
Device:enableCPUCores(2)
CanvasContext:enableCPUCores(2)
end
local page_size = Document.getNativePageDimensions(doc, pageno)
@ -425,7 +424,7 @@ function KoptInterface:renderOptimizedPage(doc, pageno, rect, zoom, rotation, re
DocCache:insert(hash, tile)
if hinting then
Device:enableCPUCores(1)
CanvasContext:enableCPUCores(1)
end
return tile
@ -464,7 +463,7 @@ function KoptInterface:hintReflowedPage(doc, pageno, zoom, rotation, gamma, rend
local cached = DocCache:check(hash)
if not cached then
if hinting then
Device:enableCPUCores(2)
CanvasContext:enableCPUCores(2)
end
local kc = self:createContext(doc, pageno, bbox)

Loading…
Cancel
Save