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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/android/resources/crushed_sprite_resource.h
diff --git a/ui/android/resources/crushed_sprite_resource.h b/ui/android/resources/crushed_sprite_resource.h
new file mode 100644
index 0000000000000000000000000000000000000000..2122b00125863f88afe8da4e748a0d06fe879598
--- /dev/null
+++ b/ui/android/resources/crushed_sprite_resource.h
@@ -0,0 +1,87 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_ANDROID_RESOURCES_CRUSHED_SPRITE_RESOURCE_H_
+#define UI_ANDROID_RESOURCES_CRUSHED_SPRITE_RESOURCE_H_
+
+#include <utility>
+#include <vector>
+
+#include "base/memory/ref_counted.h"
+#include "ui/android/ui_android_export.h"
+#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.
+#include "ui/gfx/geometry/rect.h"
+
+namespace ui {
+
+// A resource that provides an unscaled bitmap and corresponding metadata for a
+// crushed sprite. A crushed sprite animation is run by drawing rectangles from
+// a bitmap to a canvas. Each frame in the animation draws its rectangles on top
+// of the previous frame.
+class UI_ANDROID_EXPORT CrushedSpriteResource :
+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.
+ public:
+ typedef std::vector<std::pair<gfx::Rect, gfx::Rect>> FrameSrcDstRects;
+ typedef std::vector<FrameSrcDstRects> SrcDstRects;
+
+ // Creates a new CrushedSpriteResource. |bitmap_res_id| is the id for the
+ // for the source bitmap, |java_bitmap| is the source bitmap for the crushed
+ // sprite, |src_dst_rects| is a list of rectangles to draw for each frame, and
+ // |sprite_size| is the size of an individual sprite.
+ static scoped_refptr<CrushedSpriteResource> CreateFromJavaBitmap(
+ int bitmap_res_id,
+ 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
+ const SrcDstRects& src_dst_rects,
+ int sprite_size);
+
+ // Sets the source bitmap to |java_bitmap|.
+ void SetBitmapFromJavaBitmap(const gfx::JavaBitmap& java_bitmap);
+
+ // Returns the source bitmap.
+ SkBitmap GetBitmap();
+
+ // Stores the bitmap for the last frame and evicts the source bitmap from
+ // memory. This should be called when the crushed sprite animation finishes
+ // if it is unlikely to be rerun.
+ 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
+
+ // Returns the bitmap for the last frame if available or an empty bitmap.
+ SkBitmap GetBitmapForLastFrame();
+
+ // Returns true if the source bitmap has been evicted from memory.
+ bool BitmapHasBeenEvictedFromMemory();
+
+ // Returns a list of rectangles to be drawn for |frame|.
+ FrameSrcDstRects GetRectanglesForFrame(int frame);
+
+ // Returns the size of an individual sprite.
+ int GetSpriteSize();
+
+ // Returns the total number of frames in the sprite animation.
+ int GetFrameCount();
+
+ // Returns the resource id for the source bitmap.
+ 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
+
+ private:
+ friend class base::RefCounted<CrushedSpriteResource>;
+ CrushedSpriteResource(
+ int bitmap_res_id,
+ const SkBitmap& bitmap,
+ const SrcDstRects& src_dst_rects,
+ int sprite_size);
+ ~CrushedSpriteResource();
+
+ SkBitmap bitmap_;
+ SkBitmap last_frame_bitmap_;
David Trainor- moved to gerrit 2015/10/15 21:04:57 Shouldn't need?
+ SrcDstRects src_dst_rects_;
+ int sprite_size_;
+ 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
+
+ DISALLOW_COPY_AND_ASSIGN(CrushedSpriteResource);
+};
+
+} // namespace ui
+
+#endif // UI_ANDROID_RESOURCES_CRUSHED_SPRITE_RESOURCE_H_

Powered by Google App Engine
This is Rietveld 408576698