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