非主线程允许使用UIKit,Core Graphics,Core Animation,OpenGL的哪些部分? [英] Which parts of UIKit, Core Graphics, Core Animation, OpenGL are allowed on non main-thread?

查看:175
本文介绍了非主线程允许使用UIKit,Core Graphics,Core Animation,OpenGL的哪些部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基于OpenGL-ES 1.1的应用程序中,我使用CALayer s作为OpenGL纹理的源.这些CALayerCGImage和通过CoreGraphics呈现的文本组成.另一个OpenGL纹理来源是使用-[CALAyer renderInContext:]UIGraphicsGetImageFromCurrentImageContext拍摄的UIView的屏幕截图.目前,我完全在主线程上运行.

In my OpenGL-ES 1.1 based app, I'm using CALayers as a source for OpenGL textures. Those CALayers comprise of CGImages and text rendered through CoreGraphics. Another OpenGL texture source is a screenshot of a UIView taken using -[CALAyer renderInContext:] and UIGraphicsGetImageFromCurrentImageContext. Currently, I'm running completely on the main thread.

后一种情况特别糟糕,因为它会在创建UIView及其屏幕截图的整个过程中停止OpenGL渲染.

The latter case in particular is pretty bad because it halts the OpenGL rendering for the whole time it takes to create the UIView and its screenshot.

现在,我正在考虑将OpenGL代码移动到单独的线程中,以期解决此阻塞问题.理想情况下,屏幕截图应采用与OpenGL渲染不同的线程(如果需要,可以在主线程上)拍摄.

Now I'm considering to move the OpenGL code into a separate thread hoping to get around this blocking. Ideally, the screenshot would be taken on a different thread (main thread if needed) than the OpenGL rendering.

我无法在文档中找到有关在主线程上运行什么以及不运行哪些内容的完整介绍.我在

I wasn't able to find a complete coverage in the documentation about what requires running on the main thread and what not. I found some comments in the iOS 4 release notes, and some comments in specific UIKit methods but I'm missing the complete picture.

代码在iOS 4.x或更高版本上运行.

The code runs on iOS 4.x or higher.

推荐答案

只要不尝试同时从另一个线程访问OpenGL上下文,就可以在后台线程上使用OpenGL ES进行绘制. .有关更多信息,请参见Apple的技术问答QA1612 .这个.

You can do drawing with OpenGL ES on a background thread, as long as you do don't try to access the OpenGL context from another thread at the same time. See Apple's Technical Q&A QA1612 for a little more on this.

从后台线程更新CALayer内容时遇到了许多问题,因此我需要对主线程上的图层进行任何处理.无论如何,Core Animation会在后台线程上触发其动画.

I have run into a number of issues with updating CALayer content from a background thread, so I do any work with layers on the main thread. Core Animation fires off its animations on a background thread, anyway.

我从不从后台线程更新与UIKit相关的任何内容,但是UIKit中某些绘图方面在4.0中成为线程安全的.大卫·邓肯(David Duncan)在此处进行评论上下文现在是线程安全的.

I'd never updated anything related to UIKit from a background thread, but some aspects of drawing in UIKit were made threadsafe in 4.0. David Duncan comments here that drawing to a context is now threadsafe.

在您的情况下,在后台线程上运行OpenGL ES渲染不会出现问题(也许在GCD中使用串行分派队列来防止一次从多个线程访问上下文)然后执行图像抓住另一个.

In your case, I wouldn't see a problem with running the OpenGL ES rendering on a background thread (perhaps using a serial dispatch queue in GCD to prevent access to the context from multiple threads at once) and then doing your image grabs on another.

这篇关于非主线程允许使用UIKit,Core Graphics,Core Animation,OpenGL的哪些部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