xref: /third_party/skia/src/gpu/GrImageInfo.h (revision cb93a386)
1/*
2 * Copyright 2019 Google LLC
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 GrImageInfo_DEFINED
9#define GrImageInfo_DEFINED
10
11#include "include/core/SkImageInfo.h"
12#include "include/private/GrTypesPriv.h"
13#include "src/gpu/GrColorInfo.h"
14
15class GrImageInfo {
16public:
17    GrImageInfo() = default;
18
19    /* implicit */ GrImageInfo(const SkImageInfo& info)
20            : fColorInfo(info.colorInfo()), fDimensions(info.dimensions()) {}
21
22    GrImageInfo(GrColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs, int w, int h)
23            : fColorInfo(ct, at, std::move(cs)), fDimensions{w,h} {}
24
25    GrImageInfo(GrColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs, const SkISize& dimensions)
26            : fColorInfo(ct, at, std::move(cs)), fDimensions(dimensions) {}
27
28    GrImageInfo(const GrColorInfo& info, const SkISize& dimensions)
29            : fColorInfo(info), fDimensions(dimensions) {}
30
31    GrImageInfo(GrColorInfo&& info, const SkISize& dimensions)
32            : fColorInfo(std::move(info)), fDimensions(dimensions) {}
33
34    GrImageInfo(const GrImageInfo&) = default;
35    GrImageInfo(GrImageInfo&&) = default;
36    GrImageInfo& operator=(const GrImageInfo&) = default;
37    GrImageInfo& operator=(GrImageInfo&&) = default;
38
39    GrImageInfo makeColorType(GrColorType ct) const {
40        return {this->colorInfo().makeColorType(ct), this->dimensions()};
41    }
42
43    GrImageInfo makeAlphaType(SkAlphaType at) const {
44        return {this->colorType(), at, this->refColorSpace(), this->width(), this->height()};
45    }
46
47    GrImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const {
48        return {this->colorType(), this->alphaType(), std::move(cs), this->width(), this->height()};
49    }
50
51    GrImageInfo makeDimensions(SkISize dimensions) const {
52        return {this->colorType(), this->alphaType(), this->refColorSpace(), dimensions};
53    }
54
55    GrImageInfo makeWH(int width, int height) const {
56        return {this->colorType(), this->alphaType(), this->refColorSpace(), width, height};
57    }
58
59    const GrColorInfo& colorInfo() const { return fColorInfo; }
60
61    GrColorType colorType() const { return fColorInfo.colorType(); }
62
63    SkAlphaType alphaType() const { return fColorInfo.alphaType(); }
64
65    SkColorSpace* colorSpace() const { return fColorInfo.colorSpace(); }
66
67    sk_sp<SkColorSpace> refColorSpace() const { return fColorInfo.refColorSpace(); }
68
69    SkISize dimensions() const { return fDimensions; }
70
71    int width() const { return fDimensions.width(); }
72
73    int height() const { return fDimensions.height(); }
74
75    size_t bpp() const { return GrColorTypeBytesPerPixel(this->colorType()); }
76
77    size_t minRowBytes() const { return this->bpp() * this->width(); }
78
79    bool isValid() const { return fColorInfo.isValid() && this->width() > 0 && this->height() > 0; }
80
81private:
82    GrColorInfo fColorInfo = {};
83    SkISize fDimensions;
84};
85
86#endif
87