bitmap_content_layer_updater.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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.
4
5#ifndef CC_RESOURCES_BITMAP_CONTENT_LAYER_UPDATER_H_
6#define CC_RESOURCES_BITMAP_CONTENT_LAYER_UPDATER_H_
7
8#include "cc/base/cc_export.h"
9#include "cc/resources/content_layer_updater.h"
10#include "skia/ext/refptr.h"
11
12class SkCanvas;
13
14namespace cc {
15
16class LayerPainter;
17class RenderingStatsInstrumenation;
18
19// This class rasterizes the content_rect into a skia bitmap canvas. It then
20// updates textures by copying from the canvas into the texture, using
21// MapSubImage if possible.
22class CC_EXPORT BitmapContentLayerUpdater : public ContentLayerUpdater {
23 public:
24  class Resource : public LayerUpdater::Resource {
25   public:
26    Resource(BitmapContentLayerUpdater* updater,
27             scoped_ptr<PrioritizedResource> resource);
28    virtual ~Resource();
29
30    virtual void Update(ResourceUpdateQueue* queue,
31                        gfx::Rect source_rect,
32                        gfx::Vector2d dest_offset,
33                        bool partial_update) OVERRIDE;
34
35   private:
36    BitmapContentLayerUpdater* updater_;
37
38    DISALLOW_COPY_AND_ASSIGN(Resource);
39  };
40
41  static scoped_refptr<BitmapContentLayerUpdater> Create(
42      scoped_ptr<LayerPainter> painter,
43      RenderingStatsInstrumentation* stats_instrumenation,
44      int layer_id);
45
46  virtual scoped_ptr<LayerUpdater::Resource> CreateResource(
47      PrioritizedResourceManager* manager) OVERRIDE;
48  virtual void PrepareToUpdate(gfx::Rect content_rect,
49                               gfx::Size tile_size,
50                               float contents_width_scale,
51                               float contents_height_scale,
52                               gfx::Rect* resulting_opaque_rect) OVERRIDE;
53  void UpdateTexture(ResourceUpdateQueue* queue,
54                     PrioritizedResource* resource,
55                     gfx::Rect source_rect,
56                     gfx::Vector2d dest_offset,
57                     bool partial_update);
58  virtual void SetOpaque(bool opaque) OVERRIDE;
59  virtual void ReduceMemoryUsage() OVERRIDE;
60
61 protected:
62  BitmapContentLayerUpdater(
63      scoped_ptr<LayerPainter> painter,
64      RenderingStatsInstrumentation* stats_instrumenation,
65      int layer_id);
66  virtual ~BitmapContentLayerUpdater();
67
68  skia::RefPtr<SkCanvas> canvas_;
69  gfx::Size canvas_size_;
70  bool opaque_;
71
72 private:
73  DISALLOW_COPY_AND_ASSIGN(BitmapContentLayerUpdater);
74};
75
76}  // namespace cc
77
78#endif  // CC_RESOURCES_BITMAP_CONTENT_LAYER_UPDATER_H_
79