Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / renderer_host / backing_store.h
blobba36920401c19d52b954c270d7788a3f21a4628f
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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_H_
8 #include <vector>
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"
17 class RenderProcessHost;
19 namespace gfx {
20 class Rect;
23 namespace skia {
24 class PlatformBitmap;
27 namespace content {
28 class RenderProcessHost;
29 class RenderWidgetHost;
31 // Represents a backing store for the pixels in a RenderWidgetHost.
32 class CONTENT_EXPORT BackingStore {
33 public:
34 virtual ~BackingStore();
36 RenderWidgetHost* render_widget_host() const {
37 return render_widget_host_;
39 const gfx::Size& size() { return size_; }
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();
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.
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;
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;
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);
81 private:
82 // The owner of this backing store.
83 RenderWidgetHost* render_widget_host_;
85 // The size of the backing store.
86 gfx::Size size_;
88 DISALLOW_COPY_AND_ASSIGN(BackingStore);
91 } // namespace content
93 #endif // CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_H_