Diff
Modified: trunk/Source/WebCore/ChangeLog (124374 => 124375)
--- trunk/Source/WebCore/ChangeLog 2012-08-01 22:21:00 UTC (rev 124374)
+++ trunk/Source/WebCore/ChangeLog 2012-08-01 22:26:21 UTC (rev 124375)
@@ -1,3 +1,33 @@
+2012-08-01 James Robinson <[email protected]>
+
+ [chromium] Move compositor HUD font atlas generation out of compositor core
+ https://bugs.webkit.org/show_bug.cgi?id=92901
+
+ Reviewed by Adrienne Walker.
+
+ This moves the font atlas generation out of CCFontAtlas into a separate helper class and ports the CCFontAtlas
+ text drawing code over to use skia directly.
+
+ * WebCore.gypi:
+ * platform/graphics/chromium/CompositorHUDFontAtlas.cpp: Added.
+ (WebCore):
+ (WebCore::wrapPositionIfNeeded):
+ (WebCore::CompositorHUDFontAtlas::generateFontAtlas):
+ * platform/graphics/chromium/CompositorHUDFontAtlas.h: Added.
+ (WebCore):
+ (CompositorHUDFontAtlas):
+ * platform/graphics/chromium/cc/CCFontAtlas.cpp:
+ (WebCore::CCFontAtlas::CCFontAtlas):
+ (WebCore::CCFontAtlas::~CCFontAtlas):
+ (WebCore::CCFontAtlas::initialize):
+ (WebCore::CCFontAtlas::drawText):
+ (WebCore::CCFontAtlas::drawOneLineOfTextInternal):
+ (WebCore::CCFontAtlas::drawDebugAtlas):
+ * platform/graphics/chromium/cc/CCFontAtlas.h:
+ (WebCore):
+ (CCFontAtlas):
+ * platform/graphics/chromium/cc/CCHeadsUpDisplayLayerImpl.cpp:
+
2012-08-01 Peter Beverloo <[email protected]>
[Text Autosizing] Provide an API for influencing the font scale factor
Modified: trunk/Source/WebCore/WebCore.gypi (124374 => 124375)
--- trunk/Source/WebCore/WebCore.gypi 2012-08-01 22:21:00 UTC (rev 124374)
+++ trunk/Source/WebCore/WebCore.gypi 2012-08-01 22:26:21 UTC (rev 124375)
@@ -8246,6 +8246,8 @@
'platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h',
'platform/graphics/chromium/CanvasLayerTextureUpdater.cpp',
'platform/graphics/chromium/CanvasLayerTextureUpdater.h',
+ 'platform/graphics/chromium/CompositorHUDFontAtlas.cpp',
+ 'platform/graphics/chromium/CompositorHUDFontAtlas.h',
'platform/graphics/chromium/ContentLayerChromium.cpp',
'platform/graphics/chromium/ContentLayerChromium.h',
'platform/graphics/chromium/FrameBufferSkPictureCanvasLayerTextureUpdater.cpp',
Added: trunk/Source/WebCore/platform/graphics/chromium/CompositorHUDFontAtlas.cpp (0 => 124375)
--- trunk/Source/WebCore/platform/graphics/chromium/CompositorHUDFontAtlas.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/CompositorHUDFontAtlas.cpp 2012-08-01 22:26:21 UTC (rev 124375)
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "CompositorHUDFontAtlas.h"
+
+#include "Font.h"
+#include "FontCache.h"
+#include "FontDescription.h"
+#include "GraphicsContext.h"
+#include "PlatformContextSkia.h"
+#include "SkCanvas.h"
+#include "SkDevice.h"
+#include "TextRun.h"
+#include "skia/ext/platform_canvas.h"
+
+namespace WebCore {
+
+#define ATLAS_SIZE 128
+
+static void wrapPositionIfNeeded(IntPoint& position, int textWidth, int textHeight)
+{
+ if (position.x() + textWidth > ATLAS_SIZE)
+ position = IntPoint(0, position.y() + textHeight);
+}
+
+// Paints the font into the atlas, from left-to-right, top-to-bottom, starting at
+// startingPosition. At the same time, it updates the ascii-to-IntRect mapping for
+// each character. By doing things this way, it is possible to support variable-width
+// fonts and multiple fonts on the same atlas.
+SkBitmap CompositorHUDFontAtlas::generateFontAtlas(IntRect asciiToRectTable[128], int& fontHeight)
+{
+ fontHeight = 14;
+
+ OwnPtr<SkCanvas> canvas = adoptPtr(skia::CreateBitmapCanvas(ATLAS_SIZE, ATLAS_SIZE, false /* opaque */));
+
+ PlatformContextSkia platformContext(canvas.get());
+ platformContext.setDrawingToImageBuffer(true);
+ GraphicsContext atlasContext(&platformContext);
+
+ // Clear the entire texture atlas to transparent before drawing fonts.
+ atlasContext.setFillColor(Color(0, 0, 0, 0), ColorSpaceDeviceRGB);
+ atlasContext.fillRect(FloatRect(0, 0, ATLAS_SIZE, ATLAS_SIZE));
+
+ // FIXME: monospace font does not work as expected.
+ FontDescription fontDescription;
+ fontDescription.setGenericFamily(FontDescription::MonospaceFamily);
+ fontDescription.setComputedSize(fontHeight);
+
+ FontCachePurgePreventer fontCachePurgePreventer;
+
+ int textHeight = fontDescription.computedPixelSize();
+ IntPoint position(0, textHeight);
+ // This is a dirty little trick to account for overhang letters like g, p, j.
+ int inflation = textHeight / 3;
+
+ Font font(fontDescription, 0, 0);
+ font.update(0);
+
+ Color fontColor(255, 0, 0);
+ atlasContext.setStrokeColor(fontColor, ColorSpaceDeviceRGB);
+ atlasContext.setFillColor(fontColor, ColorSpaceDeviceRGB);
+
+ // First, draw a generic rect that will be used for special and unknown characters that have nothing else to render.
+ {
+ int textWidth = textHeight / 2;
+ wrapPositionIfNeeded(position, textWidth, textHeight + inflation);
+ atlasContext.strokeRect(FloatRect(FloatPoint(position.x() + 1, position.y() - textHeight + 1 + inflation), FloatSize(textWidth - 2, textHeight - 2 - inflation)), 1);
+
+ // Initialize the rect that would be copied when drawing this glyph from the atlas.
+ asciiToRectTable[0] = IntRect(IntPoint(position.x(), position.y() - textHeight), IntSize(textWidth, textHeight + inflation));
+
+ // Increment to the position where the next glyph will be placed.
+ position.setX(position.x() + textWidth);
+ }
+
+ // Then, draw the ASCII characters.
+ for (LChar i = 1; i < 128; ++i) {
+ if (i < 32) {
+ // Special characters will simply use the the default glyph.
+ asciiToRectTable[i] = asciiToRectTable[0];
+ continue;
+ }
+
+ String str;
+ str.append(i);
+ TextRun text(str);
+
+ int textWidth = round(font.width(text));
+ wrapPositionIfNeeded(position, textWidth, textHeight + inflation);
+ atlasContext.drawText(font, text, position);
+
+ // Initialize the rect that would be copied when drawing this glyph from the atlas.
+ asciiToRectTable[i] = IntRect(IntPoint(position.x(), position.y() - textHeight), IntSize(textWidth, textHeight + inflation));
+
+ // Increment to the position where the next glyph will be placed.
+ position.setX(position.x() + textWidth);
+ }
+
+ SkBitmap copy;
+ const SkBitmap& source = canvas->getDevice()->accessBitmap(false);
+ source.copyTo(©, source.config());
+ return copy;
+}
+
+} // namespace WebCore
Property changes on: trunk/Source/WebCore/platform/graphics/chromium/CompositorHUDFontAtlas.cpp
___________________________________________________________________
Added: svn:eol-style
Added: trunk/Source/WebCore/platform/graphics/chromium/CompositorHUDFontAtlas.h (0 => 124375)
--- trunk/Source/WebCore/platform/graphics/chromium/CompositorHUDFontAtlas.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/CompositorHUDFontAtlas.h 2012-08-01 22:26:21 UTC (rev 124375)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CompositorHUDFontAtlas_h
+#define CompositorHUDFontAtlas_h
+
+#include "IntRect.h"
+#include "SkBitmap.h"
+
+namespace WebCore {
+
+class CompositorHUDFontAtlas {
+public:
+ // This is a helper function that can generate a font atlas suitable for the compositor's heads up display.
+ // Returns a bitmap containing glyphs and populates asciiToRectTable with the
+ // location of each glyph.
+ static SkBitmap generateFontAtlas(IntRect asciiToRectTable[128], int& fontHeight);
+};
+
+} // namespace WebCore
+
+#endif // CompositorHUDFontAtlas_h
+
Property changes on: trunk/Source/WebCore/platform/graphics/chromium/CompositorHUDFontAtlas.h
___________________________________________________________________
Added: svn:eol-style
Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCFontAtlas.cpp (124374 => 124375)
--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCFontAtlas.cpp 2012-08-01 22:21:00 UTC (rev 124374)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCFontAtlas.cpp 2012-08-01 22:26:21 UTC (rev 124375)
@@ -27,151 +27,69 @@
#if USE(ACCELERATED_COMPOSITING)
#include "CCFontAtlas.h"
-#include "Font.h"
-#include "FontCache.h"
-#include "FontDescription.h"
-#include "GraphicsContext.h"
-#include "ImageBuffer.h"
-#include "TextRun.h"
+#include "CompositorHUDFontAtlas.h"
+#include "SkCanvas.h"
#include "cc/CCProxy.h"
-#define ATLAS_SIZE 128
-#define FONT_HEIGHT 14
-
namespace WebCore {
using namespace std;
CCFontAtlas::CCFontAtlas()
- : m_fontHeight(FONT_HEIGHT)
+ : m_fontHeight(0)
{
}
-static void wrapPositionIfNeeded(IntPoint& position, int textWidth, int textHeight)
-{
- if (position.x() + textWidth > ATLAS_SIZE)
- position = IntPoint(0, position.y() + textHeight);
-}
-void CCFontAtlas::generateAtlasForFont(GraphicsContext* atlasContext, const FontDescription& fontDescription, const Color& fontColor, const IntPoint& startingPosition, IntRect asciiToAtlasTable[128])
+CCFontAtlas::~CCFontAtlas()
{
- ASSERT(CCProxy::isMainThread());
- ASSERT(m_atlas);
-
- FontCachePurgePreventer fontCachePurgePreventer;
-
- IntPoint position = startingPosition;
- int textHeight = fontDescription.computedPixelSize();
- // This is a dirty little trick to account for overhang letters like g, p, j.
- int inflation = textHeight / 3;
-
- Font font(fontDescription, 0, 0);
- font.update(0);
-
- atlasContext->setStrokeColor(fontColor, ColorSpaceDeviceRGB);
- atlasContext->setFillColor(fontColor, ColorSpaceDeviceRGB);
-
- // First, draw a generic rect that will be used for special and unknown characters that have nothing else to render.
- {
- int textWidth = textHeight / 2;
- wrapPositionIfNeeded(position, textWidth, textHeight + inflation);
- atlasContext->strokeRect(FloatRect(FloatPoint(position.x() + 1, position.y() - textHeight + 1 + inflation), FloatSize(textWidth - 2, textHeight - 2 - inflation)), 1);
-
- // Initialize the rect that would be copied when drawing this glyph from the atlas.
- asciiToAtlasTable[0] = IntRect(IntPoint(position.x(), position.y() - textHeight), IntSize(textWidth, textHeight + inflation));
-
- // Increment to the position where the next glyph will be placed.
- position.setX(position.x() + textWidth);
- }
-
- // Then, draw the ASCII characters.
- for (LChar i = 1; i < 128; ++i) {
- if (i < 32) {
- // Special characters will simply use the the default glyph.
- asciiToAtlasTable[i] = asciiToAtlasTable[0];
- continue;
- }
-
- String str;
- str.append(i);
- TextRun text(str);
-
- int textWidth = round(font.width(text));
- wrapPositionIfNeeded(position, textWidth, textHeight + inflation);
- atlasContext->drawText(font, text, position);
-
- // Initialize the rect that would be copied when drawing this glyph from the atlas.
- asciiToAtlasTable[i] = IntRect(IntPoint(position.x(), position.y() - textHeight), IntSize(textWidth, textHeight + inflation));
-
- // Increment to the position where the next glyph will be placed.
- position.setX(position.x() + textWidth);
- }
}
void CCFontAtlas::initialize()
{
ASSERT(CCProxy::isMainThread());
- // We expect this function to be called only once when the atlas did not exist yet. We should be aware if that's not true.
- ASSERT(!m_atlas);
-
- m_atlas = ImageBuffer::create(IntSize(ATLAS_SIZE, ATLAS_SIZE));
- GraphicsContext* atlasContext = m_atlas->context();
-
- // Clear the entire texture atlas to transparent before drawing fonts.
- atlasContext->setFillColor(Color(0, 0, 0, 0), ColorSpaceDeviceRGB);
- atlasContext->fillRect(FloatRect(0, 0, ATLAS_SIZE, ATLAS_SIZE));
-
- // FIXME: monospace font does not work as expected.
- FontDescription fontDescription;
- fontDescription.setGenericFamily(FontDescription::MonospaceFamily);
- fontDescription.setComputedSize(m_fontHeight);
- generateAtlasForFont(atlasContext, fontDescription, Color(255, 0, 0), IntPoint(0, fontDescription.computedPixelSize()), m_asciiToRectTable);
+ m_atlas = CompositorHUDFontAtlas::generateFontAtlas(m_asciiToRectTable, m_fontHeight);
}
void CCFontAtlas::drawText(SkCanvas* canvas, const String& text, const IntPoint& destPosition, const IntSize& clip) const
{
ASSERT(CCProxy::isImplThread());
- ASSERT(m_atlas);
Vector<String> lines;
text.split('\n', lines);
- PlatformContextSkia platformContext(canvas);
- platformContext.setDrawingToImageBuffer(true);
- GraphicsContext context(&platformContext);
-
IntPoint position = destPosition;
for (size_t i = 0; i < lines.size(); ++i) {
- drawOneLineOfTextInternal(&context, lines[i], position);
+ drawOneLineOfTextInternal(canvas, lines[i], position);
position.setY(position.y() + m_fontHeight);
if (position.y() > clip.height())
return;
}
}
-void CCFontAtlas::drawOneLineOfTextInternal(GraphicsContext* targetContext, const String& textLine, const IntPoint& destPosition) const
+void CCFontAtlas::drawOneLineOfTextInternal(SkCanvas* canvas, const String& textLine, const IntPoint& destPosition) const
{
ASSERT(CCProxy::isImplThread());
- ASSERT(m_atlas);
IntPoint position = destPosition;
for (unsigned i = 0; i < textLine.length(); ++i) {
// If the ASCII code is out of bounds, then index 0 is used, which is just a plain rectangle glyph.
int asciiIndex = (textLine[i] < 128) ? textLine[i] : 0;
IntRect glyphBounds = m_asciiToRectTable[asciiIndex];
- targetContext->drawImageBuffer(m_atlas.get(), ColorSpaceDeviceRGB, position, glyphBounds);
+ SkIRect source = glyphBounds;
+ canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(position.x(), position.y(), glyphBounds.width(), glyphBounds.height()));
position.setX(position.x() + glyphBounds.width());
}
}
-void CCFontAtlas::drawDebugAtlas(GraphicsContext* targetContext, const IntPoint& destPosition) const
+void CCFontAtlas::drawDebugAtlas(SkCanvas* canvas, const IntPoint& destPosition) const
{
ASSERT(CCProxy::isImplThread());
- ASSERT(m_atlas);
- targetContext->drawImageBuffer(m_atlas.get(), ColorSpaceDeviceRGB, destPosition, IntRect(IntPoint::zero(), IntSize(ATLAS_SIZE, ATLAS_SIZE)));
+ SkIRect source = SkIRect::MakeWH(m_atlas.width(), m_atlas.height());
+ canvas->drawBitmapRect(m_atlas, &source, SkRect::MakeXYWH(destPosition.x(), destPosition.y(), m_atlas.width(), m_atlas.height()));
}
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCFontAtlas.h (124374 => 124375)
--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCFontAtlas.h 2012-08-01 22:21:00 UTC (rev 124374)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCFontAtlas.h 2012-08-01 22:26:21 UTC (rev 124375)
@@ -27,7 +27,8 @@
#if USE(ACCELERATED_COMPOSITING)
-#include "ImageBuffer.h"
+#include "IntRect.h"
+#include "SkBitmap.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/text/WTFString.h>
@@ -38,9 +39,9 @@
class Color;
class FontDescription;
-class IntPoint;
-class IntRect;
class GraphicsContext;
+class IntPoint;
+class IntSize;
// This class provides basic ability to draw text onto the heads-up display.
// It must be initialized on the main thread, and it can only draw text on the impl thread.
@@ -51,6 +52,7 @@
{
return adoptPtr(new CCFontAtlas());
}
+ ~CCFontAtlas();
// Creates the font atlas.
// - Should only be called on the main thread.
@@ -65,21 +67,15 @@
void drawText(SkCanvas*, const String& text, const IntPoint& destPosition, const IntSize& clip) const;
// Draws the entire atlas at the specified position, just for debugging purposes.
- void drawDebugAtlas(GraphicsContext*, const IntPoint& destPosition) const;
+ void drawDebugAtlas(SkCanvas*, const IntPoint& destPosition) const;
private:
CCFontAtlas();
- // Paints the font into the atlas, from left-to-right, top-to-bottom, starting at
- // startingPosition. At the same time, it updates the ascii-to-IntRect mapping for
- // each character. By doing things this way, it is possible to support variable-width
- // fonts and multiple fonts on the same atlas.
- void generateAtlasForFont(GraphicsContext*, const FontDescription&, const Color& fontColor, const IntPoint& startingPosition, IntRect asciiToAtlasTable[128]);
+ void drawOneLineOfTextInternal(SkCanvas*, const String&, const IntPoint& destPosition) const;
- void drawOneLineOfTextInternal(GraphicsContext*, const String&, const IntPoint& destPosition) const;
-
// The actual texture atlas containing all the pre-rendered glyphs.
- OwnPtr<ImageBuffer> m_atlas;
+ SkBitmap m_atlas;
// The look-up tables mapping ascii characters to their IntRect locations on the atlas.
IntRect m_asciiToRectTable[128];
Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplayLayerImpl.cpp (124374 => 124375)
--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplayLayerImpl.cpp 2012-08-01 22:21:00 UTC (rev 124374)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplayLayerImpl.cpp 2012-08-01 22:26:21 UTC (rev 124375)
@@ -30,11 +30,14 @@
#include "Extensions3DChromium.h"
#include "GraphicsContext3D.h"
#include "LayerRendererChromium.h"
+#include "SkBitmap.h"
+#include "SkPaint.h"
#include "cc/CCDebugRectHistory.h"
#include "cc/CCFontAtlas.h"
#include "cc/CCFrameRateCounter.h"
#include "cc/CCLayerTreeHostImpl.h"
#include "cc/CCQuadSink.h"
+#include "skia/ext/platform_canvas.h"
#include <public/WebCompositorTextureQuad.h>
#include <wtf/text/WTFString.h>