remove unneeded friends/includes in SkPaint.h

Bug: skia:
Change-Id: Ica9f10cdb67322eb43ec38b6549146350fa5dcd9
Reviewed-on: https://skia-review.googlesource.com/c/188630
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Auto-Submit: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2019-02-01 14:00:34 -05:00 committed by Skia Commit-Bot
parent 9a2bb09202
commit ec7278e703
11 changed files with 82 additions and 119 deletions

View File

@ -123,6 +123,7 @@ skia_core_sources = [
"$_src/core/SkFontMgr.cpp",
"$_src/core/SkFontDescriptor.cpp",
"$_src/core/SkFontDescriptor.h",
"$_src/core/SkFontPriv.cpp",
"$_src/core/SkFontStream.cpp",
"$_src/core/SkFontStream.h",
"$_src/core/SkFuzzLogging.h",
@ -193,7 +194,6 @@ skia_core_sources = [
"$_src/core/SkOSFile.h",
"$_src/core/SkOverdrawCanvas.cpp",
"$_src/core/SkPaint.cpp",
"$_src/core/SkPaint_text.cpp",
"$_src/core/SkPaintDefaults.h",
"$_src/core/SkPaintPriv.cpp",
"$_src/core/SkPaintPriv.h",

View File

@ -22,16 +22,10 @@
#include "SkBlendMode.h"
#include "SkColor.h"
#include "SkFilterQuality.h"
#include "SkMatrix.h"
#include "SkRefCnt.h"
// TODO: remove after updating android sites to IWYU
#include "SkFontMetrics.h"
class GrTextBlob;
class SkColorFilter;
class SkColorSpace;
class SkData;
class SkDrawLooper;
struct SkRect;
class SkImageFilter;
@ -40,8 +34,10 @@ class SkPath;
class SkPathEffect;
struct SkPoint;
class SkShader;
// TODO: remove after updating android sites to IWYU
#include "SkFontMetrics.h"
class SkSurfaceProps;
class SkTextBlob;
/** \class SkPaint
SkPaint controls options applied when drawing. SkPaint collects all
@ -692,29 +688,6 @@ private:
} fBitfields;
uint32_t fBitfieldsUInt;
};
/*
* The luminance color is used to determine which Gamma Canonical color to map to. This is
* really only used by backends which want to cache glyph masks, and need some way to know if
* they need to generate new masks based off a given color.
*/
SkColor computeLuminanceColor() const;
friend class GrTextBlob;
friend class GrTextContext;
friend class GrGLPathRendering;
friend class GrPathRendering;
friend class SkAutoGlyphCacheNoGamma;
friend class SkCanonicalizePaint;
friend class SkCanvas;
friend class SkDraw;
friend class SkGlyphRunListPainter;
friend class SkPaintPriv;
friend class SkPicturePlayback;
friend class SkPDFDevice;
friend class SkScalerContext;
friend class SkTextBaseIter;
friend class SkTextBlobCacheDiffCanvas;
};
#endif

36
src/core/SkFontPriv.cpp Normal file
View File

@ -0,0 +1,36 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkFontPriv.h"
#include "SkGraphics.h"
#include "SkMatrix.h"
static SkScalar mag2(SkScalar x, SkScalar y) {
return x * x + y * y;
}
static bool tooBig(const SkMatrix& m, SkScalar ma2max) {
return mag2(m[SkMatrix::kMScaleX], m[SkMatrix::kMSkewY]) > ma2max
||
mag2(m[SkMatrix::kMSkewX], m[SkMatrix::kMScaleY]) > ma2max;
}
bool SkFontPriv::TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM, SkScalar maxLimit) {
SkASSERT(!ctm.hasPerspective());
SkASSERT(!textM.hasPerspective());
SkMatrix matrix;
matrix.setConcat(ctm, textM);
return tooBig(matrix, MaxCacheSize2(maxLimit));
}
SkScalar SkFontPriv::MaxCacheSize2(SkScalar maxLimit) {
// we have a self-imposed maximum, just for memory-usage sanity
const int limit = SkMin32(SkGraphics::GetFontCachePointSizeLimit(), maxLimit);
const SkScalar maxSize = SkIntToScalar(limit);
return maxSize * maxSize;
}

View File

