Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Multithreaded Drawing by Eric Lanz
Search
Triangle Cocoa
August 23, 2012
Programming
240
3
Share
Multithreaded Drawing by Eric Lanz
Eric discusses multithreaded drawing with Core Graphics at CocoaHeads August in Raleigh
Triangle Cocoa
August 23, 2012
More Decks by Triangle Cocoa
See All by Triangle Cocoa
App Store Secrets by Lawrence Ingraham
trianglecocoa
1
330
iPhone 5 and You! by Ameir Al-Zoubi
trianglecocoa
0
200
Grand Central Dispatch by Jody Hagins
trianglecocoa
2
510
Instruments: Leaks by Trevor Brown
trianglecocoa
5
170
Foundation Collections by Kevin Conner
trianglecocoa
3
280
Unburdened ViewControllers by Jay Thrash
trianglecocoa
9
11k
Automated Acceptance Testing by Josh Johnson
trianglecocoa
4
200
Understanding UIResponder by Dirk Smith
trianglecocoa
5
370
Taming Xcode by Jay Thrash
trianglecocoa
3
170
Other Decks in Programming
See All in Programming
開発体験を左右するライブラリの API 設計 - GraphQL スキーマ構築ライブラリから考える #tskaigi
izumin5210
2
240
AIエージェントの隔離技術の徹底比較
kawayu
0
280
新規プロダクトを高速で生み出すハーネスエンジニアリング
seanchas116
3
210
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
2
360
KMP × Kotlin 2.3 - How Android Got Slower While iOS Builds Improved by 47%
rio432
0
230
Cloudflare で始める Data Platform
ta93abe
0
200
RailsTokyo 2026#4: AI様があれば、 Hotwireの弱点は消えるか?
naofumi
3
450
Agentic UI beyond Chats Architecture Patterns & Open Standards @ngMunich 05/2026
manfredsteyer
PRO
0
110
ビジネスモデルから紐解く、AI+型駆動開発
hirokiomote
2
520
プロパティの順序で型推論が壊れる!? TypeScript6.0の修正からContext-Sensitivityの仕組みを追う
bicstone
2
140
Transactional Change Stream Processing With Debezium and Apache Flink
gunnarmorling
1
100
Import assertionsが消えた日~ECMAScriptの仕様はどう決まり、なぜ覆るのか~
bicstone
2
190
Featured
See All Featured
Building Applications with DynamoDB
mza
96
7k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
300
30 Presentation Tips
portentint
PRO
1
300
GitHub's CSS Performance
jonrohan
1033
470k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
70
39k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
200
First, design no harm
axbom
PRO
2
1.2k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
330
Ruling the World: When Life Gets Gamed
codingconduct
0
230
Building AI with AI
inesmontani
PRO
1
1k
Transcript
Multithreaded Drawing with core graphics Eric.Lanz @OrgBook.com
What you should do • Get an artist to make
all your graphics up front • Use tools like GraphicsMagick, OptiPng and PVRTC (OpenGL) • Use built in cache mechanisms • UIKit -> Core Animation -> OpenGL
What if you can’t • User defined image data at
run-time • Continuous animation responding to user interaction • Too much image data to pre-process and ship with the app
Know when to draw View Controllers Drawables Drawables Drawables Drawables
User Input • User triggers redraw • View controllers determine layout • Don’t directly call draw on a drawable
Synchronous Data API View Controllers Drawables Drawables Drawables Drawables Data
Controller User Input Core Data No Local Copy? Return a fake object while you wait for the API
Asynchronous Draw API View Controllers Drawables Drawables Drawables Drawables Data
Controller User Input Core Data Targeted NSNotifications: @”ObjectUpdate_XYZ”
Drawing Pipeline Render Controller Drawable • Drawable asks to be
drawn using some template • Entire operation contained in a block
Direct Draw Controller Drawable Direct Template Core Graphics Cache 1
Dispatch Serial Queue Draw Controller Drawable Dispatch_Serial Template Core Graphics
Cache 2 Create a serial dispatch queue, this will run one task at a time on a worker thread.
Dispatch Global Queue Draw Controller Drawable Dispatch_Global Template Core Graphics
Cache 3 Use the Global dispatch queue, this runs tasks concurrently on multiple worker threads.
All Together Now Draw Controller Drawable Dispatch_Global Template Core Graphics
Cache 3 Dispatch_Serial Template Core Graphics Cache 2 Direct Template Core Graphics Cache 1
Dispatch Serial Queue UIGraphicsPushContext(c); [[UIColor blackColor] setFill]; [@"Sample" drawInRect:CGRectMake(0, 4,
width, height) withFont:[UIFont fontWithName:@"Helvetica" size:fontSize] lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentCenter]; UIGraphicsPopContext(); CGContextRelease(c); CGColorSpaceRelease(genericRGBColorspace); GLubyte *imageData = (GLubyte *) calloc(1, width * height * 4); CGColorSpaceRef genericRGBColorspace = CGColorSpaceCreateDeviceRGB(); CGContextRef c = CGBitmapContextCreate(imageData, width, height, 8, width * 4, genericRGBColorspace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
Dispatch Global CGContextScaleCTM(c, 1.0, -1.0); CGContextTranslateCTM(c, 0, -height); CGMutablePathRef circlePath
= CGPathCreateMutable(); CGPathAddEllipseInRect( circlePath , NULL , CGRectMake(1, 1, width-2, height-2) ); CGContextAddPath(c, circlePath); CGContextClip(c); UIImage * personImage = [UIImage imageWithContentsOfFile:path]; CGContextDrawImage(c, CGRectMake(0, 0, width, height), personImage.CGImage); CGContextRelease(c); CGColorSpaceRelease(genericRGBColorspace); GLubyte *imageData = (GLubyte *) calloc(1, width * height * 4); CGColorSpaceRef genericRGBColorspace = CGColorSpaceCreateDeviceRGB(); CGContextRef c = CGBitmapContextCreate(imageData, width, height, 8, width * 4, genericRGBColorspace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
Final Thoughts • No architecture is perfect • Maintain balance
• Make it easy to tweak • Don’t get lost in the details
Questions