blob: 47bd44f4ef1ba00d5ec12bbe3fff974da582e60c [file] [log] [blame]
bsalomonafbf2d62014-09-30 12:18:44 -07001/*
2 * Copyright 2014 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 GrSurfacePriv_DEFINED
9#define GrSurfacePriv_DEFINED
10
11#include "GrSurface.h"
12
13/** Class that adds methods to GrSurface that are only intended for use internal to Skia.
14 This class is purely a privileged window into GrSurface. It should never have additional data
15 members or virtual methods.
16 Non-static methods that are not trivial inlines should be spring-boarded (e.g. declared and
17 implemented privately in GrSurface with a inline public method here). */
18class GrSurfacePriv {
19public:
20 /**
bsalomon74f681d2015-06-23 14:38:48 -070021 * Derive a SkImageInfo from the surface's descriptor. The caller must provide the alpha type as
22 * GrSurface has no equivalent.
bsalomonafbf2d62014-09-30 12:18:44 -070023 */
bsalomon74f681d2015-06-23 14:38:48 -070024 SkImageInfo info(SkAlphaType alphaType) const { return fSurface->info(alphaType); }
bsalomonafbf2d62014-09-30 12:18:44 -070025
26 /**
bsalomonafbf2d62014-09-30 12:18:44 -070027 * Write the contents of the surface to a PNG. Returns true if successful.
28 * @param filename Full path to desired file
29 */
30 bool savePixels(const char* filename) { return fSurface->savePixels(filename); }
31
32 bool hasPendingRead() const { return fSurface->hasPendingRead(); }
33 bool hasPendingWrite() const { return fSurface->hasPendingWrite(); }
34 bool hasPendingIO() const { return fSurface->hasPendingIO(); }
35
36private:
bsalomon6bc1b5f2015-02-23 09:06:38 -080037 explicit GrSurfacePriv(GrSurface* surface) : fSurface(surface) {}
38 GrSurfacePriv(const GrSurfacePriv&); // unimpl
39 GrSurfacePriv& operator=(const GrSurfacePriv&); // unimpl
bsalomonafbf2d62014-09-30 12:18:44 -070040
41 // No taking addresses of this type.
42 const GrSurfacePriv* operator&() const;
43 GrSurfacePriv* operator&();
44
45 GrSurface* fSurface;
46
47 friend class GrSurface; // to construct/copy this type.
48};
49
50inline GrSurfacePriv GrSurface::surfacePriv() { return GrSurfacePriv(this); }
51
52inline const GrSurfacePriv GrSurface::surfacePriv() const {
53 return GrSurfacePriv(const_cast<GrSurface*>(this));
54}
55
56#endif