@ -20,6 +20,7 @@
class SkBaseDevice;
class SkGlyph;
class SkTextBlob;
class SkGlyphRun {
public:

View File

@ -731,7 +731,8 @@ void GrTextBlob::generateFromGlyphRunList(GrStrikeCache* glyphCache,
SkPoint origin = glyphRunList.origin();
const SkPaint& runPaint = glyphRunList.paint();
this->initReusableBlob(runPaint.computeLuminanceColor(), viewMatrix, origin.x(), origin.y());
this->initReusableBlob(SkPaintPriv::ComputeLuminanceColor(runPaint), viewMatrix,
origin.x(), origin.y());
for (const auto& glyphRun : glyphRunList) {
const SkFont& runFont = glyphRun.font();

View File

@ -58,3 +58,29 @@ bool SkPaintPriv::ShouldDither(const SkPaint& p, SkColorType dstCT) {
return p.getImageFilter() || p.getMaskFilter()
|| !p.getShader() || !as_SB(p.getShader())->isConstant();
}
// return true if the paint is just a single color (i.e. not a shader). If its
// a shader, then we can't compute a const luminance for it :(
static bool just_a_color(const SkPaint& paint, SkColor* color) {
SkColor c = paint.getColor();
const auto* shader = as_SB(paint.getShader());
if (shader && !shader->asLuminanceColor(&c)) {
return false;
}
if (paint.getColorFilter()) {
c = paint.getColorFilter()->filterColor(c);
}
if (color) {
*color = c;
}
return true;
}
SkColor SkPaintPriv::ComputeLuminanceColor(const SkPaint& paint) {
SkColor c;
if (!just_a_color(paint, &c)) {
c = SkColorSetRGB(0x7F, 0x80, 0x7F);
}
return c;
}

View File

@ -38,6 +38,13 @@ public:
static bool ShouldDither(const SkPaint&, SkColorType);
/*
* The luminance color is used to determine which Gamma Canonical color to map to. This is
* really only used by backends which want to cache glyph masks, and need some way to know if
* they need to generate new masks based off a given color.
*/
static SkColor ComputeLuminanceColor(const SkPaint&);
/** Serializes SkPaint into a buffer. A companion unflatten() call
can reconstitute the paint at a later time.

View File

@ -1,83 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkPaint.h"
#include "SkColorFilter.h"
#include "SkDraw.h"
#include "SkFontDescriptor.h"
#include "SkFontPriv.h"
#include "SkGraphics.h"
#include "SkPaintDefaults.h"
#include "SkPaintPriv.h"
#include "SkPathEffect.h"
#include "SkSafeRange.h"
#include "SkScalar.h"
#include "SkScalerContext.h"
#include "SkShader.h"
#include "SkShaderBase.h"
#include "SkStrike.h"
#include "SkStringUtils.h"
#include "SkTLazy.h"
#include "SkTextBlob.h"
#include "SkTextBlobPriv.h"
#include "SkTextFormatParams.h"
#include "SkTo.h"
#include "SkTypeface.h"
///////////////////////////////////////////////////////////////////////////////
static SkScalar mag2(SkScalar x, SkScalar y) {
return x * x + y * y;
}
static bool tooBig(const SkMatrix& m, SkScalar ma2max) {
return mag2(m[SkMatrix::kMScaleX], m[SkMatrix::kMSkewY]) > ma2max
||
mag2(m[SkMatrix::kMSkewX], m[SkMatrix::kMScaleY]) > ma2max;
}
bool SkFontPriv::TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM, SkScalar maxLimit) {
SkASSERT(!ctm.hasPerspective());
SkASSERT(!textM.hasPerspective());
SkMatrix matrix;
matrix.setConcat(ctm, textM);
return tooBig(matrix, MaxCacheSize2(maxLimit));
}
SkScalar SkFontPriv::MaxCacheSize2(SkScalar maxLimit) {
// we have a self-imposed maximum, just for memory-usage sanity
const int limit = SkMin32(SkGraphics::GetFontCachePointSizeLimit(), maxLimit);
const SkScalar maxSize = SkIntToScalar(limit);
return maxSize * maxSize;
}
// return true if the paint is just a single color (i.e. not a shader). If its
// a shader, then we can't compute a const luminance for it :(
static bool just_a_color(const SkPaint& paint, SkColor* color) {
SkColor c = paint.getColor();
const auto* shader = as_SB(paint.getShader());
if (shader && !shader->asLuminanceColor(&c)) {
return false;
}
if (paint.getColorFilter()) {
c = paint.getColorFilter()->filterColor(c);
}
if (color) {
*color = c;
}
return true;
}
SkColor SkPaint::computeLuminanceColor() const {
SkColor c;
if (!just_a_color(*this, &c)) {
c = SkColorSetRGB(0x7F, 0x80, 0x7F);
}
return c;
}

View File

@ -1015,7 +1015,7 @@ void SkScalerContext::MakeRecAndEffects(const SkFont& font, const SkPaint& paint
// these modify fFlags, so do them after assigning fFlags
rec->setHinting(computeHinting(font));
rec->setLuminanceColor(paint.computeLuminanceColor());
rec->setLuminanceColor(SkPaintPriv::ComputeLuminanceColor(paint));
// For now always set the paint gamma equal to the device gamma.
// The math in SkMaskGamma can handle them being different,

View File

@ -14,6 +14,7 @@
#include "GrTextTarget.h"
#include "SkColorFilter.h"
#include "SkMaskFilterBase.h"
#include "SkPaintPriv.h"
#include "ops/GrAtlasTextOp.h"
#include <new>
@ -81,7 +82,7 @@ bool GrTextBlob::mustRegenerate(const SkPaint& paint, bool anyRunHasSubpixelPosi
// to regenerate the blob on any color change
// We use the grPaint to get any color filter effects
if (fKey.fCanonicalColor == SK_ColorTRANSPARENT &&
fLuminanceColor != paint.computeLuminanceColor()) {
fLuminanceColor != SkPaintPriv::ComputeLuminanceColor(paint)) {
return true;
}
@ -176,7 +177,8 @@ inline std::unique_ptr<GrAtlasTextOp> GrTextBlob::makeOp(
// TODO: Can we be even smarter based on the dest transfer function?
op = GrAtlasTextOp::MakeDistanceField(
target->getContext(), std::move(grPaint), glyphCount, distanceAdjustTable,
target->colorSpaceInfo().isLinearlyBlended(), paint.computeLuminanceColor(),
target->colorSpaceInfo().isLinearlyBlended(),
SkPaintPriv::ComputeLuminanceColor(paint),
props, info.isAntiAliased(), info.hasUseLCDText());
} else {
op = GrAtlasTextOp::MakeBitmap(target->getContext(), std::move(grPaint), format, glyphCount,

View File

@ -50,7 +50,7 @@ std::unique_ptr<GrTextContext> GrTextContext::Make(const Options& options) {
}
SkColor GrTextContext::ComputeCanonicalColor(const SkPaint& paint, bool lcd) {
SkColor canonicalColor = paint.computeLuminanceColor();
SkColor canonicalColor = SkPaintPriv::ComputeLuminanceColor(paint);
if (lcd) {
// This is the correct computation, but there are tons of cases where LCD can be overridden.
// For now we just regenerate if any run in a textblob has LCD.