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 #ifndef CC_LAYERS_PICTURE_LAYER_IMPL_H_ 6 #define CC_LAYERS_PICTURE_LAYER_IMPL_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "cc/base/cc_export.h" 12 #include "cc/base/scoped_ptr_vector.h" 13 #include "cc/layers/layer_impl.h" 14 #include "cc/resources/picture_layer_tiling.h" 15 #include "cc/resources/picture_layer_tiling_set.h" 16 #include "cc/resources/picture_pile_impl.h" 17 #include "skia/ext/refptr.h" 18 #include "third_party/skia/include/core/SkPicture.h" 19 20 namespace cc { 21 22 struct AppendQuadsData; 23 class QuadSink; 24 class MicroBenchmarkImpl; 25 26 class CC_EXPORT PictureLayerImpl 27 : public LayerImpl, 28 NON_EXPORTED_BASE(public PictureLayerTilingClient) { 29 public: 30 static scoped_ptr<PictureLayerImpl> Create(LayerTreeImpl* tree_impl, int id) { 31 return make_scoped_ptr(new PictureLayerImpl(tree_impl, id)); 32 } 33 virtual ~PictureLayerImpl(); 34 35 // LayerImpl overrides. 36 virtual const char* LayerTypeAsString() const OVERRIDE; 37 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) 38 OVERRIDE; 39 virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE; 40 virtual void AppendQuads(QuadSink* quad_sink, 41 AppendQuadsData* append_quads_data) OVERRIDE; 42 virtual void UpdateTilePriorities() OVERRIDE; 43 virtual void DidBecomeActive() OVERRIDE; 44 virtual void DidBeginTracing() OVERRIDE; 45 virtual void DidLoseOutputSurface() OVERRIDE; 46 virtual void CalculateContentsScale(float ideal_contents_scale, 47 float device_scale_factor, 48 float page_scale_factor, 49 bool animating_transform_to_screen, 50 float* contents_scale_x, 51 float* contents_scale_y, 52 gfx::Size* content_bounds) OVERRIDE; 53 virtual skia::RefPtr<SkPicture> GetPicture() OVERRIDE; 54 55 // PictureLayerTilingClient overrides. 56 virtual scoped_refptr<Tile> CreateTile(PictureLayerTiling* tiling, 57 gfx::Rect content_rect) OVERRIDE; 58 virtual void UpdatePile(Tile* tile) OVERRIDE; 59 virtual gfx::Size CalculateTileSize( 60 gfx::Size content_bounds) const OVERRIDE; 61 virtual const Region* GetInvalidation() OVERRIDE; 62 virtual const PictureLayerTiling* GetTwinTiling( 63 const PictureLayerTiling* tiling) const OVERRIDE; 64 65 // PushPropertiesTo active tree => pending tree. 66 void SyncTiling(const PictureLayerTiling* tiling); 67 68 // Mask-related functions 69 void SetIsMask(bool is_mask); 70 virtual ResourceProvider::ResourceId ContentsResourceId() const OVERRIDE; 71 72 virtual size_t GPUMemoryUsageInBytes() const OVERRIDE; 73 74 virtual void RunMicroBenchmark(MicroBenchmarkImpl* benchmark) OVERRIDE; 75 76 protected: 77 PictureLayerImpl(LayerTreeImpl* tree_impl, int id); 78 PictureLayerTiling* AddTiling(float contents_scale); 79 void RemoveTiling(float contents_scale); 80 void RemoveAllTilings(); 81 void SyncFromActiveLayer(const PictureLayerImpl* other); 82 void ManageTilings(bool animating_transform_to_screen); 83 virtual bool ShouldAdjustRasterScale( 84 bool animating_transform_to_screen) const; 85 virtual void RecalculateRasterScales( 86 bool animating_transform_to_screen); 87 void CleanUpTilingsOnActiveLayer( 88 std::vector<PictureLayerTiling*> used_tilings); 89 float MinimumContentsScale() const; 90 float SnappedContentsScale(float new_contents_scale); 91 void UpdateLCDTextStatus(bool new_status); 92 void ResetRasterScale(); 93 void MarkVisibleResourcesAsRequired() const; 94 bool MarkVisibleTilesAsRequired( 95 PictureLayerTiling* tiling, 96 const PictureLayerTiling* optional_twin_tiling, 97 float contents_scale, 98 gfx::Rect rect, 99 const Region& missing_region) const; 100 101 void DoPostCommitInitializationIfNeeded() { 102 if (needs_post_commit_initialization_) 103 DoPostCommitInitialization(); 104 } 105 void DoPostCommitInitialization(); 106 107 bool CanHaveTilings() const; 108 bool CanHaveTilingWithScale(float contents_scale) const; 109 void SanityCheckTilingState() const; 110 bool ShouldUseGPURasterization() const; 111 112 virtual void GetDebugBorderProperties( 113 SkColor* color, float* width) const OVERRIDE; 114 virtual void AsValueInto(base::DictionaryValue* dict) const OVERRIDE; 115 116 PictureLayerImpl* twin_layer_; 117 118 scoped_ptr<PictureLayerTilingSet> tilings_; 119 scoped_refptr<PicturePileImpl> pile_; 120 Region invalidation_; 121 122 gfx::Transform last_screen_space_transform_; 123 gfx::Size last_bounds_; 124 float last_content_scale_; 125 bool is_mask_; 126 127 float ideal_page_scale_; 128 float ideal_device_scale_; 129 float ideal_source_scale_; 130 float ideal_contents_scale_; 131 132 float raster_page_scale_; 133 float raster_device_scale_; 134 float raster_source_scale_; 135 float raster_contents_scale_; 136 float low_res_raster_contents_scale_; 137 138 bool raster_source_scale_was_animating_; 139 bool is_using_lcd_text_; 140 bool needs_post_commit_initialization_; 141 // A sanity state check to make sure UpdateTilePriorities only gets called 142 // after a CalculateContentsScale/ManageTilings. 143 bool should_update_tile_priorities_; 144 145 friend class PictureLayer; 146 DISALLOW_COPY_AND_ASSIGN(PictureLayerImpl); 147 }; 148 149 } // namespace cc 150 151 #endif // CC_LAYERS_PICTURE_LAYER_IMPL_H_ 152