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.
8 #include "CCSharedQuadState.h"
12 // WARNING! All CCXYZDrawQuad classes must remain PODs (plain old data).
13 // They are intended to be "serializable" by copying their raw bytes, so they
14 // must not contain any non-bit-copyable member variables!
16 // Furthermore, the class members need to be packed so they are aligned
17 // properly and don't have paddings/gaps, otherwise memory check tools
18 // like Valgrind will complain about uninitialized memory usage when
19 // transferring these classes over the wire.
22 // CCDrawQuad is a bag of data used for drawing a quad. Because different
23 // materials need different bits of per-quad data to render, classes that derive
24 // from CCDrawQuad store additional data in their derived instance. The Material
25 // enum is used to "safely" downcast to the derived class.
41 IntRect
quadRect() const { return m_quadRect
; }
42 const WebKit::WebTransformationMatrix
& quadTransform() const { return m_sharedQuadState
->quadTransform
; }
43 IntRect
visibleContentRect() const { return m_sharedQuadState
->visibleContentRect
; }
44 IntRect
clippedRectInTarget() const { return m_sharedQuadState
->clippedRectInTarget
; }
45 float opacity() const { return m_sharedQuadState
->opacity
; }
46 // For the purposes of blending, what part of the contents of this quad are opaque?
47 IntRect
opaqueRect() const;
48 bool needsBlending() const { return m_needsBlending
|| !opaqueRect().contains(m_quadVisibleRect
); }
50 // Allows changing the rect that gets drawn to make it smaller. Parameter passed
51 // in will be clipped to quadRect().
52 void setQuadVisibleRect(const IntRect
&);
53 IntRect
quadVisibleRect() const { return m_quadVisibleRect
; }
54 bool isDebugQuad() const { return m_material
== DebugBorder
; }
56 Material
material() const { return m_material
; }
58 // Returns transfer size of this object based on the derived class (by
59 // looking at the material type).
60 unsigned size() const;
62 PassOwnPtr
<CCDrawQuad
> copy(const CCSharedQuadState
* copiedSharedQuadState
) const;
64 const CCSharedQuadState
* sharedQuadState() const { return m_sharedQuadState
; }
65 int sharedQuadStateId() const { return m_sharedQuadStateId
; }
66 void setSharedQuadState(const CCSharedQuadState
*);
69 CCDrawQuad(const CCSharedQuadState
*, Material
, const IntRect
&);
71 // Stores state common to a large bundle of quads; kept separate for memory
72 // efficiency. There is special treatment to reconstruct these pointers
73 // during serialization.
74 const CCSharedQuadState
* m_sharedQuadState
;
75 int m_sharedQuadStateId
;
79 IntRect m_quadVisibleRect
;
81 // By default, the shared quad state determines whether or not this quad is
82 // opaque or needs blending. Derived classes can override with these
87 // Be default, this rect is empty. It is used when the shared quad state and above
88 // variables determine that the quad is not fully opaque but may be partially opaque.