Add Sad Tab resources to the iOS build.
[chromium-blink-merge.git] / cc / bitmap_content_layer_updater.cc
blob387a06c113b9997a5e2e3fa0722cebc053478706
1 // Copyright 2011 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/bitmap_content_layer_updater.h"
9 #include "cc/layer_painter.h"
10 #include "cc/resource_update.h"
11 #include "cc/resource_update_queue.h"
12 #include "skia/ext/platform_canvas.h"
14 namespace cc {
16 BitmapContentLayerUpdater::Resource::Resource(BitmapContentLayerUpdater* updater, scoped_ptr<PrioritizedResource> texture)
17 : LayerUpdater::Resource(texture.Pass())
18 , m_updater(updater)
22 BitmapContentLayerUpdater::Resource::~Resource()
26 void BitmapContentLayerUpdater::Resource::update(ResourceUpdateQueue& queue, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset, bool partialUpdate, RenderingStats&)
28 updater()->updateTexture(queue, texture(), sourceRect, destOffset, partialUpdate);
31 scoped_refptr<BitmapContentLayerUpdater> BitmapContentLayerUpdater::create(scoped_ptr<LayerPainter> painter)
33 return make_scoped_refptr(new BitmapContentLayerUpdater(painter.Pass()));
36 BitmapContentLayerUpdater::BitmapContentLayerUpdater(scoped_ptr<LayerPainter> painter)
37 : ContentLayerUpdater(painter.Pass())
38 , m_opaque(false)
42 BitmapContentLayerUpdater::~BitmapContentLayerUpdater()
46 scoped_ptr<LayerUpdater::Resource> BitmapContentLayerUpdater::createResource(PrioritizedResourceManager* manager)
48 return scoped_ptr<LayerUpdater::Resource>(new Resource(this, PrioritizedResource::create(manager)));
51 void BitmapContentLayerUpdater::prepareToUpdate(const gfx::Rect& contentRect, const gfx::Size& tileSize, float contentsWidthScale, float contentsHeightScale, gfx::Rect& resultingOpaqueRect, RenderingStats& stats)
53 if (m_canvasSize != contentRect.size()) {
54 m_canvasSize = contentRect.size();
55 m_canvas = make_scoped_ptr(skia::CreateBitmapCanvas(m_canvasSize.width(), m_canvasSize.height(), m_opaque));
58 paintContents(m_canvas.get(), contentRect, contentsWidthScale, contentsHeightScale, resultingOpaqueRect, stats);
61 void BitmapContentLayerUpdater::updateTexture(ResourceUpdateQueue& queue, PrioritizedResource* texture, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset, bool partialUpdate)
63 ResourceUpdate upload = ResourceUpdate::Create(
64 texture,
65 &m_canvas->getDevice()->accessBitmap(false),
66 contentRect(),
67 sourceRect,
68 destOffset);
69 if (partialUpdate)
70 queue.appendPartialUpload(upload);
71 else
72 queue.appendFullUpload(upload);
75 void BitmapContentLayerUpdater::setOpaque(bool opaque)
77 if (opaque != m_opaque) {
78 m_canvas.reset();
79 m_canvasSize = gfx::Size();
81 m_opaque = opaque;
84 } // namespace cc