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_CONTENT_LAYER_UPDATER_H_
6#define CC_RESOURCES_CONTENT_LAYER_UPDATER_H_
7
8#include "cc/base/cc_export.h"
9#include "cc/resources/layer_updater.h"
10#include "ui/gfx/rect.h"
11
12class SkCanvas;
13
14namespace cc {
15
16class LayerPainter;
17class RenderingStatsInstrumentation;
18
19// Base class for BitmapContentLayerUpdater and
20// SkPictureContentLayerUpdater that reduces code duplication between
21// their respective PaintContents implementations.
22class CC_EXPORT ContentLayerUpdater : public LayerUpdater {
23 public:
24  void set_rendering_stats_instrumentation(RenderingStatsInstrumentation* rsi);
25  virtual void SetOpaque(bool opaque) OVERRIDE;
26  virtual void SetFillsBoundsCompletely(bool fills_bounds) OVERRIDE;
27  virtual void SetBackgroundColor(SkColor background_color) OVERRIDE;
28
29 protected:
30  ContentLayerUpdater(scoped_ptr<LayerPainter> painter,
31                      RenderingStatsInstrumentation* stats_instrumentation,
32                      int layer_id);
33  virtual ~ContentLayerUpdater();
34
35  // Paints the contents. |content_size| size of the underlying layer in
36  // layer's content space. |paint_rect| bounds to paint in content space of the
37  // layer. Both |content_size| and |paint_rect| are in pixels.
38  void PaintContents(SkCanvas* canvas,
39                     const gfx::Size& layer_content_size,
40                     const gfx::Rect& paint_rect,
41                     float contents_width_scale,
42                     float contents_height_scale);
43  gfx::Rect paint_rect() const { return paint_rect_; }
44
45  bool layer_is_opaque() const { return layer_is_opaque_; }
46  bool layer_fills_bounds_completely() const {
47    return layer_fills_bounds_completely_;
48  }
49
50  SkColor background_color() const { return background_color_; }
51
52  RenderingStatsInstrumentation* rendering_stats_instrumentation_;
53  int layer_id_;
54
55  // True when it is known that all output pixels will be opaque.
56  bool layer_is_opaque_;
57  // True when it is known that all output pixels will be filled.
58  bool layer_fills_bounds_completely_;
59
60 private:
61  gfx::Rect paint_rect_;
62  scoped_ptr<LayerPainter> painter_;
63  SkColor background_color_;
64
65  DISALLOW_COPY_AND_ASSIGN(ContentLayerUpdater);
66};
67
68}  // namespace cc
69
70#endif  // CC_RESOURCES_CONTENT_LAYER_UPDATER_H_
71