Source/Platform/ChangeLog

 12012-08-01 James Robinson <jamesr@chromium.org>
 2
 3 [chromium] Move compositor HUD font atlas initialization code out of compositor core
 4 https://bugs.webkit.org/show_bug.cgi?id=92924
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 The chromium compositor does not have any text rendering capabilities. It generally does not need them, but it
 9 is helpful for some debugging aids to be able to render at least ASCII text to the screen. This provides an API
 10 on WebLayerTreeView by which an embedder can provide an ASCII glyph atlas to use for displaying debug
 11 information.
 12
 13 * chromium/public/WebLayerTreeView.h:
 14 (WebLayerTreeView):
 15
1162012-08-01 Tommy Widenflycht <tommyw@google.com>
217
318 MediaStream API: Add ExtraData capability to MediaStreamSource

Source/WebCore/ChangeLog

112012-08-01 James Robinson <jamesr@chromium.org>
22
 3 [chromium] Move compositor HUD font atlas initialization code out of compositor core
 4 https://bugs.webkit.org/show_bug.cgi?id=92924
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 This moves the HUD font atlas initialization code out of the compositor implementation to cut out Font-related
 9 dependencies. The new flow is that an embedder can pass a font atlas to the CCLayerTreeHost, after which the
 10 atlas is provided the HUD layer (if any) on the next commit. The HUD layer renders text using the font atlas if
 11 it has any if the settings require text.
 12
 13 HUD tested manually, we don't have automated tests for this debugging-only feature.
 14
 15 * platform/graphics/chromium/CompositorHUDFontAtlas.cpp:
 16 (WebCore):
 17 (WebCore::CompositorHUDFontAtlas::generateFontAtlas):
 18 * platform/graphics/chromium/CompositorHUDFontAtlas.h:
 19 (CompositorHUDFontAtlas):
 20 * platform/graphics/chromium/HeadsUpDisplayLayerChromium.cpp:
 21 (WebCore::HeadsUpDisplayLayerChromium::create):
 22 (WebCore::HeadsUpDisplayLayerChromium::HeadsUpDisplayLayerChromium):
 23 (WebCore::HeadsUpDisplayLayerChromium::setFontAtlas):
 24 (WebCore):
 25 (WebCore::HeadsUpDisplayLayerChromium::createCCLayerImpl):
 26 (WebCore::HeadsUpDisplayLayerChromium::pushPropertiesTo):
 27 * platform/graphics/chromium/HeadsUpDisplayLayerChromium.h:
 28 (HeadsUpDisplayLayerChromium):
 29 * platform/graphics/chromium/cc/CCFontAtlas.cpp:
 30 (WebCore::CCFontAtlas::CCFontAtlas):
 31 * platform/graphics/chromium/cc/CCFontAtlas.h:
 32 (WebCore):
 33 (WebCore::CCFontAtlas::create):
 34 (CCFontAtlas):
 35 * platform/graphics/chromium/cc/CCHeadsUpDisplayLayerImpl.cpp:
 36 (WebCore::CCHeadsUpDisplayLayerImpl::CCHeadsUpDisplayLayerImpl):
 37 (WebCore::CCHeadsUpDisplayLayerImpl::setFontAtlas):
 38 (WebCore):
 39 * platform/graphics/chromium/cc/CCHeadsUpDisplayLayerImpl.h:
 40 (WebCore::CCHeadsUpDisplayLayerImpl::create):
 41 (CCHeadsUpDisplayLayerImpl):
 42 * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
 43 (WebCore::CCLayerTreeHost::setFontAtlas):
 44 (WebCore):
 45 (WebCore::CCLayerTreeHost::willCommit):
 46 * platform/graphics/chromium/cc/CCLayerTreeHost.h:
 47 (WebCore):
 48 (CCLayerTreeHost):
 49
 502012-08-01 James Robinson <jamesr@chromium.org>
 51
352 [chromium] Move compositor HUD font atlas generation out of compositor core
453 https://bugs.webkit.org/show_bug.cgi?id=92901
554

