| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CC_TILES_TILE_DRAW_INFO_H_ | 5 #ifndef CC_TILES_TILE_DRAW_INFO_H_ |
| 6 #define CC_TILES_TILE_DRAW_INFO_H_ | 6 #define CC_TILES_TILE_DRAW_INFO_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/trace_event/trace_event_argument.h" | 10 #include "base/trace_event/trace_event_argument.h" |
| 11 #include "cc/resources/platform_color.h" | 11 #include "cc/resources/platform_color.h" |
| 12 #include "cc/resources/resource_provider.h" | 12 #include "cc/resources/resource_provider.h" |
| 13 #include "cc/resources/scoped_resource.h" | 13 #include "cc/resources/scoped_resource.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 // This class holds all the state relevant to drawing a tile. | 17 // This class holds all the state relevant to drawing a tile. |
| 18 class CC_EXPORT TileDrawInfo { | 18 class CC_EXPORT TileDrawInfo { |
| 19 public: | 19 public: |
| 20 enum Mode { RESOURCE_MODE, SOLID_COLOR_MODE, OOM_MODE }; | 20 enum Mode { RESOURCE_MODE, SOLID_COLOR_MODE, OOM_MODE }; |
| 21 | 21 |
| 22 TileDrawInfo(); | 22 TileDrawInfo(); |
| 23 ~TileDrawInfo(); | 23 ~TileDrawInfo(); |
| 24 | 24 |
| 25 Mode mode() const { return mode_; } | 25 Mode mode() const { return mode_; } |
| 26 | 26 |
| 27 bool IsReadyToDraw() const { | 27 bool IsReadyToDraw() const { |
| 28 switch (mode_) { | 28 switch (mode_) { |
| 29 case RESOURCE_MODE: | 29 case RESOURCE_MODE: |
| 30 return !!resource_; | 30 return ready_to_draw_; |
| 31 case SOLID_COLOR_MODE: | 31 case SOLID_COLOR_MODE: |
| 32 case OOM_MODE: | 32 case OOM_MODE: |
| 33 return true; | 33 return true; |
| 34 } | 34 } |
| 35 NOTREACHED(); | 35 NOTREACHED(); |
| 36 return false; | 36 return false; |
| 37 } | 37 } |
| 38 |
| 38 bool NeedsRaster() const { | 39 bool NeedsRaster() const { |
| 39 switch (mode_) { | 40 switch (mode_) { |
| 40 case RESOURCE_MODE: | 41 case RESOURCE_MODE: |
| 41 return !resource_; | 42 return !ready_to_draw_; |
| 42 case SOLID_COLOR_MODE: | 43 case SOLID_COLOR_MODE: |
| 43 return false; | 44 return false; |
| 44 case OOM_MODE: | 45 case OOM_MODE: |
| 45 return true; | 46 return true; |
| 46 } | 47 } |
| 47 NOTREACHED(); | 48 NOTREACHED(); |
| 48 return false; | 49 return false; |
| 49 } | 50 } |
| 50 | 51 |
| 51 ResourceId resource_id() const { | 52 ResourceId resource_id() const { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 64 DCHECK(mode_ == SOLID_COLOR_MODE); | 65 DCHECK(mode_ == SOLID_COLOR_MODE); |
| 65 return solid_color_; | 66 return solid_color_; |
| 66 } | 67 } |
| 67 | 68 |
| 68 bool contents_swizzled() const { return contents_swizzled_; } | 69 bool contents_swizzled() const { return contents_swizzled_; } |
| 69 | 70 |
| 70 bool requires_resource() const { | 71 bool requires_resource() const { |
| 71 return mode_ == RESOURCE_MODE || mode_ == OOM_MODE; | 72 return mode_ == RESOURCE_MODE || mode_ == OOM_MODE; |
| 72 } | 73 } |
| 73 | 74 |
| 74 inline bool has_resource() const { return !!resource_; } | 75 bool has_resource() const { return !!resource_; } |
| 75 | 76 |
| 76 inline bool has_compressed_resource() const { | 77 bool has_compressed_resource() const { |
| 77 return resource_ ? IsResourceFormatCompressed(resource_->format()) : false; | 78 return resource_ ? IsResourceFormatCompressed(resource_->format()) : false; |
| 78 } | 79 } |
| 79 | 80 |
| 80 void SetSolidColorForTesting(SkColor color) { set_solid_color(color); } | 81 void SetSolidColorForTesting(SkColor color) { set_solid_color(color); } |
| 81 | 82 |
| 82 void AsValueInto(base::trace_event::TracedValue* state) const; | 83 void AsValueInto(base::trace_event::TracedValue* state) const; |
| 83 | 84 |
| 84 void set_was_ever_ready_to_draw() { was_ever_ready_to_draw_ = true; } | 85 void set_was_ever_ready_to_draw() { was_ever_ready_to_draw_ = true; } |
| 85 void set_was_ever_used_to_draw() { was_ever_used_to_draw_ = true; } | 86 void set_was_ever_used_to_draw() { was_ever_used_to_draw_ = true; } |
| 86 void set_was_a_prepaint_tile() { was_a_prepaint_tile_ = true; } | 87 void set_was_a_prepaint_tile() { was_a_prepaint_tile_ = true; } |
| 87 | 88 |
| 88 private: | 89 private: |
| 89 friend class Tile; | 90 friend class Tile; |
| 90 friend class TileManager; | 91 friend class TileManager; |
| 91 | 92 |
| 92 void set_use_resource() { mode_ = RESOURCE_MODE; } | 93 void set_use_resource() { mode_ = RESOURCE_MODE; } |
| 93 | 94 |
| 95 void set_resource(Resource* resource) { |
| 96 DCHECK_EQ(RESOURCE_MODE, mode_); |
| 97 resource_ = resource; |
| 98 } |
| 99 |
| 94 void set_solid_color(const SkColor& color) { | 100 void set_solid_color(const SkColor& color) { |
| 95 mode_ = SOLID_COLOR_MODE; | 101 mode_ = SOLID_COLOR_MODE; |
| 96 solid_color_ = color; | 102 solid_color_ = color; |
| 97 } | 103 } |
| 98 | 104 |
| 99 void set_oom() { mode_ = OOM_MODE; } | 105 void set_oom() { mode_ = OOM_MODE; } |
| 100 | 106 |
| 107 void set_ready_to_draw(bool ready_to_draw) { ready_to_draw_ = ready_to_draw; } |
| 108 |
| 109 void set_contents_swizzled(bool contents_swizzled) { |
| 110 contents_swizzled_ = contents_swizzled; |
| 111 } |
| 112 |
| 113 Resource* resource() const { return resource_; } |
| 114 |
| 101 Mode mode_; | 115 Mode mode_; |
| 102 SkColor solid_color_; | 116 SkColor solid_color_; |
| 103 Resource* resource_; | 117 Resource* resource_; |
| 118 bool ready_to_draw_; |
| 104 bool contents_swizzled_; | 119 bool contents_swizzled_; |
| 105 | 120 |
| 106 // Used for gathering UMA stats. | 121 // Used for gathering UMA stats. |
| 107 bool was_ever_ready_to_draw_ : 1; | 122 bool was_ever_ready_to_draw_ : 1; |
| 108 bool was_ever_used_to_draw_ : 1; | 123 bool was_ever_used_to_draw_ : 1; |
| 109 bool was_a_prepaint_tile_ : 1; | 124 bool was_a_prepaint_tile_ : 1; |
| 110 }; | 125 }; |
| 111 | 126 |
| 112 } // namespace cc | 127 } // namespace cc |
| 113 | 128 |
| 114 #endif // CC_TILES_TILE_DRAW_INFO_H_ | 129 #endif // CC_TILES_TILE_DRAW_INFO_H_ |
| OLD | NEW |