12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2011 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CC_QUADS_RENDER_PASS_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CC_QUADS_RENDER_PASS_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include <utility> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h" 11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/callback.h" 127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/containers/hash_tables.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/base/cc_export.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/base/scoped_ptr_vector.h" 151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "cc/quads/list_container.h" 1603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "cc/quads/render_pass_id.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "skia/ext/refptr.h" 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/rect.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/rect_f.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/transform.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 22ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochnamespace base { 235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace debug { 245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class TracedValue; 255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 26ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochclass Value; 27ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}; 28ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace cc { 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DrawQuad; 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class CopyOutputRequest; 331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass RenderPassDrawQuad; 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class SharedQuadState; 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A list of DrawQuad objects, sorted internally in front-to-back order. 371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass QuadList : public ListContainer<DrawQuad> { 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci explicit QuadList(size_t default_size_to_reserve); 401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci typedef QuadList::ReverseIterator BackToFrontIterator; 421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci typedef QuadList::ConstReverseIterator ConstBackToFrontIterator; 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) inline BackToFrontIterator BackToFrontBegin() { return rbegin(); } 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) inline BackToFrontIterator BackToFrontEnd() { return rend(); } 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) inline ConstBackToFrontIterator BackToFrontBegin() const { return rbegin(); } 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) inline ConstBackToFrontIterator BackToFrontEnd() const { return rend(); } 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef ScopedPtrVector<SharedQuadState> SharedQuadStateList; 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class CC_EXPORT RenderPass { 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ~RenderPass(); 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static scoped_ptr<RenderPass> Create(); 57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) static scoped_ptr<RenderPass> Create(size_t num_layers); 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // A shallow copy of the render pass, which does not include its quads or copy 604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // requests. 6103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) scoped_ptr<RenderPass> Copy(RenderPassId new_id) const; 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // A deep copy of the render passes in the list including the quads. 644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) static void CopyAll(const ScopedPtrVector<RenderPass>& in, 654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ScopedPtrVector<RenderPass>* out); 664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 6703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) void SetNew(RenderPassId id, 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Rect& output_rect, 69c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const gfx::Rect& damage_rect, 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Transform& transform_to_root_target); 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) void SetAll(RenderPassId id, 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Rect& output_rect, 74c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const gfx::Rect& damage_rect, 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Transform& transform_to_root_target, 76effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch bool has_transparent_background); 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void AsValueInto(base::debug::TracedValue* dict) const; 79ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 80010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) SharedQuadState* CreateAndAppendSharedQuadState(); 811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 82116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch template <typename DrawQuadType> 83116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DrawQuadType* CreateAndAppendDrawQuad() { 841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return quad_list.AllocateAndConstruct<DrawQuadType>(); 85116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 86116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 87116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch RenderPassDrawQuad* CopyFromAndAppendRenderPassDrawQuad( 88116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const RenderPassDrawQuad* quad, 89116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const SharedQuadState* shared_quad_state, 9003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) RenderPassId render_pass_id); 91116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DrawQuad* CopyFromAndAppendDrawQuad(const DrawQuad* quad, 92116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const SharedQuadState* shared_quad_state); 93010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Uniquely identifies the render pass in the compositor's current frame. 9503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) RenderPassId id; 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // These are in the space of the render pass' physical pixels. 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect output_rect; 99c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch gfx::Rect damage_rect; 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Transforms from the origin of the |output_rect| to the origin of the root 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // render pass' |output_rect|. 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Transform transform_to_root_target; 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If false, the pixels in the render pass' texture are all opaque. 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool has_transparent_background; 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // If non-empty, the renderer should produce a copy of the render pass' 109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // contents as a bitmap, and give a copy of the bitmap to each callback in 110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // this list. This property should not be serialized between compositors, as 111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // it only makes sense in the root compositor. 11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ScopedPtrVector<CopyOutputRequest> copy_requests; 113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) QuadList quad_list; 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SharedQuadStateList shared_quad_state_list; 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 118f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) explicit RenderPass(size_t num_layers); 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderPass(); 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 121eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch private: 122116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch template <typename DrawQuadType> 123116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DrawQuadType* CopyFromAndAppendTypedDrawQuad(const DrawQuad* quad) { 1241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return quad_list.AllocateAndCopyFrom(DrawQuadType::MaterialCast(quad)); 125116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 126116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(RenderPass); 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} // namespace cc 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace BASE_HASH_NAMESPACE { 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(COMPILER_MSVC) 13403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)inline size_t hash_value(const cc::RenderPassId& key) { 135bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return base::HashPair(key.layer_id, key.index); 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#elif defined(COMPILER_GCC) 13803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)template <> 13903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)struct hash<cc::RenderPassId> { 14003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) size_t operator()(cc::RenderPassId key) const { 141bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch return base::HashPair(key.layer_id, key.index); 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#else 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#error define a hash function for your compiler 146c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif // COMPILER 147eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} // namespace BASE_HASH_NAMESPACE 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace cc { 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef ScopedPtrVector<RenderPass> RenderPassList; 15103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)typedef base::hash_map<RenderPassId, RenderPass*> RenderPassIdHashMap; 152c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} // namespace cc 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CC_QUADS_RENDER_PASS_H_ 155