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.
5 #include "cc/quads/texture_draw_quad.h"
7 #include "base/logging.h"
8 #include "base/trace_event/trace_event_argument.h"
9 #include "base/values.h"
10 #include "cc/base/math_util.h"
11 #include "ui/gfx/geometry/vector2d_f.h"
15 TextureDrawQuad::TextureDrawQuad()
16 : premultiplied_alpha(false),
17 background_color(SK_ColorTRANSPARENT
),
19 nearest_neighbor(false) {
20 this->vertex_opacity
[0] = 0.f
;
21 this->vertex_opacity
[1] = 0.f
;
22 this->vertex_opacity
[2] = 0.f
;
23 this->vertex_opacity
[3] = 0.f
;
26 void TextureDrawQuad::SetNew(const SharedQuadState
* shared_quad_state
,
27 const gfx::Rect
& rect
,
28 const gfx::Rect
& opaque_rect
,
29 const gfx::Rect
& visible_rect
,
31 bool premultiplied_alpha
,
32 const gfx::PointF
& uv_top_left
,
33 const gfx::PointF
& uv_bottom_right
,
34 SkColor background_color
,
35 const float vertex_opacity
[4],
37 bool nearest_neighbor
) {
38 bool needs_blending
= vertex_opacity
[0] != 1.0f
|| vertex_opacity
[1] != 1.0f
39 || vertex_opacity
[2] != 1.0f
|| vertex_opacity
[3] != 1.0f
;
40 DrawQuad::SetAll(shared_quad_state
, DrawQuad::TEXTURE_CONTENT
, rect
,
41 opaque_rect
, visible_rect
, needs_blending
);
42 resources
.ids
[kResourceIdIndex
] = resource_id
;
44 this->premultiplied_alpha
= premultiplied_alpha
;
45 this->uv_top_left
= uv_top_left
;
46 this->uv_bottom_right
= uv_bottom_right
;
47 this->background_color
= background_color
;
48 this->vertex_opacity
[0] = vertex_opacity
[0];
49 this->vertex_opacity
[1] = vertex_opacity
[1];
50 this->vertex_opacity
[2] = vertex_opacity
[2];
51 this->vertex_opacity
[3] = vertex_opacity
[3];
52 this->y_flipped
= y_flipped
;
53 this->nearest_neighbor
= nearest_neighbor
;
56 void TextureDrawQuad::SetAll(const SharedQuadState
* shared_quad_state
,
57 const gfx::Rect
& rect
,
58 const gfx::Rect
& opaque_rect
,
59 const gfx::Rect
& visible_rect
,
62 gfx::Size resource_size_in_pixels
,
64 bool premultiplied_alpha
,
65 const gfx::PointF
& uv_top_left
,
66 const gfx::PointF
& uv_bottom_right
,
67 SkColor background_color
,
68 const float vertex_opacity
[4],
70 bool nearest_neighbor
) {
71 DrawQuad::SetAll(shared_quad_state
, DrawQuad::TEXTURE_CONTENT
, rect
,
72 opaque_rect
, visible_rect
, needs_blending
);
73 resources
.ids
[kResourceIdIndex
] = resource_id
;
74 overlay_resources
.size_in_pixels
[kResourceIdIndex
] = resource_size_in_pixels
;
75 overlay_resources
.allow_overlay
[kResourceIdIndex
] = allow_overlay
;
77 this->premultiplied_alpha
= premultiplied_alpha
;
78 this->uv_top_left
= uv_top_left
;
79 this->uv_bottom_right
= uv_bottom_right
;
80 this->background_color
= background_color
;
81 this->vertex_opacity
[0] = vertex_opacity
[0];
82 this->vertex_opacity
[1] = vertex_opacity
[1];
83 this->vertex_opacity
[2] = vertex_opacity
[2];
84 this->vertex_opacity
[3] = vertex_opacity
[3];
85 this->y_flipped
= y_flipped
;
86 this->nearest_neighbor
= nearest_neighbor
;
89 const TextureDrawQuad
* TextureDrawQuad::MaterialCast(const DrawQuad
* quad
) {
90 DCHECK(quad
->material
== DrawQuad::TEXTURE_CONTENT
);
91 return static_cast<const TextureDrawQuad
*>(quad
);
94 void TextureDrawQuad::ExtendValue(base::trace_event::TracedValue
* value
) const {
95 value
->SetInteger("resource_id", resources
.ids
[kResourceIdIndex
]);
96 value
->SetBoolean("premultiplied_alpha", premultiplied_alpha
);
98 MathUtil::AddToTracedValue("uv_top_left", uv_top_left
, value
);
99 MathUtil::AddToTracedValue("uv_bottom_right", uv_bottom_right
, value
);
101 value
->SetInteger("background_color", background_color
);
103 value
->BeginArray("vertex_opacity");
104 for (size_t i
= 0; i
< 4; ++i
)
105 value
->AppendDouble(vertex_opacity
[i
]);
108 value
->SetBoolean("y_flipped", y_flipped
);
109 value
->SetBoolean("nearest_neighbor", nearest_neighbor
);
112 TextureDrawQuad::OverlayResources::OverlayResources() {
113 for (size_t i
= 0; i
< Resources::kMaxResourceIdCount
; ++i
)
114 allow_overlay
[i
] = false;