update slide content
BUG=skia: TBR= Review URL: https://codereview.chromium.org/698563004
This commit is contained in:
parent
1b6ab4417e
commit
bb8a0ababa
@ -27,6 +27,32 @@ function make_paint(typefacename, stylebits, size, color)
|
||||
return paint
|
||||
end
|
||||
|
||||
function center_rect(sw, sh, dst)
|
||||
local dw = dst.right - dst.left
|
||||
local dh = dst.bottom - dst.top
|
||||
|
||||
local rw, rh
|
||||
|
||||
if sw / sh > dw / dh then
|
||||
rw = dw
|
||||
rh = sh * dw / sw
|
||||
else
|
||||
rh = dh
|
||||
rw = sw * dh / sh
|
||||
end
|
||||
|
||||
local x = dst.left + ((sw - rw) / 2)
|
||||
local y = dst.top + ((sh - rh) / 2)
|
||||
return make_rect(x, y, x + rw, y + rh)
|
||||
end
|
||||
|
||||
function draw_image_centered(canvas, image)
|
||||
local sw = image:width()
|
||||
local sh = image:height()
|
||||
local dstR = center_rect(image:width(), image:height(), make_rect(20, 20, 620, 460))
|
||||
canvas:drawImageRect(image, nil, dstR)
|
||||
end
|
||||
|
||||
function draw_bullet(canvas, x, y, paint, indent)
|
||||
if 0 == indent then
|
||||
return
|
||||
@ -46,7 +72,14 @@ function stroke_rect(canvas, rect, color)
|
||||
end
|
||||
|
||||
function drawSlide(canvas, slide, master_template)
|
||||
template = master_template.slide -- need to sniff the slide to know if we're title or slide
|
||||
|
||||
if #slide == 1 then
|
||||
template = master_template.title
|
||||
canvas:drawText(slide[1].text, 320, 240, template[1])
|
||||
return
|
||||
end
|
||||
|
||||
template = master_template.slide
|
||||
|
||||
local x = template.margin_x
|
||||
local y = template.margin_y
|
||||
@ -173,23 +206,19 @@ end
|
||||
function next_slide()
|
||||
local prev = gSlides[gSlideIndex]
|
||||
|
||||
gSlideIndex = gSlideIndex + 1
|
||||
if gSlideIndex > #gSlides then
|
||||
gSlideIndex = 1
|
||||
if gSlideIndex < #gSlides then
|
||||
gSlideIndex = gSlideIndex + 1
|
||||
spawn_transition(prev, gSlides[gSlideIndex], true)
|
||||
end
|
||||
|
||||
spawn_transition(prev, gSlides[gSlideIndex], true)
|
||||
end
|
||||
|
||||
function prev_slide()
|
||||
local prev = gSlides[gSlideIndex]
|
||||
|
||||
gSlideIndex = gSlideIndex - 1
|
||||
if gSlideIndex < 1 then
|
||||
gSlideIndex = #gSlides
|
||||
if gSlideIndex > 1 then
|
||||
gSlideIndex = gSlideIndex - 1
|
||||
spawn_transition(prev, gSlides[gSlideIndex], false)
|
||||
end
|
||||
|
||||
spawn_transition(prev, gSlides[gSlideIndex], false)
|
||||
end
|
||||
|
||||
function convert_to_picture_drawable(slide)
|
||||
@ -204,7 +233,6 @@ function convert_to_image_drawable(slide)
|
||||
return new_drawable_image(surf:newImageSnapshot())
|
||||
end
|
||||
|
||||
-- gMakeDrawable = convert_to_picture_drawable
|
||||
gMakeDrawable = new_drawable_slide
|
||||
|
||||
load_file("slides_transitions")
|
||||
@ -285,6 +313,7 @@ function draw_bg(canvas)
|
||||
local grad = Sk.newLinearGradient( 0, 0, { a=1, r=0, g=0, b=.3 },
|
||||
640, 480, { a=1, r=0, g=0, b=.8 })
|
||||
bgPaint:setShader(grad)
|
||||
bgPaint:setDither(true)
|
||||
end
|
||||
|
||||
canvas:drawPaint(bgPaint)
|
||||
|
@ -2,80 +2,29 @@ Skia Update
|
||||
|
||||
Skia : Overview
|
||||
- portable 2D graphics engine
|
||||
- src: geometry, images, text
|
||||
- dst : raster, gpu, pdf, displaylist, *user-defined
|
||||
- attr: shaders, filters, antialiasing, blending, *user-defined
|
||||
|
||||
Skia : Clients
|
||||
- Blink : direct and via GraphicsContext
|
||||
- Chrome : ui/gfx and compositor
|
||||
- Android framework
|
||||
- third parties : e.g. Mozilla
|
||||
- code.google.com/p/skia
|
||||
- src : geometry, images, text
|
||||
- attr: shaders, filters, antialiasing, blending
|
||||
- dst : raster, gpu, pdf, picture
|
||||
|
||||
Skia : Porting
|
||||
- C++ and some SIMD assembly
|
||||
- Fonts : CoreText, FreeType, GDI, DirectWrite, *user-define
|
||||
- Fonts : CoreText, FreeType, GDI, DirectWrite
|
||||
- Threads : wrappers for native apis
|
||||
- Memory : wrappers for [new, malloc, discardable]
|
||||
|
||||
Skia : API
|
||||
- SkCanvas
|
||||
-- save, saveLayer, restore
|
||||
-- translate, scale, rotate, concat
|
||||
-- clipRect, clipPath
|
||||
- SkPaint
|
||||
-- color, stroking, antialiasing, filtering
|
||||
-- typeface, textSize, text-flags
|
||||
-- effects: shader, color-filter, image-filter, mask-filter, xfermode
|
||||
Skia : Clients
|
||||
- Blink : under the GraphicsContext hood
|
||||
- Chrome : ui/gfx and compositor
|
||||
- Android framework
|
||||
- third parties : e.g. Mozilla
|
||||
- sites.google.com/site/skiadocs
|
||||
|
||||
<blockstyle = code>
|
||||
void onDraw(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
paint.setFoo(...);
|
||||
canvas->drawRect(..., paint);
|
||||
paint.setBar(...);
|
||||
canvas->drawOval(..., paint);
|
||||
}
|
||||
|
||||
<blockstyle = code>
|
||||
void onDraw(SkCanvas* canvas) {
|
||||
canvas->drawRect(..., fPaint0);
|
||||
canvas->drawOval(..., fPaint1);
|
||||
}
|
||||
|
||||
Skia In Blink : GraphicsContext
|
||||
- Similar
|
||||
-- rects, paths, images, text
|
||||
-- matrices, clips
|
||||
- Different
|
||||
-- save/restore affect matrix+clip PLUS all paint settings
|
||||
-- both fill and stroke settings are specified
|
||||
-- hence: fillRect(), strokeRect(), drawRect()
|
||||
|
||||
<blockstyle = code>
|
||||
void onDraw(GraphicsContext* gc) {
|
||||
gc->save();
|
||||
gc->setFoo(...);
|
||||
gc->fillRect(...);
|
||||
gc->setBar(...);
|
||||
gc->fillOval(...);
|
||||
gc->restore();
|
||||
}
|
||||
|
||||
Skia In Blink : more than GraphicsContext
|
||||
- Simple wrappers
|
||||
-- FloatRect -- SkRect
|
||||
-- Path -- SkPath
|
||||
- Font.h + 21 others
|
||||
-- SkTypeface + flags
|
||||
- Image.h + 25 others
|
||||
-- SkBitmap, SkImage
|
||||
Skia In Blink
|
||||
|
||||
Skia In Blink : Fonts
|
||||
- Assist with code-sharing between platforms
|
||||
- SkTypeface and SkFontMgr : platform agnostic
|
||||
- Runtime switch between GDI and DirectWrite
|
||||
- Add SkFontMgr for selection
|
||||
- SkTextBlob to encapsulate runs of text
|
||||
- Push LCD decision-making out of Blink
|
||||
|
||||
Skia In Blink : Record-Time-Rasterization
|
||||
@ -89,8 +38,52 @@ Skia In Blink : Record-Time-Rasterization
|
||||
|
||||
Skia In Blink : RTR response
|
||||
- SkImageFilter w/ CPU and GPU implementations
|
||||
- SkPaint::FilterLevel : none, low, medium (mipmaps), high
|
||||
- FilterLevel : none, low, medium (mipmaps), high
|
||||
- SkPicture for caching SVG
|
||||
- SkPicture + saveLayer() for masks
|
||||
-- PathOps for resolving complex paths
|
||||
- SkPictureShader for device-independent patterns
|
||||
|
||||
Skia In Blink : Recording
|
||||
- GraphicsContext usuaually backed by SkPicture
|
||||
-- draw commands are recorded for later playback
|
||||
-- all parameters must be copied or (safely) ref'd
|
||||
-- may record more than is currently visible
|
||||
- Resulting picture may be replayed multiple times
|
||||
|
||||
Skia In Blink : Recording response
|
||||
- New implementation
|
||||
- Optimized for recording speed
|
||||
-- shallow copies whenever possible
|
||||
-- rearchitect all Skia effects to be immutable
|
||||
- Reentrant-safe for playback in multiple threads
|
||||
-- also affected effect subclasses
|
||||
|
||||
Skia In Blink : Playback
|
||||
- Separate pass for optimizations (optional)
|
||||
-- peep-holes rewrites
|
||||
-- compute bounding-box hierarchy for faster tiling
|
||||
-- can be done outside of Blink thread
|
||||
- GPU optimizations
|
||||
-- layer "hoisting"
|
||||
-- distance field fonts
|
||||
|
||||
Skia : Roadmap
|
||||
|
||||
Skia In Blink : Roadmap
|
||||
- GPU performance
|
||||
-- extended OpenGL features (e.g. geometry shaders)
|
||||
-- reordering for increased batching
|
||||
-- support for new low-level OpenGL APIs
|
||||
- Cross process support
|
||||
-- immediate mode ala SkGPipe
|
||||
-- serialize pictures
|
||||
|
||||
Skia API Roadmap
|
||||
- Direct support for sRGB
|
||||
- Stable C API / ABI
|
||||
-- bindings for JS, Go, Python, Lua
|
||||
- Robust file format
|
||||
|
||||
Demo
|
||||
|
||||
|
@ -54,12 +54,17 @@ function pretty_print_slides(slides)
|
||||
io.write("}\n")
|
||||
end
|
||||
|
||||
function parse_transition_type(s)
|
||||
return s:match("^<%s*transition%s*=%s*(%a+)%s*>$")
|
||||
function parse_attr(s, lvalue)
|
||||
local ts = "^<%s*" .. lvalue .. "%s*=%s*(%a+)%s*>$"
|
||||
return s:match(ts)
|
||||
end
|
||||
|
||||
function parse_blockstyle_type(s)
|
||||
return s:match("^<%s*blockstyle%s*=%s*(%a+)%s*>$")
|
||||
function flush(slides, block)
|
||||
if #block > 0 then
|
||||
slides[#slides + 1] = block
|
||||
return {}
|
||||
end
|
||||
return block
|
||||
end
|
||||
|
||||
function parse_file(file)
|
||||
@ -69,13 +74,10 @@ function parse_file(file)
|
||||
for line in file:lines() do
|
||||
local s = trim_ws(line)
|
||||
if #s == 0 then -- done with a block
|
||||
if #block > 0 then
|
||||
slides[#slides + 1] = block
|
||||
block = {}
|
||||
end
|
||||
block = flush(slides, block)
|
||||
else
|
||||
local transition_type = parse_transition_type(s)
|
||||
local blockstyle = parse_blockstyle_type(s)
|
||||
local transition_type = parse_attr(s, "transition")
|
||||
local blockstyle = parse_attr(s, "blockstyle")
|
||||
if transition_type then
|
||||
block["transition"] = transition_type
|
||||
elseif blockstyle then
|
||||
|
@ -761,6 +761,11 @@ static int lpaint_isDither(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lpaint_setDither(lua_State* L) {
|
||||
get_obj<SkPaint>(L, 1)->setDither(lua2bool(L, 2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lpaint_isUnderlineText(lua_State* L) {
|
||||
lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isUnderlineText());
|
||||
return 1;
|
||||
@ -1061,6 +1066,7 @@ static const struct luaL_Reg gSkPaint_Methods[] = {
|
||||
{ "isAntiAlias", lpaint_isAntiAlias },
|
||||
{ "setAntiAlias", lpaint_setAntiAlias },
|
||||
{ "isDither", lpaint_isDither },
|
||||
{ "setDither", lpaint_setDither },
|
||||
{ "isUnderlineText", lpaint_isUnderlineText },
|
||||
{ "isStrikeThruText", lpaint_isStrikeThruText },
|
||||
{ "isFakeBoldText", lpaint_isFakeBoldText },
|
||||
|
Loading…
Reference in New Issue
Block a user