summaryrefslogtreecommitdiffstats
path: root/cc/caching_bitmap_canvas_layer_texture_updater.cc
blob: 7d2c85f1e6c3b04008f5df6f920edff04893c614 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 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),
      pixels_did_change_(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);
  pixels_did_change_ = new_bitmap.config() != cached_bitmap_.config() ||
                       new_bitmap.height() != cached_bitmap_.height() ||
                       new_bitmap.width() != cached_bitmap_.width() ||
                       memcmp(new_bitmap.getPixels(),
                              cached_bitmap_.getPixels(),
                              new_bitmap.getSafeSize());

  if (pixels_did_change_)
    new_bitmap.deepCopyTo(&cached_bitmap_, new_bitmap.config());
}

bool CachingBitmapCanvasLayerTextureUpdater::pixelsDidChange() const
{
  return pixels_did_change_;
}

}  // namespace cc