skia2/include/core/SkSurfaceProps.h
brianosman 898235c486 SkSurfaceProps now has a gamma-correct ("AllowSRGBInputs") flag. That's propagated in a few places so that the backend can do the right thing for L32 vs S32 mode.
Also added SkSurfaceProps to SkSpecialImage, so that Image -> Surface conversion can preserve the desired behavior during filtering.

Many small changes, including a bunch of comments about places where we may be losing information right now. My approach was to ensure that if anything fails, it will always fall back to "legacy" mode - gamma-correctness is opt-in, so I'll just have to feed things through as missing cases are exposed.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1838953007

Review URL: https://codereview.chromium.org/1845283003
2016-04-06 07:38:23 -07:00

99 lines
3.3 KiB
C++

/*
* 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 SkSurfaceProps_DEFINED
#define SkSurfaceProps_DEFINED
#include "SkTypes.h"
/**
* Description of how the LCD strips are arranged for each pixel. If this is unknown, or the
* pixels are meant to be "portable" and/or transformed before showing (e.g. rotated, scaled)
* then use kUnknown_SkPixelGeometry.
*/
enum SkPixelGeometry {
kUnknown_SkPixelGeometry,
kRGB_H_SkPixelGeometry,
kBGR_H_SkPixelGeometry,
kRGB_V_SkPixelGeometry,
kBGR_V_SkPixelGeometry,
};
// Returns true iff geo is a known geometry and is RGB.
static inline bool SkPixelGeometryIsRGB(SkPixelGeometry geo) {
return kRGB_H_SkPixelGeometry == geo || kRGB_V_SkPixelGeometry == geo;
}
// Returns true iff geo is a known geometry and is BGR.
static inline bool SkPixelGeometryIsBGR(SkPixelGeometry geo) {
return kBGR_H_SkPixelGeometry == geo || kBGR_V_SkPixelGeometry == geo;
}
// Returns true iff geo is a known geometry and is horizontal.
static inline bool SkPixelGeometryIsH(SkPixelGeometry geo) {
return kRGB_H_SkPixelGeometry == geo || kBGR_H_SkPixelGeometry == geo;
}
// Returns true iff geo is a known geometry and is vertical.
static inline bool SkPixelGeometryIsV(SkPixelGeometry geo) {
return kRGB_V_SkPixelGeometry == geo || kBGR_V_SkPixelGeometry == geo;
}
/**
* Describes properties and constraints of a given SkSurface. The rendering engine can parse these
* during drawing, and can sometimes optimize its performance (e.g. disabling an expensive
* feature).
*/
class SK_API SkSurfaceProps {
public:
enum Flags {
kDisallowAntiAlias_Flag = 1 << 0,
kDisallowDither_Flag = 1 << 1,
kUseDeviceIndependentFonts_Flag = 1 << 2,
/**
* This flag causes sRGB inputs to the color pipeline (images and other sRGB-tagged
* colors) to be gamma-corrected (converted to linear) before use. Without this flag,
* texture scaling and filtering is not gamma correct, preserving the behavior of Skia
* up through 2015.
*
* It is recommended to enable this flag when rendering to an sRGB or floating point
* surface.
*/
kAllowSRGBInputs_Flag = 1 << 3,
};
/** Deprecated alias used by Chromium. Will be removed. */
static const Flags kUseDistanceFieldFonts_Flag = kUseDeviceIndependentFonts_Flag;
SkSurfaceProps(uint32_t flags, SkPixelGeometry);
enum InitType {
kLegacyFontHost_InitType
};
SkSurfaceProps(InitType);
SkSurfaceProps(uint32_t flags, InitType);
SkSurfaceProps(const SkSurfaceProps& other);
uint32_t flags() const { return fFlags; }
SkPixelGeometry pixelGeometry() const { return fPixelGeometry; }
bool isDisallowAA() const { return SkToBool(fFlags & kDisallowAntiAlias_Flag); }
bool isDisallowDither() const { return SkToBool(fFlags & kDisallowDither_Flag); }
bool isUseDeviceIndependentFonts() const {
return SkToBool(fFlags & kUseDeviceIndependentFonts_Flag);
}
bool allowSRGBInputs() const { return SkToBool(fFlags & kAllowSRGBInputs_Flag); }
private:
SkSurfaceProps();
uint32_t fFlags;
SkPixelGeometry fPixelGeometry;
};
#endif