Home | History | Annotate | Download | only in resources
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CC_RESOURCES_MANAGED_TILE_STATE_H_
      6 #define CC_RESOURCES_MANAGED_TILE_STATE_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "cc/resources/platform_color.h"
     10 #include "cc/resources/raster_worker_pool.h"
     11 #include "cc/resources/resource_pool.h"
     12 #include "cc/resources/resource_provider.h"
     13 #include "cc/resources/scoped_resource.h"
     14 
     15 namespace cc {
     16 
     17 class TileManager;
     18 
     19 // Tile manager classifying tiles into a few basic bins:
     20 enum ManagedTileBin {
     21   NOW_AND_READY_TO_DRAW_BIN = 0,  // Ready to draw and within viewport.
     22   NOW_BIN = 1,                    // Needed ASAP.
     23   SOON_BIN = 2,                   // Impl-side version of prepainting.
     24   EVENTUALLY_AND_ACTIVE_BIN = 3,  // Nice to have, and has a task or resource.
     25   EVENTUALLY_BIN = 4,             // Nice to have, if we've got memory and time.
     26   AT_LAST_AND_ACTIVE_BIN = 5,     // Only do this after all other bins.
     27   AT_LAST_BIN = 6,                // Only do this after all other bins.
     28   NEVER_BIN = 7,                  // Dont bother.
     29   NUM_BINS = 8
     30   // NOTE: Be sure to update ManagedTileBinAsValue and kBinPolicyMap when adding
     31   // or reordering fields.
     32 };
     33 scoped_ptr<base::Value> ManagedTileBinAsValue(
     34     ManagedTileBin bin);
     35 
     36 // This is state that is specific to a tile that is
     37 // managed by the TileManager.
     38 class CC_EXPORT ManagedTileState {
     39  public:
     40   class CC_EXPORT TileVersion {
     41     public:
     42       enum Mode {
     43         RESOURCE_MODE,
     44         SOLID_COLOR_MODE,
     45         PICTURE_PILE_MODE
     46       };
     47 
     48       TileVersion();
     49       ~TileVersion();
     50 
     51       Mode mode() const {
     52         return mode_;
     53       }
     54 
     55       bool IsReadyToDraw() const;
     56 
     57       ResourceProvider::ResourceId get_resource_id() const {
     58         DCHECK(mode_ == RESOURCE_MODE);
     59         DCHECK(resource_);
     60 
     61         return resource_->id();
     62       }
     63 
     64       SkColor get_solid_color() const {
     65         DCHECK(mode_ == SOLID_COLOR_MODE);
     66 
     67         return solid_color_;
     68       }
     69 
     70       bool contents_swizzled() const {
     71         DCHECK(resource_);
     72         return !PlatformColor::SameComponentOrder(resource_->format());
     73       }
     74 
     75       bool requires_resource() const {
     76         return mode_ == RESOURCE_MODE ||
     77                mode_ == PICTURE_PILE_MODE;
     78       }
     79 
     80       size_t GPUMemoryUsageInBytes() const;
     81 
     82       void SetSolidColorForTesting(SkColor color) {
     83         set_solid_color(color);
     84       }
     85       void SetHasTextForTesting(bool has_text) {
     86         has_text_ = has_text;
     87       }
     88 
     89     private:
     90       friend class TileManager;
     91       friend class PrioritizedTileSet;
     92       friend class Tile;
     93       friend class ManagedTileState;
     94 
     95       void set_use_resource() {
     96         mode_ = RESOURCE_MODE;
     97       }
     98 
     99       void set_solid_color(const SkColor& color) {
    100         mode_ = SOLID_COLOR_MODE;
    101         solid_color_ = color;
    102       }
    103 
    104       void set_has_text(bool has_text) {
    105         has_text_ = has_text;
    106       }
    107 
    108       void set_rasterize_on_demand() {
    109         mode_ = PICTURE_PILE_MODE;
    110       }
    111 
    112       Mode mode_;
    113       SkColor solid_color_;
    114       bool has_text_;
    115       scoped_ptr<ScopedResource> resource_;
    116       RasterWorkerPool::RasterTask raster_task_;
    117   };
    118 
    119   ManagedTileState();
    120   ~ManagedTileState();
    121 
    122   scoped_ptr<base::Value> AsValue() const;
    123 
    124   // Persisted state: valid all the time.
    125   TileVersion tile_versions[NUM_RASTER_MODES];
    126   RasterMode raster_mode;
    127 
    128   ManagedTileBin bin;
    129 
    130   TileResolution resolution;
    131   bool required_for_activation;
    132   float time_to_needed_in_seconds;
    133   float distance_to_visible_in_pixels;
    134   bool visible_and_ready_to_draw;
    135 
    136   // Priority for this state from the last time we assigned memory.
    137   unsigned scheduled_priority;
    138 };
    139 
    140 }  // namespace cc
    141 
    142 #endif  // CC_RESOURCES_MANAGED_TILE_STATE_H_
    143