Re-land: C++ readability review
[chromium-blink-merge.git] / cc / resources / image_layer_updater.cc
blob0538d96ea36b5579ff4f4fba0b3e68d4bd2fb8b7
1 // Copyright 2012 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 "cc/resources/image_layer_updater.h"
6 #include "cc/resources/prioritized_resource.h"
7 #include "cc/resources/resource_update_queue.h"
9 namespace cc {
11 ImageLayerUpdater::Resource::Resource(ImageLayerUpdater* updater,
12 scoped_ptr<PrioritizedResource> texture)
13 : LayerUpdater::Resource(texture.Pass()), updater_(updater) {}
15 ImageLayerUpdater::Resource::~Resource() {}
17 void ImageLayerUpdater::Resource::Update(ResourceUpdateQueue* queue,
18 const gfx::Rect& source_rect,
19 const gfx::Vector2d& dest_offset,
20 bool partial_update) {
21 updater_->UpdateTexture(
22 queue, texture(), source_rect, dest_offset, partial_update);
25 // static
26 scoped_refptr<ImageLayerUpdater> ImageLayerUpdater::Create() {
27 return make_scoped_refptr(new ImageLayerUpdater());
30 scoped_ptr<LayerUpdater::Resource> ImageLayerUpdater::CreateResource(
31 PrioritizedResourceManager* manager) {
32 return make_scoped_ptr(
33 new Resource(this, PrioritizedResource::Create(manager)));
36 void ImageLayerUpdater::UpdateTexture(ResourceUpdateQueue* queue,
37 PrioritizedResource* texture,
38 const gfx::Rect& source_rect,
39 const gfx::Vector2d& dest_offset,
40 bool partial_update) {
41 // Source rect should never go outside the image pixels, even if this
42 // is requested because the texture extends outside the image.
43 gfx::Rect clipped_source_rect = source_rect;
44 gfx::Rect image_rect = gfx::Rect(0, 0, bitmap_.width(), bitmap_.height());
45 clipped_source_rect.Intersect(image_rect);
47 gfx::Vector2d clipped_dest_offset =
48 dest_offset +
49 gfx::Vector2d(clipped_source_rect.origin() - source_rect.origin());
51 ResourceUpdate upload = ResourceUpdate::Create(
52 texture, &bitmap_, image_rect, clipped_source_rect, clipped_dest_offset);
53 if (partial_update)
54 queue->AppendPartialUpload(upload);
55 else
56 queue->AppendFullUpload(upload);
59 void ImageLayerUpdater::SetBitmap(const SkBitmap& bitmap) {
60 DCHECK(bitmap.pixelRef());
61 bitmap_ = bitmap;
64 bool ImageLayerUpdater::UsingBitmap(const SkBitmap& bitmap) const {
65 return bitmap.pixelRef() == bitmap_.pixelRef();
68 } // namespace cc