blob: f3819faf3dd236f478f694bd9f64f3a8211d4cd6 [file] [log] [blame]
[email protected]94f206c12012-08-25 00:09:141// 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.
4
[email protected]a8461d82012-10-16 21:11:145#include "cc/image_layer.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]a8461d82012-10-16 21:11:147#include "base/compiler_specific.h"
[email protected]35680c02012-11-06 05:53:008#include "cc/image_layer_updater.h"
[email protected]64d8d392012-10-23 18:34:519#include "cc/layer_updater.h"
[email protected]d50c6862012-10-23 02:08:3110#include "cc/layer_tree_host.h"
[email protected]b4da2032012-10-25 21:22:5511#include "cc/resource_update_queue.h"
[email protected]94f206c12012-08-25 00:09:1412
[email protected]9c88e562012-09-14 22:21:3013namespace cc {
[email protected]94f206c12012-08-25 00:09:1414
[email protected]96baf3e2012-10-22 23:09:5515scoped_refptr<ImageLayer> ImageLayer::create()
[email protected]94f206c12012-08-25 00:09:1416{
[email protected]96baf3e2012-10-22 23:09:5517 return make_scoped_refptr(new ImageLayer());
[email protected]94f206c12012-08-25 00:09:1418}
19
[email protected]96baf3e2012-10-22 23:09:5520ImageLayer::ImageLayer()
21 : TiledLayer()
[email protected]94f206c12012-08-25 00:09:1422{
23}
24
[email protected]96baf3e2012-10-22 23:09:5525ImageLayer::~ImageLayer()
[email protected]94f206c12012-08-25 00:09:1426{
27}
28
[email protected]96baf3e2012-10-22 23:09:5529void ImageLayer::setBitmap(const SkBitmap& bitmap)
[email protected]94f206c12012-08-25 00:09:1430{
31 // setBitmap() currently gets called whenever there is any
32 // style change that affects the layer even if that change doesn't
33 // affect the actual contents of the image (e.g. a CSS animation).
34 // With this check in place we avoid unecessary texture uploads.
35 if (bitmap.pixelRef() && bitmap.pixelRef() == m_bitmap.pixelRef())
36 return;
37
38 m_bitmap = bitmap;
39 setNeedsDisplay();
40}
41
[email protected]96baf3e2012-10-22 23:09:5542void ImageLayer::setTexturePriorities(const PriorityCalculator& priorityCalc)
[email protected]94f206c12012-08-25 00:09:1443{
44 // Update the tile data before creating all the layer's tiles.
45 updateTileSizeAndTilingOption();
46
[email protected]96baf3e2012-10-22 23:09:5547 TiledLayer::setTexturePriorities(priorityCalc);
[email protected]94f206c12012-08-25 00:09:1448}
49
[email protected]b4da2032012-10-25 21:22:5550void ImageLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker* occlusion, RenderingStats& stats)
[email protected]94f206c12012-08-25 00:09:1451{
[email protected]64d8d392012-10-23 18:34:5152 createUpdaterIfNeeded();
[email protected]94f206c12012-08-25 00:09:1453 if (m_needsDisplay) {
[email protected]64d8d392012-10-23 18:34:5154 m_updater->setBitmap(m_bitmap);
[email protected]94f206c12012-08-25 00:09:1455 updateTileSizeAndTilingOption();
[email protected]aad0a0072012-11-01 18:15:5856 invalidateContentRect(gfx::Rect(gfx::Point(), contentBounds()));
[email protected]94f206c12012-08-25 00:09:1457 m_needsDisplay = false;
58 }
[email protected]96baf3e2012-10-22 23:09:5559 TiledLayer::update(queue, occlusion, stats);
[email protected]94f206c12012-08-25 00:09:1460}
61
[email protected]64d8d392012-10-23 18:34:5162void ImageLayer::createUpdaterIfNeeded()
[email protected]94f206c12012-08-25 00:09:1463{
[email protected]64d8d392012-10-23 18:34:5164 if (m_updater)
[email protected]94f206c12012-08-25 00:09:1465 return;
66
[email protected]64d8d392012-10-23 18:34:5167 m_updater = ImageLayerUpdater::create();
[email protected]d9c28522012-10-18 23:35:4368 GLenum textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat;
[email protected]94f206c12012-08-25 00:09:1469 setTextureFormat(textureFormat);
[email protected]94f206c12012-08-25 00:09:1470}
71
[email protected]64d8d392012-10-23 18:34:5172LayerUpdater* ImageLayer::updater() const
[email protected]94f206c12012-08-25 00:09:1473{
[email protected]64d8d392012-10-23 18:34:5174 return m_updater.get();
[email protected]94f206c12012-08-25 00:09:1475}
76
[email protected]aad0a0072012-11-01 18:15:5877gfx::Size ImageLayer::contentBounds() const
[email protected]94f206c12012-08-25 00:09:1478{
[email protected]aad0a0072012-11-01 18:15:5879 return gfx::Size(m_bitmap.width(), m_bitmap.height());
[email protected]94f206c12012-08-25 00:09:1480}
81
[email protected]96baf3e2012-10-22 23:09:5582bool ImageLayer::drawsContent() const
[email protected]94f206c12012-08-25 00:09:1483{
[email protected]96baf3e2012-10-22 23:09:5584 return !m_bitmap.isNull() && TiledLayer::drawsContent();
[email protected]94f206c12012-08-25 00:09:1485}
86
[email protected]904e9132012-11-01 00:12:4787float ImageLayer::contentsScaleX() const
[email protected]94f206c12012-08-25 00:09:1488{
[email protected]aad0a0072012-11-01 18:15:5889 if (bounds().IsEmpty() || contentBounds().IsEmpty())
[email protected]904e9132012-11-01 00:12:4790 return 1;
91 return static_cast<float>(m_bitmap.width()) / bounds().width();
92}
93
94float ImageLayer::contentsScaleY() const
95{
[email protected]aad0a0072012-11-01 18:15:5896 if (bounds().IsEmpty() || contentBounds().IsEmpty())
[email protected]904e9132012-11-01 00:12:4797 return 1;
98 return static_cast<float>(m_bitmap.height()) / bounds().height();
[email protected]94f206c12012-08-25 00:09:1499}
100
[email protected]bc5e77c2012-11-05 20:00:49101} // namespace cc