aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrSurfacePriv.h
blob: 5c98e3f7736358aaf5453633372a9730a6d2494b (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrSurfacePriv_DEFINED
#define GrSurfacePriv_DEFINED

#include "GrSurface.h"

/** Class that adds methods to GrSurface that are only intended for use internal to Skia.
    This class is purely a privileged window into GrSurface. It should never have additional data
    members or virtual methods.
    Non-static methods that are not trivial inlines should be spring-boarded (e.g. declared and
    implemented privately in GrSurface with a inline public method here). */
class GrSurfacePriv {
public:
    /** Helpers used in read/write pixels implementations. The parameters are adjusted so that the
        read/write respects the bounds of a surface. If the input *rowBytes is 0 it will be
        the tight row bytes (based on width and bpp) on output. */
    static bool AdjustReadPixelParams(int surfaceWidth,
                                      int surfaceHeight,
                                      size_t bpp,
                                      int* left, int* top, int* width, int* height,
                                      void** data,
                                      size_t* rowBytes);
    static bool AdjustWritePixelParams(int surfaceWidth,
                                      int surfaceHeight,
                                      size_t bpp,
                                      int* left, int* top, int* width, int* height,
                                      const void** data,
                                      size_t* rowBytes);

    bool hasPendingRead() const { return fSurface->hasPendingRead(); }
    bool hasPendingWrite() const { return fSurface->hasPendingWrite(); }
    bool hasPendingIO() const { return fSurface->hasPendingIO(); }
    bool hasUniqueRef() const { return fSurface->internalHasUniqueRef(); }

    GrInternalSurfaceFlags flags() const { return fSurface->fSurfaceFlags; }

    bool doesNotSupportMipMaps() const { return fSurface->doesNotSupportMipMaps(); }
    bool isGLTextureRectangleOrExternal() const {
        return fSurface->isGLTextureRectangleOrExternal();
    }
    // We only support the clamp wrap mode with gl rectangle or external textures.
    bool isClampOnly() const { return fSurface->isGLTextureRectangleOrExternal(); }

private:
    explicit GrSurfacePriv(GrSurface* surface) : fSurface(surface) {}
    GrSurfacePriv(const GrSurfacePriv&); // unimpl
    GrSurfacePriv& operator=(const GrSurfacePriv&); // unimpl

    // No taking addresses of this type.
    const GrSurfacePriv* operator&() const;
    GrSurfacePriv* operator&();

    GrSurface* fSurface;

    friend class GrSurface; // to construct/copy this type.
};

inline GrSurfacePriv GrSurface::surfacePriv() { return GrSurfacePriv(this); }

inline const GrSurfacePriv GrSurface::surfacePriv() const {
    return GrSurfacePriv(const_cast<GrSurface*>(this));
}

#endif