aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/mtl/GrMtlCopyManager.h
blob: 7899397e1c7f3a48e0ae4da865438ba5ac9dfe86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Copyright 2018 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
*/

#ifndef GrMtlCopyManager_DEFINED
#define GrMtlCopyManager_DEFINED

#include "GrTypes.h"

#import <metal/metal.h>

class GrMtlCopyPipelineState;
class GrMtlGpu;
class GrSurface;
struct SkIPoint;
struct SkIRect;

class GrMtlCopyManager {
public:
    GrMtlCopyManager(GrMtlGpu* gpu) : fGpu(gpu) {}

    bool copySurfaceAsDraw(GrSurface* dst, GrSurfaceOrigin dstOrigin,
                           GrSurface* src, GrSurfaceOrigin srcOrigin,
                           const SkIRect& srcRect, const SkIPoint& dstPoint,
                           bool canDiscardOutsideDstRect);

    static bool IsCompatible(const GrMtlCopyPipelineState*, MTLPixelFormat dstPixelFormat);

private:
    enum BufferIndex {
        kUniform_BufferIndex,
        kAttribute_BufferIndex,
    };

    void createCopyProgramBuffer();
    void createCopyProgramShaders();
    void createCopyProgramVertexDescriptor();

    void createCopyProgram();

    id<MTLSamplerState>  fSamplerState;
    id<MTLBuffer>        fVertexAttributeBuffer;
    id<MTLFunction>      fVertexFunction;
    id<MTLFunction>      fFragmentFunction;
    MTLVertexDescriptor* fVertexDescriptor;

    GrMtlGpu* fGpu;
};

#endif