Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Side by Side Diff: cc/output/filter_operation.cc

Issue 1867913002: Implement cc::FilterOperations::MapRect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: senorblanco review Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/output/filter_operation.h ('k') | cc/output/filter_operations.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/trace_event/trace_event_argument.h" 9 #include "base/trace_event/trace_event_argument.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "cc/base/math_util.h" 11 #include "cc/base/math_util.h"
12 #include "cc/output/filter_operation.h" 12 #include "cc/output/filter_operation.h"
13 #include "ui/gfx/animation/tween.h" 13 #include "ui/gfx/animation/tween.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/geometry/rect_conversions.h"
16 #include "ui/gfx/skia_util.h"
14 17
15 namespace cc { 18 namespace cc {
16 19
17 bool FilterOperation::operator==(const FilterOperation& other) const { 20 bool FilterOperation::operator==(const FilterOperation& other) const {
18 if (type_ != other.type_) 21 if (type_ != other.type_)
19 return false; 22 return false;
20 if (type_ == COLOR_MATRIX) 23 if (type_ == COLOR_MATRIX)
21 return !memcmp(matrix_, other.matrix_, sizeof(matrix_)); 24 return !memcmp(matrix_, other.matrix_, sizeof(matrix_));
22 if (type_ == DROP_SHADOW) { 25 if (type_ == DROP_SHADOW) {
23 return amount_ == other.amount_ && 26 return amount_ == other.amount_ &&
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 value->AppendInteger(it.rect().y()); 313 value->AppendInteger(it.rect().y());
311 value->AppendInteger(it.rect().width()); 314 value->AppendInteger(it.rect().width());
312 value->AppendInteger(it.rect().height()); 315 value->AppendInteger(it.rect().height());
313 } 316 }
314 value->EndArray(); 317 value->EndArray();
315 } 318 }
316 break; 319 break;
317 } 320 }
318 } 321 }
319 322
323 static int SpreadForStdDeviation(float std_deviation) {
324 // https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#feGaussianBlurE lement
325 // provides this approximation for evaluating a gaussian blur by a triple box
326 // filter.
327 float d = floorf(std_deviation * 3.f * sqrt(8.f * atan(1.f)) / 4.f + 0.5f);
328 return static_cast<int>(ceilf(d * 3.f / 2.f));
329 }
330
331 gfx::Rect FilterOperation::MapRect(const gfx::Rect& rect) const {
332 switch (type_) {
333 case FilterOperation::BLUR: {
334 int spread = SpreadForStdDeviation(amount());
335 gfx::Rect result = rect;
336 result.Inset(-spread, -spread, -spread, -spread);
337 return result;
338 }
339 case FilterOperation::DROP_SHADOW: {
340 int spread = SpreadForStdDeviation(amount());
341 gfx::Rect result = rect;
342 result.Inset(-spread, -spread, -spread, -spread);
343 result += drop_shadow_offset().OffsetFromOrigin();
344 result.Union(rect);
345 return result;
346 }
347 case FilterOperation::REFERENCE: {
348 if (!image_filter())
349 return rect;
350 SkIRect in_rect = gfx::RectToSkIRect(rect);
351 SkIRect out_rect = image_filter()->filterBounds(
352 in_rect, SkMatrix::I(), SkImageFilter::kForward_MapDirection);
353 return gfx::SkIRectToRect(out_rect);
354 }
355 default:
356 return rect;
357 }
358 }
359
320 } // namespace cc 360 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/filter_operation.h ('k') | cc/output/filter_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698