- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / backing_store.h
1 // Copyright (c) 2012 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 CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "content/common/content_export.h"
13 #include "ui/gfx/size.h"
14 #include "ui/gfx/vector2d.h"
15 #include "ui/surface/transport_dib.h"
16
17 class RenderProcessHost;
18
19 namespace gfx {
20 class Rect;
21 }
22
23 namespace skia {
24 class PlatformBitmap;
25 }
26
27 namespace content {
28 class RenderProcessHost;
29 class RenderWidgetHost;
30
31 // Represents a backing store for the pixels in a RenderWidgetHost.
32 class CONTENT_EXPORT BackingStore {
33  public:
34   virtual ~BackingStore();
35
36   RenderWidgetHost* render_widget_host() const {
37     return render_widget_host_;
38   }
39   const gfx::Size& size() { return size_; }
40
41   // The number of bytes that this backing store consumes. The default
42   // implementation just assumes there's 32 bits per pixel over the current
43   // size of the screen. Implementations may override this if they have more
44   // information about the color depth.
45   virtual size_t MemorySize();
46
47   // Paints the bitmap from the renderer onto the backing store. bitmap_rect
48   // gives the location of bitmap, and copy_rects specifies the subregion(s) of
49   // the backingstore to be painted from the bitmap. All coordinates are in
50   // DIPs. |scale_factor| contains the expected device scale factor of the
51   // backing store.
52   //
53   // PaintToBackingStore does not need to guarantee that this has happened by
54   // the time it returns, in which case it will set |scheduled_callback| to
55   // true and will call |callback| when completed.
56   virtual void PaintToBackingStore(
57       RenderProcessHost* process,
58       TransportDIB::Id bitmap,
59       const gfx::Rect& bitmap_rect,
60       const std::vector<gfx::Rect>& copy_rects,
61       float scale_factor,
62       const base::Closure& completion_callback,
63       bool* scheduled_completion_callback) = 0;
64
65   // Extracts the gives subset of the backing store and copies it to the given
66   // PlatformCanvas. The PlatformCanvas should not be initialized. This function
67   // will call initialize() with the correct size. The return value indicates
68   // success.
69   virtual bool CopyFromBackingStore(const gfx::Rect& rect,
70                                     skia::PlatformBitmap* output) = 0;
71
72   // Scrolls the contents of clip_rect in the backing store by |delta| (but
73   // |delta|.x() and |delta|.y() cannot both be non-zero).
74   virtual void ScrollBackingStore(const gfx::Vector2d& delta,
75                                   const gfx::Rect& clip_rect,
76                                   const gfx::Size& view_size) = 0;
77  protected:
78   // Can only be constructed via subclasses.
79   BackingStore(RenderWidgetHost* widget, const gfx::Size& size);
80
81  private:
82   // The owner of this backing store.
83   RenderWidgetHost* render_widget_host_;
84
85   // The size of the backing store.
86   gfx::Size size_;
87
88   DISALLOW_COPY_AND_ASSIGN(BackingStore);
89 };
90
91 }  // namespace content
92
93 #endif  // CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_H_