summaryrefslogtreecommitdiff
path: root/chromium/cc/resources/image_layer_updater.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/cc/resources/image_layer_updater.cc')
-rw-r--r--chromium/cc/resources/image_layer_updater.cc68
1 files changed, 68 insertions, 0 deletions
diff --git a/chromium/cc/resources/image_layer_updater.cc b/chromium/cc/resources/image_layer_updater.cc
new file mode 100644
index 00000000000..470f518b424
--- /dev/null
+++ b/chromium/cc/resources/image_layer_updater.cc
@@ -0,0 +1,68 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/resources/image_layer_updater.h"
+#include "cc/resources/prioritized_resource.h"
+#include "cc/resources/resource_update_queue.h"
+
+namespace cc {
+
+ImageLayerUpdater::Resource::Resource(ImageLayerUpdater* updater,
+ scoped_ptr<PrioritizedResource> texture)
+ : LayerUpdater::Resource(texture.Pass()), updater_(updater) {}
+
+ImageLayerUpdater::Resource::~Resource() {}
+
+void ImageLayerUpdater::Resource::Update(ResourceUpdateQueue* queue,
+ gfx::Rect source_rect,
+ gfx::Vector2d dest_offset,
+ bool partial_update) {
+ updater_->UpdateTexture(
+ queue, texture(), source_rect, dest_offset, partial_update);
+}
+
+// static
+scoped_refptr<ImageLayerUpdater> ImageLayerUpdater::Create() {
+ return make_scoped_refptr(new ImageLayerUpdater());
+}
+
+scoped_ptr<LayerUpdater::Resource> ImageLayerUpdater::CreateResource(
+ PrioritizedResourceManager* manager) {
+ return scoped_ptr<LayerUpdater::Resource>(
+ new Resource(this, PrioritizedResource::Create(manager)));
+}
+
+void ImageLayerUpdater::UpdateTexture(ResourceUpdateQueue* queue,
+ PrioritizedResource* texture,
+ gfx::Rect source_rect,
+ gfx::Vector2d dest_offset,
+ bool partial_update) {
+ // Source rect should never go outside the image pixels, even if this
+ // is requested because the texture extends outside the image.
+ gfx::Rect clipped_source_rect = source_rect;
+ gfx::Rect image_rect = gfx::Rect(0, 0, bitmap_.width(), bitmap_.height());
+ clipped_source_rect.Intersect(image_rect);
+
+ gfx::Vector2d clipped_dest_offset =
+ dest_offset +
+ gfx::Vector2d(clipped_source_rect.origin() - source_rect.origin());
+
+ ResourceUpdate upload = ResourceUpdate::Create(
+ texture, &bitmap_, image_rect, clipped_source_rect, clipped_dest_offset);
+ if (partial_update)
+ queue->AppendPartialUpload(upload);
+ else
+ queue->AppendFullUpload(upload);
+}
+
+void ImageLayerUpdater::SetBitmap(const SkBitmap& bitmap) {
+ DCHECK(bitmap.pixelRef());
+ bitmap_ = bitmap;
+}
+
+bool ImageLayerUpdater::UsingBitmap(const SkBitmap& bitmap) const {
+ return bitmap.pixelRef() == bitmap_.pixelRef();
+}
+
+} // namespace cc