1 // Copyright 2011 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/render_pass_draw_quad.h"
7 #include "base/trace_event/trace_event_argument.h"
8 #include "base/values.h"
9 #include "cc/base/math_util.h"
10 #include "cc/debug/traced_value.h"
11 #include "third_party/skia/include/core/SkImageFilter.h"
15 RenderPassDrawQuad::RenderPassDrawQuad()
16 : render_pass_id(RenderPassId(-1, -1)) {
19 RenderPassDrawQuad::~RenderPassDrawQuad() {
22 void RenderPassDrawQuad::SetNew(const SharedQuadState
* shared_quad_state
,
23 const gfx::Rect
& rect
,
24 const gfx::Rect
& visible_rect
,
25 RenderPassId render_pass_id
,
26 ResourceId mask_resource_id
,
27 const gfx::Vector2dF
& mask_uv_scale
,
28 const gfx::Size
& mask_texture_size
,
29 const FilterOperations
& filters
,
30 const gfx::Vector2dF
& filters_scale
,
31 const FilterOperations
& background_filters
) {
32 DCHECK_GT(render_pass_id
.layer_id
, 0);
33 DCHECK_GE(render_pass_id
.index
, 0);
35 gfx::Rect opaque_rect
;
36 bool needs_blending
= false;
37 SetAll(shared_quad_state
,
51 void RenderPassDrawQuad::SetAll(const SharedQuadState
* shared_quad_state
,
52 const gfx::Rect
& rect
,
53 const gfx::Rect
& opaque_rect
,
54 const gfx::Rect
& visible_rect
,
56 RenderPassId render_pass_id
,
57 ResourceId mask_resource_id
,
58 const gfx::Vector2dF
& mask_uv_scale
,
59 const gfx::Size
& mask_texture_size
,
60 const FilterOperations
& filters
,
61 const gfx::Vector2dF
& filters_scale
,
62 const FilterOperations
& background_filters
) {
63 DCHECK_GT(render_pass_id
.layer_id
, 0);
64 DCHECK_GE(render_pass_id
.index
, 0);
66 DrawQuad::SetAll(shared_quad_state
, DrawQuad::RENDER_PASS
, rect
, opaque_rect
,
67 visible_rect
, needs_blending
);
68 this->render_pass_id
= render_pass_id
;
69 resources
.ids
[kMaskResourceIdIndex
] = mask_resource_id
;
70 resources
.count
= mask_resource_id
? 1 : 0;
71 this->mask_uv_scale
= mask_uv_scale
;
72 this->mask_texture_size
= mask_texture_size
;
73 this->filters
= filters
;
74 this->filters_scale
= filters_scale
;
75 this->background_filters
= background_filters
;
78 gfx::RectF
RenderPassDrawQuad::MaskUVRect() const {
79 gfx::RectF
mask_uv_rect((mask_uv_scale
.x() * rect
.x()) / rect
.width(),
80 (mask_uv_scale
.y() * rect
.y()) / rect
.height(),
86 const RenderPassDrawQuad
* RenderPassDrawQuad::MaterialCast(
87 const DrawQuad
* quad
) {
88 DCHECK_EQ(quad
->material
, DrawQuad::RENDER_PASS
);
89 return static_cast<const RenderPassDrawQuad
*>(quad
);
92 void RenderPassDrawQuad::ExtendValue(
93 base::trace_event::TracedValue
* value
) const {
94 TracedValue::SetIDRef(render_pass_id
.AsTracingId(), value
, "render_pass_id");
95 value
->SetInteger("mask_resource_id", resources
.ids
[kMaskResourceIdIndex
]);
96 MathUtil::AddToTracedValue("mask_texture_size", mask_texture_size
, value
);
97 MathUtil::AddToTracedValue("mask_uv_scale", mask_uv_scale
, value
);
99 value
->BeginDictionary("filters");
100 filters
.AsValueInto(value
);
101 value
->EndDictionary();
102 MathUtil::AddToTracedValue("filters_scale", filters_scale
, value
);
104 value
->BeginDictionary("background_filters");
105 background_filters
.AsValueInto(value
);
106 value
->EndDictionary();