add (temp) SkFontLCDConfig class to hold LCD getters/setters. This will allow

us to make SkFontHost.h private (once webkit switches to the SkFontLCDConfig api)

Stage 2 is to either move this code into chrome/webkit, or change the callers to
perform their own globals management.
Review URL: https://codereview.chromium.org/12623011

git-svn-id: http://skia.googlecode.com/svn/trunk@8107 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2013-03-12 15:41:18 +00:00
parent b8f9610ac6
commit 1a64a54b27
4 changed files with 103 additions and 29 deletions

View File

@ -10,8 +10,8 @@
#define SK_GAMMA_EXPONENT (0.0f)
#endif
//TODO: get everyone to stop using SkFontHost::SetSubpixel* and remove this import.
#include "SkFontHost.h"
//TODO: get everyone to stop using SkFontLCDConfig::SetSubpixel* and remove this import.
#include "SkFontLCDConfig.h"
struct SkDeviceProperties {
struct Geometry {
@ -60,25 +60,25 @@ struct SkDeviceProperties {
}
private:
//TODO: get everyone to stop using SkFontHost::SetSubpixel* and replace these calls with constants.
static Orientation fromOldOrientation(SkFontHost::LCDOrientation orientation) {
//TODO: get everyone to stop using SkFontLCDConfig::SetSubpixel* and replace these calls with constants.
static Orientation fromOldOrientation(SkFontLCDConfig::LCDOrientation orientation) {
switch (orientation) {
case SkFontHost::kHorizontal_LCDOrientation: return kHorizontal_Orientation;
case SkFontHost::kVertical_LCDOrientation: return kVertical_Orientation;
case SkFontLCDConfig::kHorizontal_LCDOrientation: return kHorizontal_Orientation;
case SkFontLCDConfig::kVertical_LCDOrientation: return kVertical_Orientation;
default: return kUnknown_Orientation;
}
}
static Layout fromOldLayout(SkFontHost::LCDOrder order) {
static Layout fromOldLayout(SkFontLCDConfig::LCDOrder order) {
switch (order) {
case SkFontHost::kRGB_LCDOrder: return kRGB_Layout;
case SkFontHost::kBGR_LCDOrder: return kBGR_Layout;
case SkFontLCDConfig::kRGB_LCDOrder: return kRGB_Layout;
case SkFontLCDConfig::kBGR_LCDOrder: return kBGR_Layout;
default: return kUnknown_Layout;
}
}
public:
static Geometry MakeDefault() {
Orientation orientation = fromOldOrientation(SkFontHost::GetSubpixelOrientation()); //kHorizontal_Orientation
Layout layout = fromOldLayout(SkFontHost::GetSubpixelOrder()); //kRGB_Layout
Orientation orientation = fromOldOrientation(SkFontLCDConfig::GetSubpixelOrientation()); //kHorizontal_Orientation
Layout layout = fromOldLayout(SkFontLCDConfig::GetSubpixelOrder()); //kRGB_Layout
Geometry ret = { SkToU8(orientation | layout) };
return ret;
}

View File

@ -0,0 +1,59 @@
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkFontLCDConfig_DEFINED
#define SkFontLCDConfig_DEFINED
#include "SkTypes.h"
class SkFontLCDConfig {
public:
/** LCDs either have their color elements arranged horizontally or
vertically. When rendering subpixel glyphs we need to know which way
round they are.
Note, if you change this after startup, you'll need to flush the glyph
cache because it'll have the wrong type of masks cached.
@deprecated use SkPixelGeometry instead.
*/
enum LCDOrientation {
kHorizontal_LCDOrientation = 0, //!< this is the default
kVertical_LCDOrientation = 1
};
/** @deprecated set on Device creation. */
static void SetSubpixelOrientation(LCDOrientation orientation);
/** @deprecated get from Device. */
static LCDOrientation GetSubpixelOrientation();
/** LCD color elements can vary in order. For subpixel text we need to know
the order which the LCDs uses so that the color fringes are in the
correct place.
Note, if you change this after startup, you'll need to flush the glyph
cache because it'll have the wrong type of masks cached.
kNONE_LCDOrder means that the subpixel elements are not spatially
separated in any usable fashion.
@deprecated use SkPixelGeometry instead.
*/
enum LCDOrder {
kRGB_LCDOrder = 0, //!< this is the default
kBGR_LCDOrder = 1,
kNONE_LCDOrder = 2
};
/** @deprecated set on Device creation. */
static void SetSubpixelOrder(LCDOrder order);
/** @deprecated get from Device. */
static LCDOrder GetSubpixelOrder();
};
#endif

View File

@ -1,4 +1,3 @@
/*
* Copyright 2009 The Android Open Source Project
*
@ -6,32 +5,46 @@
* found in the LICENSE file.
*/
#include "SkFontLCDConfig.h"
#include "SkFontHost.h"
static SkFontLCDConfig::LCDOrientation gLCDOrientation = SkFontLCDConfig::kHorizontal_LCDOrientation;
static SkFontLCDConfig::LCDOrder gLCDOrder = SkFontLCDConfig::kRGB_LCDOrder;
static SkFontHost::LCDOrientation gLCDOrientation = SkFontHost::kHorizontal_LCDOrientation;
static SkFontHost::LCDOrder gLCDOrder = SkFontHost::kRGB_LCDOrder;
// static
SkFontHost::LCDOrientation SkFontHost::GetSubpixelOrientation()
{
SkFontLCDConfig::LCDOrientation SkFontLCDConfig::GetSubpixelOrientation() {
return gLCDOrientation;
}
// static
void SkFontHost::SetSubpixelOrientation(LCDOrientation orientation)
{
void SkFontLCDConfig::SetSubpixelOrientation(LCDOrientation orientation) {
gLCDOrientation = orientation;
}
// static
SkFontHost::LCDOrder SkFontHost::GetSubpixelOrder()
{
SkFontLCDConfig::LCDOrder SkFontLCDConfig::GetSubpixelOrder() {
return gLCDOrder;
}
// static
void SkFontHost::SetSubpixelOrder(LCDOrder order)
{
void SkFontLCDConfig::SetSubpixelOrder(LCDOrder order) {
gLCDOrder = order;
}
///////////////////////////////////////////////////////////////////////////////
// Legacy wrappers : remove from SkFontHost when webkit switches to new API
#include "SkFontHost.h"
SkFontHost::LCDOrientation SkFontHost::GetSubpixelOrientation() {
return (SkFontHost::LCDOrientation)SkFontLCDConfig::GetSubpixelOrientation();
}
void SkFontHost::SetSubpixelOrientation(LCDOrientation orientation) {
SkFontLCDConfig::SetSubpixelOrientation((SkFontLCDConfig::LCDOrientation)orientation);
}
SkFontHost::LCDOrder SkFontHost::GetSubpixelOrder() {
return (SkFontHost::LCDOrder)SkFontLCDConfig::GetSubpixelOrder();
}
void SkFontHost::SetSubpixelOrder(LCDOrder order) {
SkFontLCDConfig::SetSubpixelOrder((SkFontLCDConfig::LCDOrder)order);
}

View File

@ -42,7 +42,7 @@ static SkFontConfigInterface* RefFCI() {
return fci;
}
fci = SkFontConfigInterface::GetSingletonDirectInterface();
SkFontConfigInterface::SetGlobal(fci);
SkFontConfigInterface::SetGlobal(fci)->unref();
}
}
@ -128,6 +128,7 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
FindRec rec(familyName, style);
SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_proc, &rec);
if (face) {
SkDebugf("found cached face <%s> <%s> %p [%d]\n", familyName, ((FontConfigTypeface*)face)->getFamilyName(), face, face->getRefCnt());
return face;
}
@ -142,6 +143,7 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
face = SkNEW_ARGS(FontConfigTypeface, (outStyle, indentity, outFamilyName));
SkTypefaceCache::Add(face, style);
SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str(), face, face->getRefCnt());
return face;
}