diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-13 00:55:37 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-13 00:55:37 +0000 |
commit | c0fc094f4b95fc55baace5d1452b6110f68cf167 (patch) | |
tree | 16dc1253142393c4325055ef69971fa4f91187f0 /chrome/browser/renderer_host/backing_store.h | |
parent | f0c7a263de099efa75d9f4122c16c0c0fcaa9677 (diff) | |
download | chromium_src-c0fc094f4b95fc55baace5d1452b6110f68cf167.zip chromium_src-c0fc094f4b95fc55baace5d1452b6110f68cf167.tar.gz chromium_src-c0fc094f4b95fc55baace5d1452b6110f68cf167.tar.bz2 |
Add the ability for the GPU process to be used to paint the backing store of a
tab. This is the first pass and is currently a bit buggy and incomplete.
This patch refactors the backing store to make it a virtual interface which is
then implemented by the platform-specific backing stores. This cleans up the
multi-platform aspects of the old code, and also makes it possible to create
different backing stores (such as ones in another process).
This renames the BackingStore::PaintRect function to PaintToBackingStore which
clears up what it does. I would often get confused and think that it paints
the backing store to the screen.
This makes a common way to capture backing store information and adds it to the
backing store API. This removed a bunch of ugly ifdefs.
This adds the ability for a backing store to specify that the TransportDIB
should not be freed by RenderWidgetHost when painting is complete. This is
necessary since the out-of-process version needs to use it after the
RenderWidget paint function has returned.
This pushes up the vector of copy_rect from RenderWidgetHost to the actual
BackingStores. This prevents us from sending duplicate data over IPC. It also
makes the common non-IPC case more efficient, since we end up setting up various
surfaces only once when there are multiple update rects.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/523028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36075 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host/backing_store.h')
-rw-r--r-- | chrome/browser/renderer_host/backing_store.h | 192 |
1 files changed, 44 insertions, 148 deletions
diff --git a/chrome/browser/renderer_host/backing_store.h b/chrome/browser/renderer_host/backing_store.h index 28640ba..a60adc2 100644 --- a/chrome/browser/renderer_host/backing_store.h +++ b/chrome/browser/renderer_host/backing_store.h @@ -1,185 +1,81 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_RENDERER_HOST_BACKING_STORE_H_ #define CHROME_BROWSER_RENDERER_HOST_BACKING_STORE_H_ +#include <vector> + #include "base/basictypes.h" -#include "base/gfx/rect.h" #include "base/gfx/size.h" #include "base/process.h" -#include "build/build_config.h" - -#if defined(OS_WIN) -#include <windows.h> -#elif defined(OS_MACOSX) -#include "base/scoped_cftyperef.h" -#include "skia/ext/platform_canvas.h" -#elif defined(OS_LINUX) -#include "chrome/common/x11_util.h" -#endif +#include "chrome/common/transport_dib.h" +class RenderProcessHost; class RenderWidgetHost; -class SkBitmap; -class TransportDIB; -typedef struct _GdkDrawable GdkDrawable; -// BackingStore ---------------------------------------------------------------- +namespace gfx { +class Rect; +} + +namespace skia { +class PlatformCanvas; +} // Represents a backing store for the pixels in a RenderWidgetHost. class BackingStore { public: -#if defined(OS_WIN) || defined(OS_MACOSX) - BackingStore(RenderWidgetHost* widget, const gfx::Size& size); -#elif defined(OS_LINUX) - // Create a backing store on the X server. The visual is an Xlib Visual - // describing the format of the target window and the depth is the color - // depth of the X window which will be drawn into. - BackingStore(RenderWidgetHost* widget, - const gfx::Size& size, - void* visual, - int depth); - - // This is for unittesting only. An object constructed using this constructor - // will silently ignore all paints - BackingStore(RenderWidgetHost* widget, const gfx::Size& size); -#endif - ~BackingStore(); + virtual ~BackingStore(); RenderWidgetHost* render_widget_host() const { return render_widget_host_; } const gfx::Size& size() { return size_; } - // The number of bytes that this backing store consumes. This should roughly - // be size_.GetArea() * bytes per pixel. - size_t MemorySize(); - -#if defined(OS_WIN) - HDC hdc() { return hdc_; } - - // Returns true if we should convert to the monitor profile when painting. - static bool ColorManagementEnabled(); -#elif defined(OS_MACOSX) - // A CGLayer that stores the contents of the backing store, cached in GPU - // memory if possible. - CGLayerRef cg_layer() { return cg_layer_; } - // A CGBitmapContext that stores the contents of the backing store if the - // corresponding Cocoa view has not been inserted into an NSWindow yet. - CGContextRef cg_bitmap() { return cg_bitmap_; } - - // Paint the layer into a graphics context--if the target is a window, - // this should be a GPU->GPU copy (and therefore very fast). - void PaintToRect(const gfx::Rect& dest_rect, CGContextRef target); -#elif defined(OS_LINUX) - Display* display() const { return display_; } - XID root_window() const { return root_window_; } - - // Copy from the server-side backing store to the target window - // display: the display of the backing store and target window - // damage: the area to copy - // target: the X id of the target window - void ShowRect(const gfx::Rect& damage, XID target); - - // Paints the server-side backing store data to a SkBitmap. On failure, the - // return bitmap will be isNull(). - SkBitmap PaintRectToBitmap(const gfx::Rect& rect); -#endif - -#if defined(TOOLKIT_GTK) - // Paint the backing store into the target's |dest_rect|. - void PaintToRect(const gfx::Rect& dest_rect, GdkDrawable* target); -#endif + // The number of bytes that this backing store consumes. The default + // implementation just assumes there's 32 bits per pixel over the current + // size of the screen. Implementations may override this if they have more + // information about the color depth. + virtual size_t MemorySize(); // Paints the bitmap from the renderer onto the backing store. bitmap_rect - // gives the location of bitmap, and copy_rect specifies the subregion of + // gives the location of bitmap, and copy_rects specifies the subregion(s) of // the backingstore to be painted from the bitmap. - void PaintRect(base::ProcessHandle process, - TransportDIB* bitmap, - const gfx::Rect& bitmap_rect, - const gfx::Rect& copy_rect); + // + // The value placed into |*painted_synchronously| indicates if the paint was + // completed synchronously and the TransportDIB can be freed. False means that + // the backing store may still be using the transport DIB and it will manage + // notifying the RenderWidgetHost that it's done with it via + // DonePaintingToBackingStore(). + virtual void PaintToBackingStore( + RenderProcessHost* process, + TransportDIB::Id bitmap, + const gfx::Rect& bitmap_rect, + const std::vector<gfx::Rect>& copy_rects, + bool* painted_synchronously) = 0; + + // Extracts the gives subset of the backing store and copies it to the given + // PlatformCanvas. The PlatformCanvas should not be initialized. This function + // will call initialize() with the correct size. The return value indicates + // success. + virtual bool CopyFromBackingStore(const gfx::Rect& rect, + skia::PlatformCanvas* output) = 0; // Scrolls the contents of clip_rect in the backing store by dx or dy (but dx // and dy cannot both be non-zero). - void ScrollRect(int dx, int dy, - const gfx::Rect& clip_rect, - const gfx::Size& view_size); + virtual void ScrollBackingStore(int dx, int dy, + const gfx::Rect& clip_rect, + const gfx::Size& view_size) = 0; + protected: + // Can only be constructed via subclasses. + BackingStore(RenderWidgetHost* widget, const gfx::Size& size); private: -#if defined(OS_MACOSX) - // Creates a CGLayer associated with its owner view's window's graphics - // context, sized properly for the backing store. Returns NULL if the owner - // is not in a window with a CGContext. cg_layer_ is assigned this method's - // result. - CGLayerRef CreateCGLayer(); - - // Creates a CGBitmapContext sized properly for the backing store. The - // owner view need not be in a window. cg_bitmap_ is assigned this method's - // result. - CGContextRef CreateCGBitmapContext(); -#endif - // The owner of this backing store. RenderWidgetHost* render_widget_host_; // The size of the backing store. gfx::Size size_; -#if defined(OS_WIN) - // The backing store dc. - HDC hdc_; - // Handle to the backing store dib. - HANDLE backing_store_dib_; - // Handle to the original bitmap in the dc. - HANDLE original_bitmap_; - // Number of bits per pixel of the screen. - int color_depth_; -#elif defined(OS_MACOSX) - scoped_cftyperef<CGContextRef> cg_bitmap_; - scoped_cftyperef<CGLayerRef> cg_layer_; -#elif defined(OS_LINUX) && defined(USE_GL) - Display* const display_; - - // The parent window for this backing store. - const XID root_window_; - - unsigned int texture_id_; // 0 when uninitialized. - - // The size of the texture loaded into GL. This is 0x0 when there is no - // texture loaded. This may be different than the size of the backing store - // because we could have been resized without yet getting the updated - // bitmap. - gfx::Size texture_size_; - -#elif defined(OS_LINUX) && !defined(USE_GL) - // Paints the bitmap from the renderer onto the backing store without - // using Xrender to composite the pixmaps. - void PaintRectWithoutXrender(TransportDIB* bitmap, - const gfx::Rect& bitmap_rect, - const gfx::Rect& copy_rect); - - // This is the connection to the X server where this backing store will be - // displayed. - Display* const display_; - // What flavor, if any, MIT-SHM (X shared memory) support we have. - const x11_util::SharedMemorySupport shared_memory_support_; - // If this is true, then we can use Xrender to composite our pixmaps. - const bool use_render_; - // If |use_render_| is false, this is the number of bits-per-pixel for |depth| - int pixmap_bpp_; - // if |use_render_| is false, we need the Visual to get the RGB masks. - void* const visual_; - // This is the depth of the target window. - const int visual_depth_; - // The parent window (probably a GtkDrawingArea) for this backing store. - const XID root_window_; - // This is a handle to the server side pixmap which is our backing store. - XID pixmap_; - // This is the RENDER picture pointing at |pixmap_|. - XID picture_; - // This is a default graphic context, used in XCopyArea - void* pixmap_gc_; -#endif - DISALLOW_COPY_AND_ASSIGN(BackingStore); }; |