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 15 class GrImageInfo { 16 public: 17 GrImageInfo() = default; 18 GrImageInfo(const SkImageInfo & info)19 /* implicit */ GrImageInfo(const SkImageInfo& info) 20 : fColorInfo(info.colorInfo()), fDimensions(info.dimensions()) {} 21 GrImageInfo(GrColorType ct,SkAlphaType at,sk_sp<SkColorSpace> cs,int w,int h)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 GrImageInfo(GrColorType ct,SkAlphaType at,sk_sp<SkColorSpace> cs,const SkISize & dimensions)25 GrImageInfo(GrColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs, const SkISize& dimensions) 26 : fColorInfo(ct, at, std::move(cs)), fDimensions(dimensions) {} 27 GrImageInfo(const GrColorInfo & info,const SkISize & dimensions)28 GrImageInfo(const GrColorInfo& info, const SkISize& dimensions) 29 : fColorInfo(info), fDimensions(dimensions) {} 30 GrImageInfo(GrColorInfo && info,const SkISize & dimensions)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 makeColorType(GrColorType ct)39 GrImageInfo makeColorType(GrColorType ct) const { 40 return {this->colorInfo().makeColorType(ct), this->dimensions()}; 41 } 42 makeAlphaType(SkAlphaType at)43 GrImageInfo makeAlphaType(SkAlphaType at) const { 44 return {this->colorType(), at, this->refColorSpace(), this->width(), this->height()}; 45 } 46 makeColorSpace(sk_sp<SkColorSpace> cs)47 GrImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const { 48 return {this->colorType(), this->alphaType(), std::move(cs), this->width(), this->height()}; 49 } 50 makeDimensions(SkISize dimensions)51 GrImageInfo makeDimensions(SkISize dimensions) const { 52 return {this->colorType(), this->alphaType(), this->refColorSpace(), dimensions}; 53 } 54 makeWH(int width,int height)55 GrImageInfo makeWH(int width, int height) const { 56 return {this->colorType(), this->alphaType(), this->refColorSpace(), width, height}; 57 } 58 colorInfo()59 const GrColorInfo& colorInfo() const { return fColorInfo; } 60 colorType()61 GrColorType colorType() const { return fColorInfo.colorType(); } 62 alphaType()63 SkAlphaType alphaType() const { return fColorInfo.alphaType(); } 64 colorSpace()65 SkColorSpace* colorSpace() const { return fColorInfo.colorSpace(); } 66 refColorSpace()67 sk_sp<SkColorSpace> refColorSpace() const { return fColorInfo.refColorSpace(); } 68 dimensions()69 SkISize dimensions() const { return fDimensions; } 70 width()71 int width() const { return fDimensions.width(); } 72 height()73 int height() const { return fDimensions.height(); } 74 bpp()75 size_t bpp() const { return GrColorTypeBytesPerPixel(this->colorType()); } 76 minRowBytes()77 size_t minRowBytes() const { return this->bpp() * this->width(); } 78 isValid()79 bool isValid() const { return fColorInfo.isValid() && this->width() > 0 && this->height() > 0; } 80 81 private: 82 GrColorInfo fColorInfo = {}; 83 SkISize fDimensions; 84 }; 85 86 #endif 87