aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/text/GrGlyphCache.cpp
diff options
context:
space:
mode:
authorGravatar Timothy Liang <timliang@google.com>2018-06-13 17:12:52 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-14 13:46:47 +0000
commite6f2ecafaf0efecacfd4256f280e26ee74cb7e16 (patch)
tree38380719920daa633ca82d39c85514d6b2961068 /src/gpu/text/GrGlyphCache.cpp
parent861ea5b7b24ed272a76aa27b3d6fd3fb18c4e8cc (diff)
added 565 to 8888 conversion for gpu LCD text rendering for macOS
Bug: skia: Change-Id: Ie24160bb098d388bf4ad69d0c2f9f8ed4beb215c Reviewed-on: https://skia-review.googlesource.com/134508 Commit-Queue: Timothy Liang <timliang@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src/gpu/text/GrGlyphCache.cpp')
-rw-r--r--src/gpu/text/GrGlyphCache.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/gpu/text/GrGlyphCache.cpp b/src/gpu/text/GrGlyphCache.cpp
index f6a18c3271..78b9dc3d12 100644
--- a/src/gpu/text/GrGlyphCache.cpp
+++ b/src/gpu/text/GrGlyphCache.cpp
@@ -8,10 +8,15 @@
#include "GrGlyphCache.h"
#include "GrAtlasManager.h"
#include "GrCaps.h"
+#include "GrColor.h"
#include "GrDistanceFieldGenFromVector.h"
#include "SkAutoMalloc.h"
#include "SkDistanceFieldGen.h"
+#include "SkMasks.h"
+
+static std::unique_ptr<const SkMasks> k565Masks(SkMasks::CreateMasks({0xF800, 0x07E0, 0x001F, 0},
+ GrMaskFormatBytesPerPixel(kA565_GrMaskFormat) * 8));
GrGlyphCache::GrGlyphCache(const GrCaps* caps, size_t maxTextureBytes)
: fPreserveStrike(nullptr), fGlyphSizeLimit(0) {
@@ -128,6 +133,29 @@ static bool get_packed_glyph_image(SkGlyphCache* cache, const SkGlyph& glyph, in
return false;
}
+ // Convert if the glyph uses a 565 mask format since it is using LCD text rendering but the
+ // expected format is 8888 (will happen on macOS with Metal since that combination does not
+ // support 565).
+ if (kA565_GrMaskFormat == get_packed_glyph_mask_format(glyph) &&
+ kARGB_GrMaskFormat == expectedMaskFormat) {
+ const int a565Bpp = GrMaskFormatBytesPerPixel(kA565_GrMaskFormat);
+ const int argbBpp = GrMaskFormatBytesPerPixel(kARGB_GrMaskFormat);
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ uint16_t color565 = 0;
+ memcpy(&color565, src, a565Bpp);
+ uint32_t colorRGBA = GrColorPackRGBA(k565Masks->getRed(color565),
+ k565Masks->getGreen(color565),
+ k565Masks->getBlue(color565),
+ 0xFF);
+ memcpy(dst, &colorRGBA, argbBpp);
+ src = (char*)src + a565Bpp;
+ dst = (char*)dst + argbBpp;
+ }
+ }
+ return true;
+ }
+
// crbug:510931
// Retrieving the image from the cache can actually change the mask format. This case is very
// uncommon so for now we just draw a clear box for these glyphs.
@@ -237,6 +265,7 @@ GrDrawOpAtlas::ErrorCode GrTextStrike::addGlyphToAtlas(
SkASSERT(cache);
SkASSERT(fCache.find(glyph->fPackedID));
+ expectedMaskFormat = fullAtlasManager->resolveMaskFormat(expectedMaskFormat);
int bytesPerPixel = GrMaskFormatBytesPerPixel(expectedMaskFormat);
int width = glyph->width();
int height = glyph->height();