Home | History | Annotate | Download | only in resources
      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/resources/skpicture_content_layer_updater.h"
      6 
      7 #include "base/debug/trace_event.h"
      8 #include "cc/debug/rendering_stats_instrumentation.h"
      9 #include "cc/resources/layer_painter.h"
     10 #include "cc/resources/prioritized_resource.h"
     11 #include "cc/resources/resource_update_queue.h"
     12 #include "third_party/skia/include/core/SkCanvas.h"
     13 
     14 namespace cc {
     15 
     16 SkPictureContentLayerUpdater::SkPictureContentLayerUpdater(
     17     scoped_ptr<LayerPainter> painter,
     18     RenderingStatsInstrumentation* stats_instrumentation,
     19     int layer_id)
     20     : ContentLayerUpdater(painter.Pass(), stats_instrumentation, layer_id),
     21       layer_is_opaque_(false) {}
     22 
     23 SkPictureContentLayerUpdater::~SkPictureContentLayerUpdater() {}
     24 
     25 void SkPictureContentLayerUpdater::PrepareToUpdate(
     26     gfx::Rect content_rect,
     27     gfx::Size,
     28     float contents_width_scale,
     29     float contents_height_scale,
     30     gfx::Rect* resulting_opaque_rect) {
     31   SkCanvas* canvas =
     32       picture_.beginRecording(content_rect.width(), content_rect.height());
     33   base::TimeTicks start_time =
     34       rendering_stats_instrumentation_->StartRecording();
     35   PaintContents(canvas,
     36                 content_rect,
     37                 contents_width_scale,
     38                 contents_height_scale,
     39                 resulting_opaque_rect);
     40   base::TimeDelta duration =
     41       rendering_stats_instrumentation_->EndRecording(start_time);
     42   rendering_stats_instrumentation_->AddRecord(
     43       duration, content_rect.width() * content_rect.height());
     44   picture_.endRecording();
     45 }
     46 
     47 void SkPictureContentLayerUpdater::DrawPicture(SkCanvas* canvas) {
     48   TRACE_EVENT0("cc", "SkPictureContentLayerUpdater::DrawPicture");
     49   canvas->drawPicture(picture_);
     50 }
     51 
     52 void SkPictureContentLayerUpdater::SetOpaque(bool opaque) {
     53   layer_is_opaque_ = opaque;
     54 }
     55 
     56 }  // namespace cc
     57