• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "GrMtlCopyPipelineState.h"
9#include "GrMtlGpu.h"
10
11GrMtlCopyPipelineState* GrMtlCopyPipelineState::CreateCopyPipelineState(
12        GrMtlGpu* gpu,
13        MTLPixelFormat dstPixelFormat,
14        id<MTLFunction> vertexFunction,
15        id<MTLFunction> fragmentFunction,
16        MTLVertexDescriptor* vertexDescriptor) {
17
18    // Create pipeline state for copy as draw
19    MTLRenderPipelineDescriptor* pipelineDescriptor = [[MTLRenderPipelineDescriptor alloc] init];
20    pipelineDescriptor.vertexFunction = vertexFunction;
21    pipelineDescriptor.fragmentFunction = fragmentFunction;
22    pipelineDescriptor.vertexDescriptor = vertexDescriptor;
23    pipelineDescriptor.colorAttachments[0].pixelFormat = dstPixelFormat;
24
25    NSError* error = nil;
26    id<MTLRenderPipelineState> pipelineState =
27            [gpu->device() newRenderPipelineStateWithDescriptor: pipelineDescriptor
28                                                          error: &error];
29    if (error) {
30        SkDebugf("Error creating pipeline: %s\n",
31                 [[error localizedDescription] cStringUsingEncoding: NSASCIIStringEncoding]);
32        return nil;
33    }
34
35    SkASSERT(pipelineState);
36    return new GrMtlCopyPipelineState(pipelineState, dstPixelFormat);
37}
38