OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 UI_ANDROID_RESOURCES_CRUSHED_SPRITE_RESOURCE_H_ |
| 6 #define UI_ANDROID_RESOURCES_CRUSHED_SPRITE_RESOURCE_H_ |
| 7 |
| 8 #include <utility> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 #include "ui/android/ui_android_export.h" |
| 15 #include "ui/gfx/geometry/rect.h" |
| 16 |
| 17 namespace cc { |
| 18 class LayerTreeHost; |
| 19 class ScopedUIResource; |
| 20 typedef int UIResourceId; |
| 21 } |
| 22 |
| 23 namespace gfx { |
| 24 class JavaBitmap; |
| 25 } |
| 26 |
| 27 namespace ui { |
| 28 |
| 29 // A resource that provides an unscaled bitmap and corresponding metadata for a |
| 30 // crushed sprite. A crushed sprite animation is run by drawing rectangles from |
| 31 // a bitmap to a canvas. Each frame in the animation draws its rectangles on top |
| 32 // of the previous frame. |
| 33 class UI_ANDROID_EXPORT CrushedSpriteResource { |
| 34 public: |
| 35 typedef std::vector<std::pair<gfx::Rect, gfx::Rect>> FrameSrcDstRects; |
| 36 typedef std::vector<FrameSrcDstRects> SrcDstRects; |
| 37 |
| 38 // Creates a new CrushedSpriteResource. |bitmap_res_id| is the id for the |
| 39 // for the source bitmap, |java_bitmap| is the source bitmap for the crushed |
| 40 // sprite, |src_dst_rects| is a list of rectangles to draw for each frame, and |
| 41 // |sprite_size| is the size of an individual sprite. |
| 42 CrushedSpriteResource(const SkBitmap& bitmap, |
| 43 const SrcDstRects& src_dst_rects, |
| 44 gfx::Size sprite_size); |
| 45 ~CrushedSpriteResource(); |
| 46 |
| 47 // Sets the source bitmap. |
| 48 void SetBitmap(const SkBitmap& bitmap); |
| 49 |
| 50 // Returns the source bitmap. |
| 51 const SkBitmap& GetBitmap(); |
| 52 |
| 53 // Returns true if the source bitmap has been evicted from memory. |
| 54 bool BitmapHasBeenEvictedFromMemory(); |
| 55 |
| 56 // Returns a list of rectangles to be drawn for |frame|. |
| 57 FrameSrcDstRects GetRectanglesForFrame(int frame); |
| 58 |
| 59 // Returns the size of an individual sprite. |
| 60 gfx::Size GetSpriteSize(); |
| 61 |
| 62 // Returns the total number of frames in the sprite animation. |
| 63 int GetFrameCount(); |
| 64 |
| 65 private: |
| 66 SkBitmap bitmap_; |
| 67 scoped_ptr<cc::ScopedUIResource> last_frame_resource_; |
| 68 SrcDstRects src_dst_rects_; |
| 69 gfx::Size sprite_size_; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(CrushedSpriteResource); |
| 72 }; |
| 73 |
| 74 } // namespace ui |
| 75 |
| 76 #endif // UI_ANDROID_RESOURCES_CRUSHED_SPRITE_RESOURCE_H_ |
OLD | NEW |