| 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..63641accb935ee44741c0b493f3bbc937e8eab81
|
| --- /dev/null
|
| +++ b/ui/android/resources/crushed_sprite_resource.h
|
| @@ -0,0 +1,88 @@
|
| +// 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/macros.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "ui/android/ui_android_export.h"
|
| +#include "ui/gfx/android/java_bitmap.h"
|
| +#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> {
|
| + 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,
|
| + const SrcDstRects& src_dst_rects,
|
| + gfx::Size 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);
|
| +
|
| + // 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.
|
| + gfx::Size GetSpriteSize();
|
| +
|
| + // Returns the total number of frames in the sprite animation.
|
| + int GetFrameCount();
|
| +
|
| + // Returns the resource id for the source bitmap.
|
| + int GetBitmapResourceId();
|
| +
|
| + private:
|
| + friend class base::RefCounted<CrushedSpriteResource>;
|
| + CrushedSpriteResource(
|
| + int bitmap_res_id,
|
| + const SkBitmap& bitmap,
|
| + const SrcDstRects& src_dst_rects,
|
| + gfx::Size sprite_size);
|
| + ~CrushedSpriteResource();
|
| +
|
| + SkBitmap bitmap_;
|
| + SkBitmap last_frame_bitmap_;
|
| + SrcDstRects src_dst_rects_;
|
| + gfx::Size sprite_size_;
|
| + int bitmap_res_id_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CrushedSpriteResource);
|
| +};
|
| +
|
| +} // namespace ui
|
| +
|
| +#endif // UI_ANDROID_RESOURCES_CRUSHED_SPRITE_RESOURCE_H_
|
|
|