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 <memory> | |
9 #include <utility> | |
10 #include <vector> | |
11 | |
12 #include "base/macros.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 typedef int UIResourceId; | |
19 } | |
20 | |
21 namespace ui { | |
22 | |
23 // A resource that provides an unscaled bitmap and corresponding metadata for a | |
24 // crushed sprite. A crushed sprite animation is run by drawing rectangles from | |
25 // a bitmap to a canvas. Each frame in the animation draws its rectangles on top | |
26 // of the previous frame. | |
27 class UI_ANDROID_EXPORT CrushedSpriteResource { | |
28 public: | |
29 typedef std::vector<std::pair<gfx::Rect, gfx::Rect>> FrameSrcDstRects; | |
30 typedef std::vector<FrameSrcDstRects> SrcDstRects; | |
31 | |
32 // Creates a new CrushedSpriteResource. |bitmap_res_id| is the id for the | |
33 // for the source bitmap, |java_bitmap| is the source bitmap for the crushed | |
34 // sprite, |src_dst_rects| is a list of rectangles to draw for each frame, and | |
35 // |unscaled_sprite_size| is the size of an individual sprite unscaled. The | |
36 // sprite should be drawn at its unscaled size then scaled to | |
37 // |scaled_sprite_size|. | |
38 CrushedSpriteResource(const SkBitmap& bitmap, | |
39 const SrcDstRects& src_dst_rects, | |
40 gfx::Size unscaled_sprite_size, | |
41 gfx::Size scaled_sprite_size); | |
42 ~CrushedSpriteResource(); | |
43 | |
44 // Sets the source bitmap. | |
45 void SetBitmap(const SkBitmap& bitmap); | |
46 | |
47 // Returns the source bitmap. | |
48 const SkBitmap& GetBitmap(); | |
49 | |
50 // Evicts bitmap_ from memory. | |
51 void EvictBitmapFromMemory(); | |
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 unscaled size of an individual sprite. | |
60 gfx::Size GetUnscaledSpriteSize(); | |
61 | |
62 // Returns the scaled size of an individual sprite. | |
63 gfx::Size GetScaledSpriteSize(); | |
64 | |
65 // Returns the total number of frames in the sprite animation. | |
66 int GetFrameCount(); | |
67 | |
68 // Returns the memory usage of the bitmap. | |
69 size_t EstimateMemoryUsage() const; | |
70 | |
71 private: | |
72 SkBitmap bitmap_; | |
73 SrcDstRects src_dst_rects_; | |
74 gfx::Size unscaled_sprite_size_; | |
75 gfx::Size scaled_sprite_size_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(CrushedSpriteResource); | |
78 }; | |
79 | |
80 } // namespace ui | |
81 | |
82 #endif // UI_ANDROID_RESOURCES_CRUSHED_SPRITE_RESOURCE_H_ | |
OLD | NEW |