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)),
17 mask_resource_id(static_cast<ResourceProvider::ResourceId
>(-1)) {
20 RenderPassDrawQuad::~RenderPassDrawQuad() {
23 void RenderPassDrawQuad::SetNew(const SharedQuadState
* shared_quad_state
,
24 const gfx::Rect
& rect
,
25 const gfx::Rect
& visible_rect
,
26 RenderPassId render_pass_id
,
27 ResourceProvider::ResourceId mask_resource_id
,
28 const gfx::Vector2dF
& mask_uv_scale
,
29 const gfx::Size
& mask_texture_size
,
30 const FilterOperations
& filters
,
31 const gfx::Vector2dF
& filters_scale
,
32 const FilterOperations
& background_filters
) {
33 DCHECK_GT(render_pass_id
.layer_id
, 0);
34 DCHECK_GE(render_pass_id
.index
, 0);
36 gfx::Rect opaque_rect
;
37 bool needs_blending
= false;
38 SetAll(shared_quad_state
,
52 void RenderPassDrawQuad::SetAll(const SharedQuadState
* shared_quad_state
,
53 const gfx::Rect
& rect
,
54 const gfx::Rect
& opaque_rect
,
55 const gfx::Rect
& visible_rect
,
57 RenderPassId render_pass_id
,
58 ResourceProvider::ResourceId mask_resource_id
,
59 const gfx::Vector2dF
& mask_uv_scale
,
60 const gfx::Size
& mask_texture_size
,
61 const FilterOperations
& filters
,
62 const gfx::Vector2dF
& filters_scale
,
63 const FilterOperations
& background_filters
) {
64 DCHECK_GT(render_pass_id
.layer_id
, 0);
65 DCHECK_GE(render_pass_id
.index
, 0);
67 DrawQuad::SetAll(shared_quad_state
, DrawQuad::RENDER_PASS
, rect
, opaque_rect
,
68 visible_rect
, needs_blending
);
69 this->render_pass_id
= render_pass_id
;
70 this->mask_resource_id
= mask_resource_id
;
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 void RenderPassDrawQuad::IterateResources(
79 const ResourceIteratorCallback
& callback
) {
81 mask_resource_id
= callback
.Run(mask_resource_id
);
84 gfx::RectF
RenderPassDrawQuad::MaskUVRect() const {
85 gfx::RectF
mask_uv_rect((mask_uv_scale
.x() * rect
.x()) / rect
.width(),
86 (mask_uv_scale
.y() * rect
.y()) / rect
.height(),
92 const RenderPassDrawQuad
* RenderPassDrawQuad::MaterialCast(
93 const DrawQuad
* quad
) {
94 DCHECK_EQ(quad
->material
, DrawQuad::RENDER_PASS
);
95 return static_cast<const RenderPassDrawQuad
*>(quad
);
98 void RenderPassDrawQuad::ExtendValue(
99 base::trace_event::TracedValue
* value
) const {
100 TracedValue::SetIDRef(render_pass_id
.AsTracingId(), value
, "render_pass_id");
101 value
->SetInteger("mask_resource_id", mask_resource_id
);
102 MathUtil::AddToTracedValue("mask_texture_size", mask_texture_size
, value
);
103 MathUtil::AddToTracedValue("mask_uv_scale", mask_uv_scale
, value
);
105 value
->BeginDictionary("filters");
106 filters
.AsValueInto(value
);
107 value
->EndDictionary();
108 MathUtil::AddToTracedValue("filters_scale", filters_scale
, value
);
110 value
->BeginDictionary("background_filters");
111 background_filters
.AsValueInto(value
);
112 value
->EndDictionary();