diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-18 08:24:40 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-18 08:24:40 +0000 |
commit | e12dd0e802b2a80112cb40e01fabcc5c0475f05b (patch) | |
tree | fbfd355be68b05d64c98e4c0618e1d4ad8122f6a /cc/resources/content_layer_updater.cc | |
parent | 0d4f1f4b15d63e5976f0a2c0205d414da861c8a5 (diff) | |
download | chromium_src-e12dd0e802b2a80112cb40e01fabcc5c0475f05b.zip chromium_src-e12dd0e802b2a80112cb40e01fabcc5c0475f05b.tar.gz chromium_src-e12dd0e802b2a80112cb40e01fabcc5c0475f05b.tar.bz2 |
Part 8 of cc/ directory shuffles: resources
Continuation of https://src.chromium.org/viewvc/chrome?view=rev&revision=188681
BUG=190824
TBR=enne@chromium.org, piman@chromium.org, jschuh@chromium.org
Review URL: https://codereview.chromium.org/12471007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/resources/content_layer_updater.cc')
-rw-r--r-- | cc/resources/content_layer_updater.cc | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/cc/resources/content_layer_updater.cc b/cc/resources/content_layer_updater.cc new file mode 100644 index 0000000..b4eb1d2 --- /dev/null +++ b/cc/resources/content_layer_updater.cc @@ -0,0 +1,73 @@ +// 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/resources/content_layer_updater.h" + +#include "base/debug/trace_event.h" +#include "base/time.h" +#include "cc/debug/rendering_stats.h" +#include "cc/resources/layer_painter.h" +#include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/core/SkPaint.h" +#include "third_party/skia/include/core/SkRect.h" +#include "third_party/skia/include/core/SkScalar.h" +#include "ui/gfx/rect_conversions.h" +#include "ui/gfx/rect_f.h" + +namespace cc { + +ContentLayerUpdater::ContentLayerUpdater(scoped_ptr<LayerPainter> painter) + : painter_(painter.Pass()) {} + +ContentLayerUpdater::~ContentLayerUpdater() {} + +void ContentLayerUpdater::PaintContents(SkCanvas* canvas, + gfx::Rect content_rect, + float contents_width_scale, + float contents_height_scale, + gfx::Rect* resulting_opaque_rect, + RenderingStats* stats) { + TRACE_EVENT0("cc", "ContentLayerUpdater::paintContents"); + canvas->save(); + canvas->translate(SkFloatToScalar(-content_rect.x()), + SkFloatToScalar(-content_rect.y())); + + gfx::Rect layer_rect = content_rect; + + if (contents_width_scale != 1.f || contents_height_scale != 1.f) { + canvas->scale(SkFloatToScalar(contents_width_scale), + SkFloatToScalar(contents_height_scale)); + + gfx::RectF rect = gfx::ScaleRect( + content_rect, 1.f / contents_width_scale, 1.f / contents_height_scale); + layer_rect = gfx::ToEnclosingRect(rect); + } + + SkPaint paint; + paint.setAntiAlias(false); + paint.setXfermodeMode(SkXfermode::kClear_Mode); + SkRect layer_sk_rect = SkRect::MakeXYWH( + layer_rect.x(), layer_rect.y(), layer_rect.width(), layer_rect.height()); + canvas->drawRect(layer_sk_rect, paint); + canvas->clipRect(layer_sk_rect); + + gfx::RectF opaque_layer_rect; + base::TimeTicks paint_begin_time; + if (stats) + paint_begin_time = base::TimeTicks::Now(); + painter_->Paint(canvas, layer_rect, &opaque_layer_rect); + if (stats) { + stats->totalPaintTime += base::TimeTicks::Now() - paint_begin_time; + stats->totalPixelsPainted += content_rect.width() * content_rect.height(); + } + canvas->restore(); + + gfx::RectF opaque_content_rect = gfx::ScaleRect( + opaque_layer_rect, contents_width_scale, contents_height_scale); + *resulting_opaque_rect = gfx::ToEnclosedRect(opaque_content_rect); + + content_rect_ = content_rect; +} + +} // namespace cc |