blob: 7899397e1c7f3a48e0ae4da865438ba5ac9dfe86 [file] [log] [blame]
Timothy Liange30739a2018-07-31 10:51:17 -04001/*
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#ifndef GrMtlCopyManager_DEFINED
9#define GrMtlCopyManager_DEFINED
10
11#include "GrTypes.h"
12
13#import <metal/metal.h>
14
15class GrMtlCopyPipelineState;
16class GrMtlGpu;
17class GrSurface;
18struct SkIPoint;
19struct SkIRect;
20
21class GrMtlCopyManager {
22public:
23 GrMtlCopyManager(GrMtlGpu* gpu) : fGpu(gpu) {}
24
25 bool copySurfaceAsDraw(GrSurface* dst, GrSurfaceOrigin dstOrigin,
26 GrSurface* src, GrSurfaceOrigin srcOrigin,
27 const SkIRect& srcRect, const SkIPoint& dstPoint,
28 bool canDiscardOutsideDstRect);
29
30 static bool IsCompatible(const GrMtlCopyPipelineState*, MTLPixelFormat dstPixelFormat);
31
32private:
33 enum BufferIndex {
34 kUniform_BufferIndex,
35 kAttribute_BufferIndex,
36 };
37
38 void createCopyProgramBuffer();
39 void createCopyProgramShaders();
40 void createCopyProgramVertexDescriptor();
41
42 void createCopyProgram();
43
44 id<MTLSamplerState> fSamplerState;
45 id<MTLBuffer> fVertexAttributeBuffer;
46 id<MTLFunction> fVertexFunction;
47 id<MTLFunction> fFragmentFunction;
48 MTLVertexDescriptor* fVertexDescriptor;
49
50 GrMtlGpu* fGpu;
51};
52
53#endif