25
ONscreen vs. OFFscreen rendering Tomáš Jukin @Inza

ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

Embed Size (px)

DESCRIPTION

Slidy z mé prezentace na téma "ONscreen vs. OFFscreen rendering v iOS", která proběhla na For-Mobile iOS v březnu 2013 v prostorách Microsoft ČR. Více o události For-Mobile: http://srazy.info/for-mobile/3293 #forMobileCZ

Citation preview

Page 1: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

ONscreen vs. OFFscreen rendering

Tomáš Jukin@Inza

Page 3: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

www.for-mobile.cz

@forMobileCZ #forMobileCZ

www.srazy.info/for-mobile

Březen 2013 - iOS

Page 5: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

www.iknow.eu/cvut/

Page 6: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

ONscreen vs. OFFscreen rendering

Tomáš Jukin@Inza

Page 7: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

iOS StackUIKitUIKit

Core AnimationCore Animation

OpenGL ES Core Graphics

GPU CPU

Page 8: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

iOS StackUIKitUIKit

Core AnimationCore Animation

OpenGL ES Core Graphics

GPU CPU

UIButtonUILabel

smooth transitions

2D/3D Graphics Quartz

Page 9: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

iOS StackUIKitUIKit

Core AnimationCore Animation

OpenGL ES Core Graphics

GPU CPU

UIButtonUILabel

smooth transitions

2D/3D Graphics Quartz

C languageC language

Page 10: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

iOS StackUIKitUIKit

Core AnimationCore Animation

OpenGL ES Core Graphics

GPU CPU

Hardware Acceleration

Page 11: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

GPU

ONscreen rendering

data obrazovka

Page 12: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

OFFscreen rendering

CPUdata

GPU

bitmapa

obrazovka

Page 13: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

Kdy se použije OFFscreen rendering?

• Core Graphics (když použiju cokoliv s CG*)• drawRect() metoda, i prázdná!• CALayer s shouldRasterize == YES.• CALayer s maskami (setMasksToBounds)

dynamickými stíny (setShadow*).• drawText včetně Core Text.• použití group opacity (UIViewGroupOpacity).

Page 14: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

Proč a kdy to vadí?

“Offscreen drawing affects performance when animation is involved”

Page 15: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

Jak to testovat?

Nebo to umí i Instruments...

Page 16: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

Case Study: UIButton

Předrenderované assety

CALayer

drawRect

Jak udělat grafiku pro UIButton?

Page 17: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

Předrenderované assetyGPU + předrenderované malé resizeable/tileable obrázky

ZENové, náročné na údržbu a realizaci

Page 18: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

CALayernutné OFFscreen průběhy pro maskování rohů

v Core Animation je defaultně zapnutá animace

Overkill

Page 19: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

drawRectdrawRect -> Core Graphics

touch -> setNeedsDisplay -> redraw

CPU & memory waste

hodně tlačítek v UI naráz = smrt

Page 20: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

Závěr? Máme tedy JEN assety?NE!

Je tu hybridní přístup:

Kód -> obrázek -> assetový postup pro všechny instance

Page 21: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

One more thing...

Page 22: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

GPU OFFscreen rendering!CPU OFFscreen rendering je synchronní s aplikací- je to zápis do bitmapy pixel by pixel

OFFscreen rendering může dělat i GPU! -> render server - asynchronně

Změna kontextu mezi ON a OFF je pro GPU ale strašně drahá!

Page 23: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

GPU OFFscreen rendering!důsledek: GPU může kreslit pomaleji než CPU! (flush + bariéra)

Proto je CoreGraphics přes CPU

[CALayer setShouldRasterize:] vs. CG - nutno testovat!

Page 24: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

Next

Page 25: ONscreen vs. OFFscreen rendering v iOS - For-Mobile 3/2013

Next ?

KVC, KVO a Cocoa Bindings

Document Oriented Programing v Cocoa

Advanced Cora Data