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.
4
5 #include "cc/quads/render_pass_draw_quad.h"
6
7 #include "base/values.h"
8 #include "cc/base/math_util.h"
9 #include "cc/debug/traced_value.h"
10 #include "third_party/skia/include/core/SkImageFilter.h"
11
12 namespace cc {
13
RenderPassDrawQuad()14 RenderPassDrawQuad::RenderPassDrawQuad()
15 : render_pass_id(RenderPass::Id(-1, -1)),
16 is_replica(false),
17 mask_resource_id(-1) {
18 }
19
~RenderPassDrawQuad()20 RenderPassDrawQuad::~RenderPassDrawQuad() {
21 }
22
Create()23 scoped_ptr<RenderPassDrawQuad> RenderPassDrawQuad::Create() {
24 return make_scoped_ptr(new RenderPassDrawQuad);
25 }
26
Copy(const SharedQuadState * copied_shared_quad_state,RenderPass::Id copied_render_pass_id) const27 scoped_ptr<RenderPassDrawQuad> RenderPassDrawQuad::Copy(
28 const SharedQuadState* copied_shared_quad_state,
29 RenderPass::Id copied_render_pass_id) const {
30 scoped_ptr<RenderPassDrawQuad> copy_quad(
31 new RenderPassDrawQuad(*MaterialCast(this)));
32 copy_quad->shared_quad_state = copied_shared_quad_state;
33 copy_quad->render_pass_id = copied_render_pass_id;
34 return copy_quad.Pass();
35 }
36
SetNew(const SharedQuadState * shared_quad_state,gfx::Rect rect,RenderPass::Id render_pass_id,bool is_replica,ResourceProvider::ResourceId mask_resource_id,gfx::Rect contents_changed_since_last_frame,gfx::RectF mask_uv_rect,const FilterOperations & filters,const FilterOperations & background_filters)37 void RenderPassDrawQuad::SetNew(
38 const SharedQuadState* shared_quad_state,
39 gfx::Rect rect,
40 RenderPass::Id render_pass_id,
41 bool is_replica,
42 ResourceProvider::ResourceId mask_resource_id,
43 gfx::Rect contents_changed_since_last_frame,
44 gfx::RectF mask_uv_rect,
45 const FilterOperations& filters,
46 const FilterOperations& background_filters) {
47 DCHECK_GT(render_pass_id.layer_id, 0);
48 DCHECK_GE(render_pass_id.index, 0);
49
50 gfx::Rect opaque_rect;
51 gfx::Rect visible_rect = rect;
52 bool needs_blending = false;
53 SetAll(shared_quad_state, rect, opaque_rect, visible_rect, needs_blending,
54 render_pass_id, is_replica, mask_resource_id,
55 contents_changed_since_last_frame, mask_uv_rect, filters,
56 background_filters);
57 }
58
SetAll(const SharedQuadState * shared_quad_state,gfx::Rect rect,gfx::Rect opaque_rect,gfx::Rect visible_rect,bool needs_blending,RenderPass::Id render_pass_id,bool is_replica,ResourceProvider::ResourceId mask_resource_id,gfx::Rect contents_changed_since_last_frame,gfx::RectF mask_uv_rect,const FilterOperations & filters,const FilterOperations & background_filters)59 void RenderPassDrawQuad::SetAll(
60 const SharedQuadState* shared_quad_state,
61 gfx::Rect rect,
62 gfx::Rect opaque_rect,
63 gfx::Rect visible_rect,
64 bool needs_blending,
65 RenderPass::Id render_pass_id,
66 bool is_replica,
67 ResourceProvider::ResourceId mask_resource_id,
68 gfx::Rect contents_changed_since_last_frame,
69 gfx::RectF mask_uv_rect,
70 const FilterOperations& filters,
71 const FilterOperations& background_filters) {
72 DCHECK_GT(render_pass_id.layer_id, 0);
73 DCHECK_GE(render_pass_id.index, 0);
74
75 DrawQuad::SetAll(shared_quad_state, DrawQuad::RENDER_PASS, rect, opaque_rect,
76 visible_rect, needs_blending);
77 this->render_pass_id = render_pass_id;
78 this->is_replica = is_replica;
79 this->mask_resource_id = mask_resource_id;
80 this->contents_changed_since_last_frame = contents_changed_since_last_frame;
81 this->mask_uv_rect = mask_uv_rect;
82 this->filters = filters;
83 this->background_filters = background_filters;
84 }
85
IterateResources(const ResourceIteratorCallback & callback)86 void RenderPassDrawQuad::IterateResources(
87 const ResourceIteratorCallback& callback) {
88 if (mask_resource_id)
89 mask_resource_id = callback.Run(mask_resource_id);
90 }
91
MaterialCast(const DrawQuad * quad)92 const RenderPassDrawQuad* RenderPassDrawQuad::MaterialCast(
93 const DrawQuad* quad) {
94 DCHECK_EQ(quad->material, DrawQuad::RENDER_PASS);
95 return static_cast<const RenderPassDrawQuad*>(quad);
96 }
97
ExtendValue(base::DictionaryValue * value) const98 void RenderPassDrawQuad::ExtendValue(base::DictionaryValue* value) const {
99 value->Set("render_pass_id",
100 TracedValue::CreateIDRef(render_pass_id.AsTracingId()).release());
101 value->SetBoolean("is_replica", is_replica);
102 value->SetInteger("mask_resource_id", mask_resource_id);
103 value->Set("contents_changed_since_last_frame",
104 MathUtil::AsValue(contents_changed_since_last_frame).release());
105 value->Set("mask_uv_rect", MathUtil::AsValue(mask_uv_rect).release());
106 value->Set("filters", filters.AsValue().release());
107 value->Set("background_filters", background_filters.AsValue().release());
108 }
109
110 } // namespace cc
111