Chromium Code Reviews| Index: cc/caching_bitmap_canvas_layer_texture_updater.cc |
| diff --git a/cc/caching_bitmap_canvas_layer_texture_updater.cc b/cc/caching_bitmap_canvas_layer_texture_updater.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8e15c2d3ff9ca3b58c657019759d1e4d847b1b4d |
| --- /dev/null |
| +++ b/cc/caching_bitmap_canvas_layer_texture_updater.cc |
| @@ -0,0 +1,71 @@ |
| +// 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 "config.h" |
| + |
| +#include "caching_bitmap_canvas_layer_texture_updater.h" |
| + |
| +#include "LayerPainterChromium.h" |
| +#include "skia/ext/platform_canvas.h" |
| + |
| +namespace cc { |
| + |
| +PassRefPtr<CachingBitmapCanvasLayerTextureUpdater> |
| +CachingBitmapCanvasLayerTextureUpdater::Create( |
| + PassOwnPtr<LayerPainterChromium> painter) { |
| + return adoptRef(new CachingBitmapCanvasLayerTextureUpdater(painter)); |
| +} |
| + |
| +CachingBitmapCanvasLayerTextureUpdater::CachingBitmapCanvasLayerTextureUpdater( |
| + PassOwnPtr<LayerPainterChromium> painter) |
| + : BitmapCanvasLayerTextureUpdater(painter), |
| + texture_needs_upload_(false) { |
| +} |
| + |
| +void CachingBitmapCanvasLayerTextureUpdater::prepareToUpdate( |
| + const IntRect& content_rect, |
| + const IntSize& tile_size, |
| + float contents_width_scale, |
| + float contents_height_scale, |
| + IntRect& resulting_opaque_rect, |
| + CCRenderingStats& stats) { |
| + BitmapCanvasLayerTextureUpdater::prepareToUpdate(content_rect, |
| + tile_size, |
| + contents_width_scale, |
| + contents_height_scale, |
| + resulting_opaque_rect, |
| + stats); |
| + |
| + const SkBitmap& new_bitmap = m_canvas->getDevice()->accessBitmap(false); |
| + SkAutoLockPixels lock(new_bitmap); |
| + ASSERT(new_bitmap.bytesPerPixel() > 0); |
| + texture_needs_upload_ = new_bitmap.config() != cached_bitmap_.config() || |
| + new_bitmap.height() != cached_bitmap_.height() || |
|
jamesr
2012/10/02 23:29:49
this doesn't quite align
|
| + new_bitmap.width() != cached_bitmap_.width() || |
| + memcmp(new_bitmap.getPixels(), |
| + cached_bitmap_.getPixels(), |
| + new_bitmap.getSafeSize()); |
| +} |
| + |
| +void CachingBitmapCanvasLayerTextureUpdater::updateTextureRect( |
| + CCResourceProvider* resource_provider, |
| + CCPrioritizedTexture* texture, |
| + const IntRect& source_rect, |
| + const IntSize& dest_offset) { |
| + if (!texture_needs_upload_) |
| + return; |
| + |
| + BitmapCanvasLayerTextureUpdater::updateTextureRect( |
| + resource_provider, |
| + texture, |
| + source_rect, |
| + dest_offset); |
| + |
| + const SkBitmap& new_bitmap = m_canvas->getDevice()->accessBitmap(false); |
| + SkAutoLockPixels lock(new_bitmap); |
| + // TODO(wjmaclean): check return status here? |
| + new_bitmap.deepCopyTo(&cached_bitmap_, new_bitmap.config()); |
| +} |
| + |
| +} // namespace cc |