Source/WebKit/chromium/ChangeLog

 12012-08-01 James Robinson <jamesr@chromium.org>
 2
 3 [chromium] Move compositor HUD font atlas initialization code out of compositor core
 4 https://bugs.webkit.org/show_bug.cgi?id=92924
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 This initializes the compositor's font atlas when initialization the compositor if the "Show FPS counter" or
 9 "Show layer tree" settings are true.
 10
 11 * src/WebLayerTreeView.cpp:
 12 (WebKit::WebLayerTreeView::setFontAtlas):
 13 (WebKit):
 14 * src/WebViewImpl.cpp:
 15 (WebKit::WebViewImpl::setIsAcceleratedCompositingActive):
 16
1172012-08-01 Peter Beverloo <peter@chromium.org>
218
319 [Text Autosizing] Provide an API for influencing the font scale factor

Source/Platform/chromium/public/WebLayerTreeView.h

2626#ifndef WebLayerTreeView_h
2727#define WebLayerTreeView_h
2828
 29#include "SkBitmap.h"
2930#include "WebColor.h"
3031#include "WebCommon.h"
3132#include "WebNonCopyable.h"

@@public:
175176 // This call is relatively expensive in threaded mode as it blocks on the compositor thread.
176177 WEBKIT_EXPORT void renderingStats(WebRenderingStats&) const;
177178
 179 // Provides a font atlas to use for debug visualizations. The atlas must be a bitmap containing glyph data, a table of
 180 // ASCII character values to a subrectangle of the atlas representing the corresponding glyph, and the glyph height.
 181 WEBKIT_EXPORT void setFontAtlas(SkBitmap, WebRect asciiToRectTable[128], int fontHeight);
 182
178183 // Simulates a lost context. For testing only.
179184 WEBKIT_EXPORT void loseCompositorContext(int numTimes);
180185

Source/WebCore/platform/graphics/chromium/CompositorHUDFontAtlas.cpp

3737#include "TextRun.h"
3838#include "skia/ext/platform_canvas.h"
3939
 40using WebKit::WebRect;
 41
