1// Copyright 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 CC_OUTPUT_RENDERER_H_ 6#define CC_OUTPUT_RENDERER_H_ 7 8#include "base/basictypes.h" 9#include "cc/base/cc_export.h" 10#include "cc/quads/render_pass.h" 11#include "cc/trees/layer_tree_host.h" 12 13namespace cc { 14 15class CompositorFrameAck; 16class CompositorFrameMetadata; 17class ScopedResource; 18 19class CC_EXPORT RendererClient { 20 public: 21 // Draw viewport in non-y-flipped window space. Note that while a draw is in 22 // progress, this is guaranteed to be contained within the output surface 23 // size. 24 virtual gfx::Rect DeviceViewport() const = 0; 25 virtual gfx::Rect DeviceClip() const = 0; 26 27 virtual float DeviceScaleFactor() const = 0; 28 virtual const LayerTreeSettings& Settings() const = 0; 29 virtual void SetFullRootLayerDamage() = 0; 30 virtual bool HasImplThread() const = 0; 31 virtual bool ShouldClearRootRenderPass() const = 0; 32 virtual CompositorFrameMetadata MakeCompositorFrameMetadata() const = 0; 33 virtual bool AllowPartialSwap() const = 0; 34 virtual bool ExternalStencilTestEnabled() const = 0; 35 36 protected: 37 virtual ~RendererClient() {} 38}; 39 40class CC_EXPORT Renderer { 41 public: 42 virtual ~Renderer() {} 43 44 virtual const RendererCapabilities& Capabilities() const = 0; 45 46 const LayerTreeSettings& Settings() const { return client_->Settings(); } 47 48 virtual void ViewportChanged() {} 49 50 virtual bool CanReadPixels() const = 0; 51 52 virtual void DecideRenderPassAllocationsForFrame( 53 const RenderPassList& render_passes_in_draw_order) {} 54 virtual bool HaveCachedResourcesForRenderPassId(RenderPass::Id id) const; 55 56 // This passes ownership of the render passes to the renderer. It should 57 // consume them, and empty the list. 58 virtual void DrawFrame(RenderPassList* render_passes_in_draw_order, 59 bool disable_picture_quad_image_filtering) = 0; 60 61 // Waits for rendering to finish. 62 virtual void Finish() = 0; 63 64 virtual void DoNoOp() {} 65 66 // Puts backbuffer onscreen. 67 virtual void SwapBuffers() = 0; 68 virtual void ReceiveSwapBuffersAck(const CompositorFrameAck& ack) {} 69 70 virtual void GetFramebufferPixels(void* pixels, gfx::Rect rect) = 0; 71 72 virtual bool IsContextLost(); 73 74 virtual void SetVisible(bool visible) = 0; 75 76 virtual void SendManagedMemoryStats(size_t bytes_visible, 77 size_t bytes_visible_and_nearby, 78 size_t bytes_allocated) = 0; 79 80 virtual void SetDiscardBackBufferWhenNotVisible(bool discard) = 0; 81 82 protected: 83 explicit Renderer(RendererClient* client) 84 : client_(client) {} 85 86 RendererClient* client_; 87 88 private: 89 DISALLOW_COPY_AND_ASSIGN(Renderer); 90}; 91 92} // namespace cc 93 94#endif // CC_OUTPUT_RENDERER_H_ 95