synchronous_compositor.h revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
1// Copyright 2013 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_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_ 6#define CONTENT_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_ 7 8#include "base/memory/ref_counted.h" 9#include "content/common/content_export.h" 10#include "gpu/command_buffer/service/in_process_command_buffer.h" 11#include "ui/gfx/rect.h" 12#include "ui/gfx/size.h" 13 14class SkCanvas; 15 16namespace cc { 17class CompositorFrame; 18class CompositorFrameAck; 19} 20 21namespace gfx { 22class Transform; 23}; 24 25namespace gpu { 26class GLInProcessContext; 27} 28 29namespace content { 30 31class SynchronousCompositorClient; 32class WebContents; 33 34struct CONTENT_EXPORT SynchronousCompositorMemoryPolicy { 35 // Memory limit for rendering and pre-rendering. 36 size_t bytes_limit; 37 38 // Limit of number of GL resources used for rendering and pre-rendering. 39 size_t num_resources_limit; 40 41 SynchronousCompositorMemoryPolicy(); 42 43 bool operator==(const SynchronousCompositorMemoryPolicy& other) const; 44 bool operator!=(const SynchronousCompositorMemoryPolicy& other) const; 45}; 46 47// Interface for embedders that wish to direct compositing operations 48// synchronously under their own control. Only meaningful when the 49// kEnableSyncrhonousRendererCompositor flag is specified. 50class CONTENT_EXPORT SynchronousCompositor { 51 public: 52 // Must be called once per WebContents instance. Will create the compositor 53 // instance as needed, but only if |client| is non-NULL. 54 static void SetClientForWebContents(WebContents* contents, 55 SynchronousCompositorClient* client); 56 57 // Allows changing or resetting the client to NULL (this must be used if 58 // the client is being deleted prior to the DidDestroyCompositor() call 59 // being received by the client). Ownership of |client| remains with 60 // the caller. 61 virtual void SetClient(SynchronousCompositorClient* client) = 0; 62 63 static void SetGpuService( 64 scoped_refptr<gpu::InProcessCommandBuffer::Service> service); 65 66 // Synchronously initialize compositor for hardware draw. Can only be called 67 // while compositor is in software only mode, either after compositor is 68 // first created or after ReleaseHwDraw is called. It is invalid to 69 // DemandDrawHw before this returns true. 70 virtual bool InitializeHwDraw() = 0; 71 72 // Reverse of InitializeHwDraw above. Can only be called while hardware draw 73 // is already initialized. Brings compositor back to software only mode and 74 // releases all hardware resources. 75 virtual void ReleaseHwDraw() = 0; 76 77 // Get the share context of the compositor. The returned context is owned 78 // by the compositor and is only valid between InitializeHwDraw and 79 // ReleaseHwDraw. 80 virtual gpu::GLInProcessContext* GetShareContext() = 0; 81 82 // "On demand" hardware draw. The content is first clipped to |damage_area|, 83 // then transformed through |transform|, and finally clipped to |view_size|. 84 virtual scoped_ptr<cc::CompositorFrame> DemandDrawHw( 85 gfx::Size surface_size, 86 const gfx::Transform& transform, 87 gfx::Rect viewport, 88 gfx::Rect clip) = 0; 89 90 // For delegated rendering, return resources from parent compositor to this. 91 // Note that all resources must be returned before ReleaseHwDraw. 92 virtual void ReturnResources(const cc::CompositorFrameAck& frame_ack) = 0; 93 94 // "On demand" SW draw, into the supplied canvas (observing the transform 95 // and clip set there-in). 96 virtual bool DemandDrawSw(SkCanvas* canvas) = 0; 97 98 // Set the memory limit policy of this compositor. 99 virtual void SetMemoryPolicy( 100 const SynchronousCompositorMemoryPolicy& policy) = 0; 101 102 // Should be called by the embedder after the embedder had modified the 103 // scroll offset of the root layer (as returned by 104 // SynchronousCompositorClient::GetTotalRootLayerScrollOffset). 105 virtual void DidChangeRootLayerScrollOffset() = 0; 106 107 protected: 108 virtual ~SynchronousCompositor() {} 109}; 110 111} // namespace content 112 113#endif // CONTENT_PUBLIC_BROWSER_ANDROID_SYNCHRONOUS_COMPOSITOR_H_ 114