Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Side by Side Diff: ui/android/resources/crushed_sprite_resource.h

Issue 1337703002: [Contextual Search] Add support for crushed sprites and animate the search provider icon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes from last dtrainor@ review Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/ref_counted.h"
13 #include "ui/android/ui_android_export.h"
14 #include "ui/gfx/android/java_bitmap.h"
15 #include "ui/gfx/geometry/rect.h"
16
17 namespace ui {
18
19 // A resource that provides an unscaled bitmap and corresponding metadata for a
20 // crushed sprite. A crushed sprite animation is run by drawing rectangles from
21 // a bitmap to a canvas. Each frame in the animation draws its rectangles on top
22 // of the previous frame.
23 class UI_ANDROID_EXPORT CrushedSpriteResource :
24 public base::RefCounted<CrushedSpriteResource> {
25 public:
26 typedef std::vector<std::pair<gfx::Rect, gfx::Rect>> FrameSrcDstRects;
27 typedef std::vector<FrameSrcDstRects> SrcDstRects;
28
29 // Creates a new CrushedSpriteResource. |bitmap_res_id| is the id for the
30 // for the source bitmap, |java_bitmap| is the source bitmap for the crushed
31 // sprite, |src_dst_rects| is a list of rectangles to draw for each frame, and
32 // |sprite_size| is the size of an individual sprite.
33 static scoped_refptr<CrushedSpriteResource> CreateFromJavaBitmap(
34 int bitmap_res_id,
35 const gfx::JavaBitmap& java_bitmap,
36 const SrcDstRects& src_dst_rects,
37 gfx::Size sprite_size);
38
39 // Sets the source bitmap to |java_bitmap|.
40 void SetBitmapFromJavaBitmap(const gfx::JavaBitmap& java_bitmap);
41
42 // Returns the source bitmap.
43 SkBitmap GetBitmap();
44
45 // Stores the bitmap for the last frame and evicts the source bitmap from
46 // memory. This should be called when the crushed sprite animation finishes
47 // if it is unlikely to be rerun.
48 void SetBitmapForLastFrame(SkBitmap last_frame_bitmap);
49
50 // Returns the bitmap for the last frame if available or an empty bitmap.
51 SkBitmap GetBitmapForLastFrame();
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 // Returns the resource id for the source bitmap.
66 int GetBitmapResourceId();
67
68 private:
69 friend class base::RefCounted<CrushedSpriteResource>;
70 CrushedSpriteResource(
71 int bitmap_res_id,
72 const SkBitmap& bitmap,
73 const SrcDstRects& src_dst_rects,
74 gfx::Size sprite_size);
75 ~CrushedSpriteResource();
76
77 SkBitmap bitmap_;
78 SkBitmap last_frame_bitmap_;
79 SrcDstRects src_dst_rects_;
80 gfx::Size sprite_size_;
81 int bitmap_res_id_;
82
83 DISALLOW_COPY_AND_ASSIGN(CrushedSpriteResource);
84 };
85
86 } // namespace ui
87
88 #endif // UI_ANDROID_RESOURCES_CRUSHED_SPRITE_RESOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698