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

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: Add TODO's for other planned tests Created 5 years, 2 months 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/memory/ref_counted.h"
12 #include "ui/android/ui_android_export.h"
13 #include "ui/gfx/android/java_bitmap.h"
David Trainor- moved to gerrit 2015/10/15 21:04:57 Can we forward declare this and not include it in
Theresa 2015/10/24 00:06:46 I can; I would also need to forward declare or inc
David Trainor- moved to gerrit 2015/10/27 15:14:47 I would always forward declare if you can.
Theresa 2015/10/27 19:48:02 Done.
14 #include "ui/gfx/geometry/rect.h"
15
16 namespace ui {
17
18 // A resource that provides an unscaled bitmap and corresponding metadata for a
19 // crushed sprite. A crushed sprite animation is run by drawing rectangles from
20 // a bitmap to a canvas. Each frame in the animation draws its rectangles on top
21 // of the previous frame.
22 class UI_ANDROID_EXPORT CrushedSpriteResource :
23 public base::RefCounted<CrushedSpriteResource> {
David Trainor- moved to gerrit 2015/10/15 21:04:58 Does it have to be ref counted?
Theresa 2015/10/24 00:06:45 I wanted it to get automatically destroyed when it
David Trainor- moved to gerrit 2015/10/27 15:14:47 IIRC the IDMap is set to IDMapOwnPointer so it'll
Theresa 2015/10/27 19:48:02 Done.
24 public:
25 typedef std::vector<std::pair<gfx::Rect, gfx::Rect>> FrameSrcDstRects;
26 typedef std::vector<FrameSrcDstRects> SrcDstRects;
27
28 // Creates a new CrushedSpriteResource. |bitmap_res_id| is the id for the
29 // for the source bitmap, |java_bitmap| is the source bitmap for the crushed
30 // sprite, |src_dst_rects| is a list of rectangles to draw for each frame, and
31 // |sprite_size| is the size of an individual sprite.
32 static scoped_refptr<CrushedSpriteResource> CreateFromJavaBitmap(
33 int bitmap_res_id,
34 const gfx::JavaBitmap& java_bitmap,
David Trainor- moved to gerrit 2015/10/15 21:04:58 Would it be better to hide the fact that this came
Theresa 2015/10/24 00:06:45 I modeled it off the old UIResourceAndroid https:/
David Trainor- moved to gerrit 2015/10/27 15:14:47 Acknowledged.
Theresa 2015/10/27 19:48:02 Changed to an SkBitmap
35 const SrcDstRects& src_dst_rects,
36 int sprite_size);
37
38 // Sets the source bitmap to |java_bitmap|.
39 void SetBitmapFromJavaBitmap(const gfx::JavaBitmap& java_bitmap);
40
41 // Returns the source bitmap.
42 SkBitmap GetBitmap();
43
44 // Stores the bitmap for the last frame and evicts the source bitmap from
45 // memory. This should be called when the crushed sprite animation finishes
46 // if it is unlikely to be rerun.
47 void SetBitmapForLastFrame(SkBitmap last_frame_bitmap);
David Trainor- moved to gerrit 2015/10/15 21:04:58 I would hide a lot of this and just expose somethi
Theresa 2015/10/24 00:06:46 contextual_search_layer will call getResource each
David Trainor- moved to gerrit 2015/10/27 15:14:47 Yeah this is the downside of sharing the bitmap th
Theresa 2015/10/27 19:48:02 As discussed offline,removed the logic for caching
48
49 // Returns the bitmap for the last frame if available or an empty bitmap.
50 SkBitmap GetBitmapForLastFrame();
51
52 // Returns true if the source bitmap has been evicted from memory.
53 bool BitmapHasBeenEvictedFromMemory();
54
55 // Returns a list of rectangles to be drawn for |frame|.
56 FrameSrcDstRects GetRectanglesForFrame(int frame);
57
58 // Returns the size of an individual sprite.
59 int GetSpriteSize();
60
61 // Returns the total number of frames in the sprite animation.
62 int GetFrameCount();
63
64 // Returns the resource id for the source bitmap.
65 int GetBitmapResourceId();
David Trainor- moved to gerrit 2015/10/15 21:04:58 Shouldn't be necessary I think?
Theresa 2015/10/24 00:06:46 This method is currently being used to reload the
66
67 private:
68 friend class base::RefCounted<CrushedSpriteResource>;
69 CrushedSpriteResource(
70 int bitmap_res_id,
71 const SkBitmap& bitmap,
72 const SrcDstRects& src_dst_rects,
73 int sprite_size);
74 ~CrushedSpriteResource();
75
76 SkBitmap bitmap_;
77 SkBitmap last_frame_bitmap_;
David Trainor- moved to gerrit 2015/10/15 21:04:57 Shouldn't need?
78 SrcDstRects src_dst_rects_;
79 int sprite_size_;
80 int bitmap_res_id_;
David Trainor- moved to gerrit 2015/10/15 21:04:58 We should be able to rely on the res_id from all c
Theresa 2015/10/24 00:06:45 If the call to reload the crushed sprite resource
81
82 DISALLOW_COPY_AND_ASSIGN(CrushedSpriteResource);
83 };
84
85 } // namespace ui
86
87 #endif // UI_ANDROID_RESOURCES_CRUSHED_SPRITE_RESOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698