Home | History | Annotate | Download | only in resources
      1 // Copyright 2012 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/tile.h"
      6 
      7 #include "cc/base/math_util.h"
      8 #include "cc/debug/traced_value.h"
      9 #include "cc/resources/tile_manager.h"
     10 #include "third_party/khronos/GLES2/gl2.h"
     11 
     12 namespace cc {
     13 
     14 Tile::Id Tile::s_next_id_ = 0;
     15 
     16 Tile::Tile(TileManager* tile_manager,
     17            PicturePileImpl* picture_pile,
     18            gfx::Size tile_size,
     19            gfx::Rect content_rect,
     20            gfx::Rect opaque_rect,
     21            float contents_scale,
     22            int layer_id,
     23            int source_frame_number,
     24            bool can_use_lcd_text)
     25   : tile_manager_(tile_manager),
     26     tile_size_(tile_size),
     27     content_rect_(content_rect),
     28     contents_scale_(contents_scale),
     29     opaque_rect_(opaque_rect),
     30     layer_id_(layer_id),
     31     source_frame_number_(source_frame_number),
     32     can_use_lcd_text_(can_use_lcd_text),
     33     id_(s_next_id_++) {
     34   set_picture_pile(picture_pile);
     35   tile_manager_->RegisterTile(this);
     36 }
     37 
     38 Tile::~Tile() {
     39   TRACE_EVENT_OBJECT_DELETED_WITH_ID(
     40       TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::Tile", this);
     41   tile_manager_->UnregisterTile(this);
     42 }
     43 
     44 scoped_ptr<base::Value> Tile::AsValue() const {
     45   scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
     46   TracedValue::MakeDictIntoImplicitSnapshot(res.get(), "cc::Tile", this);
     47   res->Set("picture_pile",
     48            TracedValue::CreateIDRef(picture_pile_.get()).release());
     49   res->SetDouble("contents_scale", contents_scale_);
     50   res->Set("content_rect", MathUtil::AsValue(content_rect_).release());
     51   res->SetInteger("layer_id", layer_id_);
     52   res->Set("active_priority", priority_[ACTIVE_TREE].AsValue().release());
     53   res->Set("pending_priority", priority_[PENDING_TREE].AsValue().release());
     54   res->Set("managed_state", managed_state_.AsValue().release());
     55   return res.PassAs<base::Value>();
     56 }
     57 
     58 size_t Tile::GPUMemoryUsageInBytes() const {
     59   size_t total_size = 0;
     60   for (int mode = 0; mode < NUM_RASTER_MODES; ++mode)
     61     total_size += managed_state_.tile_versions[mode].GPUMemoryUsageInBytes();
     62   return total_size;
     63 }
     64 
     65 }  // namespace cc
     66