summaryrefslogtreecommitdiffstats
path: root/cc/quads/render_pass_draw_quad.cc
blob: 963a1906ee741b37b4d94468ae1ff42dfbc3b1ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/quads/render_pass_draw_quad.h"

#include "base/trace_event/trace_event_argument.h"
#include "base/values.h"
#include "cc/base/math_util.h"
#include "cc/debug/traced_value.h"
#include "third_party/skia/include/core/SkImageFilter.h"

namespace cc {

RenderPassDrawQuad::RenderPassDrawQuad()
    : render_pass_id(RenderPassId(-1, -1)),
      mask_resource_id(static_cast<ResourceProvider::ResourceId>(-1)) {
}

RenderPassDrawQuad::~RenderPassDrawQuad() {
}

void RenderPassDrawQuad::SetNew(const SharedQuadState* shared_quad_state,
                                const gfx::Rect& rect,
                                const gfx::Rect& visible_rect,
                                RenderPassId render_pass_id,
                                ResourceProvider::ResourceId mask_resource_id,
                                const gfx::Vector2dF& mask_uv_scale,
                                const gfx::Size& mask_texture_size,
                                const FilterOperations& filters,
                                const gfx::Vector2dF& filters_scale,
                                const FilterOperations& background_filters) {
  DCHECK_GT(render_pass_id.layer_id, 0);
  DCHECK_GE(render_pass_id.index, 0);

  gfx::Rect opaque_rect;
  bool needs_blending = false;
  SetAll(shared_quad_state,
         rect,
         opaque_rect,
         visible_rect,
         needs_blending,
         render_pass_id,
         mask_resource_id,
         mask_uv_scale,
         mask_texture_size,
         filters,
         filters_scale,
         background_filters);
}

void RenderPassDrawQuad::SetAll(const SharedQuadState* shared_quad_state,
                                const gfx::Rect& rect,
                                const gfx::Rect& opaque_rect,
                                const gfx::Rect& visible_rect,
                                bool needs_blending,
                                RenderPassId render_pass_id,
                                ResourceProvider::ResourceId mask_resource_id,
                                const gfx::Vector2dF& mask_uv_scale,
                                const gfx::Size& mask_texture_size,
                                const FilterOperations& filters,
                                const gfx::Vector2dF& filters_scale,
                                const FilterOperations& background_filters) {
  DCHECK_GT(render_pass_id.layer_id, 0);
  DCHECK_GE(render_pass_id.index, 0);

  DrawQuad::SetAll(shared_quad_state, DrawQuad::RENDER_PASS, rect, opaque_rect,
                   visible_rect, needs_blending);
  this->render_pass_id = render_pass_id;
  this->mask_resource_id = mask_resource_id;
  this->mask_uv_scale = mask_uv_scale;
  this->mask_texture_size = mask_texture_size;
  this->filters = filters;
  this->filters_scale = filters_scale;
  this->background_filters = background_filters;
}

void RenderPassDrawQuad::IterateResources(
    const ResourceIteratorCallback& callback) {
  if (mask_resource_id)
    mask_resource_id = callback.Run(mask_resource_id);
}

gfx::RectF RenderPassDrawQuad::MaskUVRect() const {
  gfx::RectF mask_uv_rect((mask_uv_scale.x() * rect.x()) / rect.width(),
                          (mask_uv_scale.y() * rect.y()) / rect.height(),
                          mask_uv_scale.x(),
                          mask_uv_scale.y());
  return mask_uv_rect;
}

const RenderPassDrawQuad* RenderPassDrawQuad::MaterialCast(
    const DrawQuad* quad) {
  DCHECK_EQ(quad->material, DrawQuad::RENDER_PASS);
  return static_cast<const RenderPassDrawQuad*>(quad);
}

void RenderPassDrawQuad::ExtendValue(
    base::trace_event::TracedValue* value) const {
  TracedValue::SetIDRef(render_pass_id.AsTracingId(), value, "render_pass_id");
  value->SetInteger("mask_resource_id", mask_resource_id);
  MathUtil::AddToTracedValue("mask_texture_size", mask_texture_size, value);
  MathUtil::AddToTracedValue("mask_uv_scale", mask_uv_scale, value);

  value->BeginDictionary("filters");
  filters.AsValueInto(value);
  value->EndDictionary();
  MathUtil::AddToTracedValue("filters_scale", filters_scale, value);

  value->BeginDictionary("background_filters");
  background_filters.AsValueInto(value);
  value->EndDictionary();
}

}  // namespace cc