Make Metal render loop more stable

Bug: skia:8737
Change-Id: Ib825e5f0c9502692cbecc60fbb68d0d1a2bc635f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/208672
Auto-Submit: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Jim Van Verth 2019-04-17 09:44:32 -04:00 committed by Skia Commit-Bot
parent 629ca1d5c7
commit 7a7a97d3c7
2 changed files with 12 additions and 4 deletions

View File

@ -189,7 +189,9 @@ protected:
bool onAnimate(const AnimTimer& timer) override {
SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360));
fAnimatingDrawable->setSweep(angle);
if (fAnimatingDrawable) {
fAnimatingDrawable->setSweep(angle);
}
return true;
}

View File

@ -65,8 +65,16 @@ void MetalWindowContext::destroyContext() {
sk_sp<SkSurface> MetalWindowContext::getBackbufferSurface() {
sk_sp<SkSurface> surface;
if (fContext) {
// Block to ensure we don't try to render to a frame that hasn't finished presenting
dispatch_semaphore_wait(fInFlightSemaphore, DISPATCH_TIME_FOREVER);
// TODO: Apple recommends grabbing the drawable (which we're implicitly doing here)
// for as little time as possible. I'm not sure it matters for our test apps, but
// you can get better throughput by doing any offscreen renders, texture uploads, or
// other non-dependant tasks first before grabbing the drawable.
GrMtlTextureInfo fbInfo;
fbInfo.fTexture = [[fMTKView currentDrawable] texture];
MTLRenderPassDescriptor* descriptor = fMTKView.currentRenderPassDescriptor;
fbInfo.fTexture = [[[descriptor colorAttachments] objectAtIndexedSubscript:0] texture];
GrBackendRenderTarget backendRT(fWidth,
fHeight,
@ -84,8 +92,6 @@ sk_sp<SkSurface> MetalWindowContext::getBackbufferSurface() {
}
void MetalWindowContext::swapBuffers() {
// Block to ensure we don't try to render to a frame that hasn't finished presenting
dispatch_semaphore_wait(fInFlightSemaphore, DISPATCH_TIME_FOREVER);
id<MTLCommandBuffer> commandBuffer = [fQueue commandBuffer];
commandBuffer.label = @"Present";