Add Sad Tab resources to the iOS build.
[chromium-blink-merge.git] / cc / content_layer.cc
blob62f32212ee82cdf4b83152cf0d8945a710f594b8
1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "config.h"
7 #include "cc/content_layer.h"
9 #include "base/metrics/histogram.h"
10 #include "base/time.h"
11 #include "cc/bitmap_content_layer_updater.h"
12 #include "cc/bitmap_skpicture_content_layer_updater.h"
13 #include "cc/content_layer_client.h"
14 #include "cc/layer_painter.h"
15 #include "cc/layer_tree_host.h"
16 #include "cc/settings.h"
18 namespace cc {
20 ContentLayerPainter::ContentLayerPainter(ContentLayerClient* client)
21 : m_client(client)
25 scoped_ptr<ContentLayerPainter> ContentLayerPainter::create(ContentLayerClient* client)
27 return make_scoped_ptr(new ContentLayerPainter(client));
30 void ContentLayerPainter::paint(SkCanvas* canvas, const gfx::Rect& contentRect, gfx::RectF& opaque)
32 base::TimeTicks paintStart = base::TimeTicks::HighResNow();
33 m_client->paintContents(canvas, contentRect, opaque);
34 base::TimeTicks paintEnd = base::TimeTicks::HighResNow();
35 double pixelsPerSec = (contentRect.width() * contentRect.height()) / (paintEnd - paintStart).InSecondsF();
36 HISTOGRAM_CUSTOM_COUNTS("Renderer4.AccelContentPaintDurationMS", (paintEnd - paintStart).InMilliseconds(), 0, 120, 30);
37 HISTOGRAM_CUSTOM_COUNTS("Renderer4.AccelContentPaintMegapixPerSecond", pixelsPerSec / 1000000, 10, 210, 30);
40 scoped_refptr<ContentLayer> ContentLayer::create(ContentLayerClient* client)
42 return make_scoped_refptr(new ContentLayer(client));
45 ContentLayer::ContentLayer(ContentLayerClient* client)
46 : TiledLayer()
47 , m_client(client)
51 ContentLayer::~ContentLayer()
55 bool ContentLayer::drawsContent() const
57 return TiledLayer::drawsContent() && m_client;
60 void ContentLayer::setTexturePriorities(const PriorityCalculator& priorityCalc)
62 // Update the tile data before creating all the layer's tiles.
63 updateTileSizeAndTilingOption();
65 TiledLayer::setTexturePriorities(priorityCalc);
68 void ContentLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker* occlusion, RenderingStats& stats)
70 createUpdaterIfNeeded();
71 TiledLayer::update(queue, occlusion, stats);
72 m_needsDisplay = false;
75 bool ContentLayer::needMoreUpdates()
77 return needsIdlePaint();
80 LayerUpdater* ContentLayer::updater() const
82 return m_updater.get();
85 void ContentLayer::createUpdaterIfNeeded()
87 if (m_updater)
88 return;
89 scoped_ptr<LayerPainter> painter = ContentLayerPainter::create(m_client).PassAs<LayerPainter>();
90 if (layerTreeHost()->settings().acceleratePainting)
91 m_updater = SkPictureContentLayerUpdater::create(painter.Pass());
92 else if (Settings::perTilePaintingEnabled())
93 m_updater = BitmapSkPictureContentLayerUpdater::create(painter.Pass());
94 else
95 m_updater = BitmapContentLayerUpdater::create(painter.Pass());
96 m_updater->setOpaque(contentsOpaque());
98 GLenum textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat;
99 setTextureFormat(textureFormat);
102 void ContentLayer::setContentsOpaque(bool opaque)
104 Layer::setContentsOpaque(opaque);
105 if (m_updater)
106 m_updater->setOpaque(opaque);
109 } // namespace cc