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
|
return paint
|
||||||
end
|
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)
|
function draw_bullet(canvas, x, y, paint, indent)
|
||||||
if 0 == indent then
|
if 0 == indent then
|
||||||
return
|
return
|
||||||
@ -46,7 +72,14 @@ function stroke_rect(canvas, rect, color)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function drawSlide(canvas, slide, master_template)
|
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 x = template.margin_x
|
||||||
local y = template.margin_y
|
local y = template.margin_y
|
||||||
@ -173,23 +206,19 @@ end
|
|||||||
function next_slide()
|
function next_slide()
|
||||||
local prev = gSlides[gSlideIndex]
|
local prev = gSlides[gSlideIndex]
|
||||||
|
|
||||||
gSlideIndex = gSlideIndex + 1
|
if gSlideIndex < #gSlides then
|
||||||
if gSlideIndex > #gSlides then
|
gSlideIndex = gSlideIndex + 1
|
||||||
gSlideIndex = 1
|
spawn_transition(prev, gSlides[gSlideIndex], true)
|
||||||
end
|
end
|
||||||
|
|
||||||
spawn_transition(prev, gSlides[gSlideIndex], true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function prev_slide()
|
function prev_slide()
|
||||||
local prev = gSlides[gSlideIndex]
|
local prev = gSlides[gSlideIndex]
|
||||||
|
|
||||||
gSlideIndex = gSlideIndex - 1
|
if gSlideIndex > 1 then
|
||||||
if gSlideIndex < 1 then
|
gSlideIndex = gSlideIndex - 1
|
||||||
gSlideIndex = #gSlides
|
spawn_transition(prev, gSlides[gSlideIndex], false)
|
||||||
end
|
end
|
||||||
|
|
||||||
spawn_transition(prev, gSlides[gSlideIndex], false)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function convert_to_picture_drawable(slide)
|
function convert_to_picture_drawable(slide)
|
||||||
@ -204,7 +233,6 @@ function convert_to_image_drawable(slide)
|
|||||||
return new_drawable_image(surf:newImageSnapshot())
|
return new_drawable_image(surf:newImageSnapshot())
|
||||||
end
|
end
|
||||||
|
|
||||||
-- gMakeDrawable = convert_to_picture_drawable
|
|
||||||
gMakeDrawable = new_drawable_slide
|
gMakeDrawable = new_drawable_slide
|
||||||
|
|
||||||
load_file("slides_transitions")
|
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 },
|
local grad = Sk.newLinearGradient( 0, 0, { a=1, r=0, g=0, b=.3 },
|
||||||
640, 480, { a=1, r=0, g=0, b=.8 })
|
640, 480, { a=1, r=0, g=0, b=.8 })
|
||||||
bgPaint:setShader(grad)
|
bgPaint:setShader(grad)
|
||||||
|
bgPaint:setDither(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
canvas:drawPaint(bgPaint)
|
canvas:drawPaint(bgPaint)
|
||||||
|
@ -2,80 +2,29 @@ Skia Update
|
|||||||
|
|
||||||
Skia : Overview
|
Skia : Overview
|
||||||
- portable 2D graphics engine
|
- portable 2D graphics engine
|
||||||
- src: geometry, images, text
|
- src : geometry, images, text
|
||||||
- dst : raster, gpu, pdf, displaylist, *user-defined
|
- attr: shaders, filters, antialiasing, blending
|
||||||
- attr: shaders, filters, antialiasing, blending, *user-defined
|
- dst : raster, gpu, pdf, picture
|
||||||
|
|
||||||
Skia : Clients
|
|
||||||
- Blink : direct and via GraphicsContext
|
|
||||||
- Chrome : ui/gfx and compositor
|
|
||||||
- Android framework
|
|
||||||
- third parties : e.g. Mozilla
|
|
||||||
- code.google.com/p/skia
|
|
||||||
|
|
||||||
Skia : Porting
|
Skia : Porting
|
||||||
- C++ and some SIMD assembly
|
- C++ and some SIMD assembly
|
||||||
- Fonts : CoreText, FreeType, GDI, DirectWrite, *user-define
|
- Fonts : CoreText, FreeType, GDI, DirectWrite
|
||||||
- Threads : wrappers for native apis
|
- Threads : wrappers for native apis
|
||||||
- Memory : wrappers for [new, malloc, discardable]
|
- Memory : wrappers for [new, malloc, discardable]
|
||||||
|
|
||||||
Skia : API
|
Skia : Clients
|
||||||
- SkCanvas
|
- Blink : under the GraphicsContext hood
|
||||||
-- save, saveLayer, restore
|
- Chrome : ui/gfx and compositor
|
||||||
-- translate, scale, rotate, concat
|
- Android framework
|
||||||
-- clipRect, clipPath
|
- third parties : e.g. Mozilla
|
||||||
- SkPaint
|
- sites.google.com/site/skiadocs
|
||||||
-- color, stroking, antialiasing, filtering
|
|
||||||
-- typeface, textSize, text-flags
|
|
||||||
-- effects: shader, color-filter, image-filter, mask-filter, xfermode
|
|
||||||
|
|
||||||
<blockstyle = code>
|
Skia In Blink
|
||||||
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 : Fonts
|
Skia In Blink : Fonts
|
||||||
- Assist with code-sharing between platforms
|
- SkTypeface and SkFontMgr : platform agnostic
|
||||||
- Runtime switch between GDI and DirectWrite
|
- Runtime switch between GDI and DirectWrite
|
||||||
- Add SkFontMgr for selection
|
- SkTextBlob to encapsulate runs of text
|
||||||
- Push LCD decision-making out of Blink
|
- Push LCD decision-making out of Blink
|
||||||
|
|
||||||
Skia In Blink : Record-Time-Rasterization
|
Skia In Blink : Record-Time-Rasterization
|
||||||
@ -89,8 +38,52 @@ Skia In Blink : Record-Time-Rasterization
|
|||||||
|
|
||||||
Skia In Blink : RTR response
|
Skia In Blink : RTR response
|
||||||
- SkImageFilter w/ CPU and GPU implementations
|
- SkImageFilter w/ CPU and GPU implementations
|
||||||
- SkPaint::FilterLevel : none, low, medium (mipmaps), high
|
- FilterLevel : none, low, medium (mipmaps), high
|
||||||
- SkPicture for caching SVG
|
- SkPicture for caching SVG
|
||||||
- SkPicture + saveLayer() for masks
|
- SkPicture + saveLayer() for masks
|
||||||
-- PathOps for resolving complex paths
|
-- PathOps for resolving complex paths
|
||||||
- SkPictureShader for device-independent patterns
|
- 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")
|
io.write("}\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
function parse_transition_type(s)
|
function parse_attr(s, lvalue)
|
||||||
return s:match("^<%s*transition%s*=%s*(%a+)%s*>$")
|
local ts = "^<%s*" .. lvalue .. "%s*=%s*(%a+)%s*>$"
|
||||||
|
return s:match(ts)
|
||||||
end
|
end
|
||||||
|
|
||||||
function parse_blockstyle_type(s)
|
function flush(slides, block)
|
||||||
return s:match("^<%s*blockstyle%s*=%s*(%a+)%s*>$")
|
if #block > 0 then
|
||||||
|
slides[#slides + 1] = block
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
return block
|
||||||
end
|
end
|
||||||
|
|
||||||
function parse_file(file)
|
function parse_file(file)
|
||||||
@ -69,13 +74,10 @@ function parse_file(file)
|
|||||||
for line in file:lines() do
|
for line in file:lines() do
|
||||||
local s = trim_ws(line)
|
local s = trim_ws(line)
|
||||||
if #s == 0 then -- done with a block
|
if #s == 0 then -- done with a block
|
||||||
if #block > 0 then
|
block = flush(slides, block)
|
||||||
slides[#slides + 1] = block
|
|
||||||
block = {}
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
local transition_type = parse_transition_type(s)
|
local transition_type = parse_attr(s, "transition")
|
||||||
local blockstyle = parse_blockstyle_type(s)
|
local blockstyle = parse_attr(s, "blockstyle")
|
||||||
if transition_type then
|
if transition_type then
|
||||||
block["transition"] = transition_type
|
block["transition"] = transition_type
|
||||||
elseif blockstyle then
|
elseif blockstyle then
|
||||||
|
@ -761,6 +761,11 @@ static int lpaint_isDither(lua_State* L) {
|
|||||||
return 1;
|
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) {
|
static int lpaint_isUnderlineText(lua_State* L) {
|
||||||
lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isUnderlineText());
|
lua_pushboolean(L, get_obj<SkPaint>(L, 1)->isUnderlineText());
|
||||||
return 1;
|
return 1;
|
||||||
@ -1061,6 +1066,7 @@ static const struct luaL_Reg gSkPaint_Methods[] = {
|
|||||||
{ "isAntiAlias", lpaint_isAntiAlias },
|
{ "isAntiAlias", lpaint_isAntiAlias },
|
||||||
{ "setAntiAlias", lpaint_setAntiAlias },
|
{ "setAntiAlias", lpaint_setAntiAlias },
|
||||||
{ "isDither", lpaint_isDither },
|
{ "isDither", lpaint_isDither },
|
||||||
|
{ "setDither", lpaint_setDither },
|
||||||
{ "isUnderlineText", lpaint_isUnderlineText },
|
{ "isUnderlineText", lpaint_isUnderlineText },
|
||||||
{ "isStrikeThruText", lpaint_isStrikeThruText },
|
{ "isStrikeThruText", lpaint_isStrikeThruText },
|
||||||
{ "isFakeBoldText", lpaint_isFakeBoldText },
|
{ "isFakeBoldText", lpaint_isFakeBoldText },
|
||||||
|
Loading…
Reference in New Issue
Block a user