4042namespace WebCore {
4143
4244#define ATLAS_SIZE 128

@@static void wrapPositionIfNeeded(IntPoint& position, int textWidth, int textHeig
4850}
4951
5052// Paints the font into the atlas, from left-to-right, top-to-bottom, starting at
51 // startingPosition. At the same time, it updates the ascii-to-IntRect mapping for
 53// startingPosition. At the same time, it updates the ascii-to-WebRect mapping for
5254// each character. By doing things this way, it is possible to support variable-width
5355// fonts and multiple fonts on the same atlas.
54 SkBitmap CompositorHUDFontAtlas::generateFontAtlas(IntRect asciiToRectTable[128], int& fontHeight)
 56SkBitmap CompositorHUDFontAtlas::generateFontAtlas(WebRect asciiToRectTable[128], int& fontHeight)
5557{
5658 fontHeight = 14;
5759

@@SkBitmap CompositorHUDFontAtlas::generateFontAtlas(IntRect asciiToRectTable[128]
9193 atlasContext.strokeRect(FloatRect(FloatPoint(position.x() + 1, position.y() - textHeight + 1 + inflation), FloatSize(textWidth - 2, textHeight - 2 - inflation)), 1);
9294
9395 // Initialize the rect that would be copied when drawing this glyph from the atlas.
94  asciiToRectTable[0] = IntRect(IntPoint(position.x(), position.y() - textHeight), IntSize(textWidth, textHeight + inflation));
 96 asciiToRectTable[0] = WebRect(position.x(), position.y() - textHeight, textWidth, textHeight + inflation);
9597
9698 // Increment to the position where the next glyph will be placed.
9799 position.setX(position.x() + textWidth);

@@SkBitmap CompositorHUDFontAtlas::generateFontAtlas(IntRect asciiToRectTable[128]
114116 atlasContext.drawText(font, text, position);
115117
116118 // Initialize the rect that would be copied when drawing this glyph from the atlas.
117  asciiToRectTable[i] = IntRect(IntPoint(position.x(), position.y() - textHeight), IntSize(textWidth, textHeight + inflation));
 119 asciiToRectTable[i] = WebRect(position.x(), position.y() - textHeight, textWidth, textHeight + inflation);
118120
119121 // Increment to the position where the next glyph will be placed.
120122 position.setX(position.x() + textWidth);

Source/WebCore/platform/graphics/chromium/CompositorHUDFontAtlas.h

2626#ifndef CompositorHUDFontAtlas_h
2727#define CompositorHUDFontAtlas_h
2828
29 #include "IntRect.h"
3029#include "SkBitmap.h"
 30#include <public/WebRect.h>
3131
3232namespace WebCore {
3333

@@public:
3636 // This is a helper function that can generate a font atlas suitable for the compositor's heads up display.
3737 // Returns a bitmap containing glyphs and populates asciiToRectTable with the
3838 // location of each glyph.
39  static SkBitmap generateFontAtlas(IntRect asciiToRectTable[128], int& fontHeight);
 39 static SkBitmap generateFontAtlas(WebKit::WebRect asciiToRectTable[128], int& fontHeight);
4040};
4141
4242} // namespace WebCore

Source/WebCore/platform/graphics/chromium/HeadsUpDisplayLayerChromium.cpp

3333
3434namespace WebCore {
3535
36 PassRefPtr<HeadsUpDisplayLayerChromium> HeadsUpDisplayLayerChromium::create(const CCLayerTreeSettings& settings)
 36PassRefPtr<HeadsUpDisplayLayerChromium> HeadsUpDisplayLayerChromium::create()
3737{
38  return adoptRef(new HeadsUpDisplayLayerChromium(settings));
 38 return adoptRef(new HeadsUpDisplayLayerChromium());
3939}
4040
41 HeadsUpDisplayLayerChromium::HeadsUpDisplayLayerChromium(const CCLayerTreeSettings& settings)
 41HeadsUpDisplayLayerChromium::HeadsUpDisplayLayerChromium()
4242 : LayerChromium()
4343{
4444
4545 setBounds(IntSize(512, 128));
46 
47  // Only allocate the font atlas if we have reason to use the heads-up display.
48  if (settings.showFPSCounter || settings.showPlatformLayerTree) {
49  TRACE_EVENT0("cc", "HeadsUpDisplayLayerChromium::initializeFontAtlas");
50  m_fontAtlas = CCFontAtlas::create();
51  m_fontAtlas->initialize();
52  }
5346}
5447
5548HeadsUpDisplayLayerChromium::~HeadsUpDisplayLayerChromium()

@@void HeadsUpDisplayLayerChromium::update(CCTextureUpdater&, const CCOcclusionTra
7366 setBounds(bounds);
7467}
7568
 69void HeadsUpDisplayLayerChromium::setFontAtlas(PassOwnPtr<CCFontAtlas> fontAtlas)
 70{
 71 m_fontAtlas = fontAtlas;
 72 setNeedsCommit();
 73}
 74
7675PassOwnPtr<CCLayerImpl> HeadsUpDisplayLayerChromium::createCCLayerImpl()
7776{
78  return CCHeadsUpDisplayLayerImpl::create(m_layerId, m_fontAtlas.release());
 77 return CCHeadsUpDisplayLayerImpl::create(m_layerId);
 78}
 79
 80void HeadsUpDisplayLayerChromium::pushPropertiesTo(CCLayerImpl* layerImpl)
 81{
 82 LayerChromium::pushPropertiesTo(layerImpl);
 83
 84 if (!m_fontAtlas)
 85 return;
 86
 87 CCHeadsUpDisplayLayerImpl* hudLayerImpl = static_cast<CCHeadsUpDisplayLayerImpl*>(layerImpl);
 88 hudLayerImpl->setFontAtlas(m_fontAtlas.release());
7989}
8090
8191}

Source/WebCore/platform/graphics/chromium/HeadsUpDisplayLayerChromium.h

3333
3434namespace WebCore {
3535
36 struct CCLayerTreeSettings;
37 
3836class HeadsUpDisplayLayerChromium : public LayerChromium {
3937public:
40  static PassRefPtr<HeadsUpDisplayLayerChromium> create(const CCLayerTreeSettings&);
 38 static PassRefPtr<HeadsUpDisplayLayerChromium> create();
4139 virtual ~HeadsUpDisplayLayerChromium();
4240
4341 virtual void update(CCTextureUpdater&, const CCOcclusionTracker*, CCRenderingStats&) OVERRIDE;
4442 virtual bool drawsContent() const OVERRIDE { return true; }
4543
 44 void setFontAtlas(PassOwnPtr<CCFontAtlas>);
 45
4646 virtual PassOwnPtr<CCLayerImpl> createCCLayerImpl() OVERRIDE;
 47 virtual void pushPropertiesTo(CCLayerImpl*) OVERRIDE;
4748
4849protected:
49  explicit HeadsUpDisplayLayerChromium(const CCLayerTreeSettings&);
 50 HeadsUpDisplayLayerChromium();
5051
5152private:
5253 OwnPtr<CCFontAtlas> m_fontAtlas;

Source/WebCore/platform/graphics/chromium/cc/CCFontAtlas.cpp

2727#if USE(ACCELERATED_COMPOSITING)
2828#include "CCFontAtlas.h"
2929
30 #include "CompositorHUDFontAtlas.h"
3130#include "SkCanvas.h"
3231#include "cc/CCProxy.h"
3332

@@namespace WebCore {
3534
3635using namespace std;
3736
38 
39 CCFontAtlas::CCFontAtlas()
40  : m_fontHeight(0)
 37CCFontAtlas::CCFontAtlas(SkBitmap bitmap, IntRect asciiToRectTable[128], int fontHeight)
 38 : m_atlas(bitmap)
 39 , m_fontHeight(fontHeight)
4140{
 41 for (size_t i = 0; i < 128; ++i)
 42 m_asciiToRectTable[i] = asciiToRectTable[i];
4243}
4344
44 
4545CCFontAtlas::~CCFontAtlas()
4646{
4747}
4848
49 void CCFontAtlas::initialize()
50 {
51  ASSERT(CCProxy::isMainThread());
52 
53  m_atlas = CompositorHUDFontAtlas::generateFontAtlas(m_asciiToRectTable, m_fontHeight);
54 }
55 
5649void CCFontAtlas::drawText(SkCanvas* canvas, const String& text, const IntPoint& destPosition, const IntSize& clip) const
5750{
5851 ASSERT(CCProxy::isImplThread());

Source/WebCore/platform/graphics/chromium/cc/CCFontAtlas.h

@@class IntPoint;
4444class IntSize;
4545
4646// This class provides basic ability to draw text onto the heads-up display.
47 // It must be initialized on the main thread, and it can only draw text on the impl thread.
4847class CCFontAtlas {
4948 WTF_MAKE_NONCOPYABLE(CCFontAtlas);
5049public:
51  static PassOwnPtr<CCFontAtlas> create()
 50 static PassOwnPtr<CCFontAtlas> create(SkBitmap bitmap, IntRect asciiToRectTable[128], int fontHeight)
5251 {
53  return adoptPtr(new CCFontAtlas());
 52 return adoptPtr(new CCFontAtlas(bitmap, asciiToRectTable, fontHeight));
5453 }
5554 ~CCFontAtlas();
5655
57  // Creates the font atlas.
58  // - Should only be called on the main thread.
59  void initialize();
60 
6156 // Draws multiple lines of text where each line of text is separated by '\n'.
6257 // - Correct glyphs will be drawn for ASCII codes in the range 32-127; any characters
6358 // outside that range will be displayed as a default rectangle glyph.

@@public:
7065 void drawDebugAtlas(SkCanvas*, const IntPoint& destPosition) const;
7166
7267private:
73  CCFontAtlas();
 68 CCFontAtlas(SkBitmap, IntRect asciiToRectTable[128], int fontHeight);
7469
7570 void drawOneLineOfTextInternal(SkCanvas*, const String&, const IntPoint& destPosition) const;
7671

Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplayLayerImpl.cpp

@@using WebKit::WebCompositorTextureQuad;
4545
4646namespace WebCore {
4747
48 CCHeadsUpDisplayLayerImpl::CCHeadsUpDisplayLayerImpl(int id, PassOwnPtr<CCFontAtlas> fontAtlas)
49  : CCLayerImpl(id),
50  m_fontAtlas(fontAtlas)
 48CCHeadsUpDisplayLayerImpl::CCHeadsUpDisplayLayerImpl(int id)
 49 : CCLayerImpl(id)
5150{
5251}
5352

@@CCHeadsUpDisplayLayerImpl::~CCHeadsUpDisplayLayerImpl()
5554{
5655}
5756
 57void CCHeadsUpDisplayLayerImpl::setFontAtlas(PassOwnPtr<CCFontAtlas> fontAtlas)
 58{
 59 m_fontAtlas = fontAtlas;
 60}
 61
5862void CCHeadsUpDisplayLayerImpl::willDraw(CCResourceProvider* resourceProvider)
5963{
6064 CCLayerImpl::willDraw(resourceProvider);

Source/WebCore/platform/graphics/chromium/cc/CCHeadsUpDisplayLayerImpl.h

@@class CCFrameRateCounter;
3939
4040class CCHeadsUpDisplayLayerImpl : public CCLayerImpl {
4141public:
42  static PassOwnPtr<CCHeadsUpDisplayLayerImpl> create(int id, PassOwnPtr<CCFontAtlas> fontAtlas)
 42 static PassOwnPtr<CCHeadsUpDisplayLayerImpl> create(int id)
4343 {
44  return adoptPtr(new CCHeadsUpDisplayLayerImpl(id, fontAtlas));
 44 return adoptPtr(new CCHeadsUpDisplayLayerImpl(id));
4545 }
4646 virtual ~CCHeadsUpDisplayLayerImpl();
4747
 48 void setFontAtlas(PassOwnPtr<CCFontAtlas>);
 49
4850 virtual void willDraw(CCResourceProvider*) OVERRIDE;
4951 virtual void appendQuads(CCQuadSink&, const CCSharedQuadState*, bool& hadMissingTiles) OVERRIDE;
5052 virtual void didDraw(CCResourceProvider*) OVERRIDE;

@@public:
5456 virtual bool layerIsAlwaysDamaged() const OVERRIDE { return true; }
5557
5658private:
57  CCHeadsUpDisplayLayerImpl(int, PassOwnPtr<CCFontAtlas>);
 59 explicit CCHeadsUpDisplayLayerImpl(int);
5860
5961 virtual const char* layerTypeAsString() const OVERRIDE { return "HeadsUpDisplayLayer"; }
6062

Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp

2626
2727#include "cc/CCLayerTreeHost.h"
2828
 29#include "CompositorHUDFontAtlas.h"
2930#include "HeadsUpDisplayLayerChromium.h"
3031#include "LayerChromium.h"
3132#include "Region.h"

@@void CCLayerTreeHost::finishCommitOnImplThread(CCLayerTreeHostImpl* hostImpl)
251252 m_commitNumber++;
252253}
253254
 255void CCLayerTreeHost::setFontAtlas(PassOwnPtr<CCFontAtlas> fontAtlas)
 256{
 257 m_fontAtlas = fontAtlas;
 258 setNeedsCommit();
 259}
 260
254261void CCLayerTreeHost::willCommit()
255262{
256263 m_client->willCommit();
257264 if (m_rootLayer && m_settings.showDebugInfo()) {
258265 if (!m_hudLayer)
259  m_hudLayer = HeadsUpDisplayLayerChromium::create(m_settings);
 266 m_hudLayer = HeadsUpDisplayLayerChromium::create();
 267
 268 if (m_fontAtlas)
 269 m_hudLayer->setFontAtlas(m_fontAtlas.release());
 270
260271 if (m_hudLayer->parent() != m_rootLayer.get()) {
261272 m_hudLayer->removeFromParent();
262273 m_rootLayer->addChild(m_hudLayer);

Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h

4747
4848namespace WebCore {
4949
 50class CCFontAtlas;
5051class CCGraphicsContext;
5152class CCLayerChromium;
5253class CCLayerTreeHostImpl;
5354class CCLayerTreeHostImplClient;
 55class CCPrioritizedTextureManager;
5456class CCTextureUpdater;
 57class HeadsUpDisplayLayerChromium;
5558class Region;
56 class CCPrioritizedTextureManager;
5759struct CCScrollAndScaleSet;
5860
5961class CCLayerTreeHostClient {

@@public:
271273 void setDeviceScaleFactor(float);
272274 float deviceScaleFactor() const { return m_deviceScaleFactor; }
273275
 276 void setFontAtlas(PassOwnPtr<CCFontAtlas>);
 277
274278protected:
275279 CCLayerTreeHost(CCLayerTreeHostClient*, const CCLayerTreeSettings&);
276280 bool initialize();

@@private:
313317 int m_numFailedRecreateAttempts;
314318
315319 RefPtr<LayerChromium> m_rootLayer;
316  RefPtr<LayerChromium> m_hudLayer;
 320 RefPtr<HeadsUpDisplayLayerChromium> m_hudLayer;
 321 OwnPtr<CCFontAtlas> m_fontAtlas;
 322
317323 OwnPtr<CCPrioritizedTextureManager> m_contentsTextureManager;
318324 OwnPtr<CCPrioritizedTexture> m_surfaceMemoryPlaceholder;
319325

@@private:
337343
338344 TextureList m_deleteTextureAfterCommitList;
339345 size_t m_partialTextureUpdateRequests;
 346
340347 static bool s_needsFilterContext;
341348};
342349

Source/WebKit/chromium/src/WebLayerTreeView.cpp

2929#include "GraphicsContext3DPrivate.h"
3030#include "LayerChromium.h"
3131#include "WebLayerTreeViewImpl.h"
 32#include "cc/CCFontAtlas.h"
3233#include "cc/CCGraphicsContext.h"
3334#include "cc/CCLayerTreeHost.h"
3435#include "cc/CCRenderingStats.h"

@@void WebLayerTreeView::renderingStats(WebRenderingStats& stats) const
189190 stats.totalRasterizeTimeInSeconds = ccStats.totalRasterizeTimeInSeconds;
190191}
191192
 193void WebLayerTreeView::setFontAtlas(SkBitmap bitmap, WebRect asciiToWebRectTable[128], int fontHeight)
 194{
 195 IntRect asciiToRectTable[128];
 196 for (int i = 0; i < 128; ++i)
 197 asciiToRectTable[i] = asciiToWebRectTable[i];
 198 OwnPtr<CCFontAtlas> fontAtlas = CCFontAtlas::create(bitmap, asciiToRectTable, fontHeight);
 199 m_private->layerTreeHost()->setFontAtlas(fontAtlas.release());
 200}
 201
192202void WebLayerTreeView::loseCompositorContext(int numTimes)
193203{
194204 m_private->layerTreeHost()->loseContext(numTimes);

Source/WebKit/chromium/src/WebViewImpl.cpp

4242#include "Color.h"
4343#include "ColorSpace.h"
4444#include "CompositionUnderlineVectorBuilder.h"
 45#include "CompositorHUDFontAtlas.h"
4546#include "ContextFeaturesClientImpl.h"
4647#include "ContextMenu.h"
4748#include "ContextMenuController.h"

@@void WebViewImpl::setIsAcceleratedCompositingActive(bool active)
36683669 m_compositorCreationFailed = false;
36693670 if (m_pageOverlays)
36703671 m_pageOverlays->update();
 3672
 3673 // Only allocate the font atlas if we have reason to use the heads-up display.
 3674 if (layerTreeViewSettings.showFPSCounter || layerTreeViewSettings.showPlatformLayerTree) {
 3675 TRACE_EVENT0("cc", "HeadsUpDisplayLayerChromium::initializeFontAtlas");
 3676 WebRect asciiToRectTable[128];
 3677 int fontHeight;
 3678 SkBitmap bitmap = WebCore::CompositorHUDFontAtlas::generateFontAtlas(asciiToRectTable, fontHeight);
 3679 m_layerTreeView.setFontAtlas(bitmap, asciiToRectTable, fontHeight);
 3680 }
36713681 } else {
36723682 m_nonCompositedContentHost.clear();
36733683 m_isAcceleratedCompositingActive = false;