OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 CHROME_BROWSER_ANDROID_THUMBNAIL_THUMBNAIL_IMPL_H_ |
| 6 #define CHROME_BROWSER_ANDROID_THUMBNAIL_THUMBNAIL_IMPL_H_ |
| 7 |
| 8 #include "chrome/browser/android/thumbnail/thumbnail.h" |
| 9 #include "content/public/browser/android/ui_resource_client_android.h" |
| 10 #include "skia/ext/refptr.h" |
| 11 #include "third_party/skia/include/core/SkBitmap.h" |
| 12 #include "ui/gfx/geometry/size.h" |
| 13 #include "ui/gfx/geometry/size_f.h" |
| 14 |
| 15 class ThumbnailCache; |
| 16 |
| 17 namespace base { |
| 18 class File; |
| 19 } |
| 20 |
| 21 namespace content { |
| 22 class UIResourceProvider; |
| 23 } |
| 24 |
| 25 class ThumbnailImpl; |
| 26 class ThumbnailImplManager { |
| 27 public: |
| 28 virtual void InvalidateCachedThumbnail( |
| 29 scoped_refptr<ThumbnailImpl> thumbnail) = 0; |
| 30 virtual ~ThumbnailImplManager() {} |
| 31 }; |
| 32 |
| 33 class ThumbnailImpl : public Thumbnail, |
| 34 public content::UIResourceClientAndroid { |
| 35 public: |
| 36 ThumbnailImpl(TabId tab_id, |
| 37 const SkBitmap& bitmap, |
| 38 float scale, |
| 39 ThumbnailImplManager* thumbnail_impl_manager, |
| 40 content::UIResourceProvider* ui_resource_provider); |
| 41 bool IsValid() const; |
| 42 |
| 43 // Thumbnail implementation. |
| 44 virtual gfx::Size GetScaledContentSize() const OVERRIDE; |
| 45 virtual gfx::SizeF GetScaledDataSize() const OVERRIDE; |
| 46 virtual cc::UIResourceId ui_resource_id() const OVERRIDE { |
| 47 return ui_resource_id_; |
| 48 } |
| 49 virtual TabId tab_id() const OVERRIDE { return tab_id_; } |
| 50 |
| 51 static void Compress(scoped_refptr<ThumbnailImpl> in_thumbnail, |
| 52 scoped_refptr<ThumbnailImpl> out_thumbnail); |
| 53 static bool WriteToFile(scoped_refptr<ThumbnailImpl> thumbnail, |
| 54 base::File& file); |
| 55 static bool ReadFromFile(base::File& file, |
| 56 scoped_refptr<ThumbnailImpl> thumbnail); |
| 57 |
| 58 scoped_refptr<ThumbnailImpl> PassDataToNewThumbnail(); |
| 59 |
| 60 // content::UIResourceClient implementation. |
| 61 virtual cc::UIResourceBitmap GetBitmap(cc::UIResourceId uid, |
| 62 bool resource_lost) OVERRIDE; |
| 63 |
| 64 // content::UIResourceClientAndroid implementation. |
| 65 virtual void UIResourceIsInvalid() OVERRIDE; |
| 66 |
| 67 protected: |
| 68 virtual ~ThumbnailImpl(); |
| 69 |
| 70 private: |
| 71 void CleanupUIResource(); |
| 72 void BuildUIResource(); |
| 73 void SetRawData(SkBitmap bitmap, float scale); |
| 74 void SetCompressedData(skia::RefPtr<SkPixelRef> compressed_data, |
| 75 float scale, |
| 76 const gfx::Size& content_size); |
| 77 TabId tab_id_; |
| 78 cc::UIResourceId ui_resource_id_; |
| 79 SkBitmap raw_data_; |
| 80 skia::RefPtr<SkPixelRef> compressed_data_; |
| 81 float scale_; |
| 82 gfx::Size data_size_; |
| 83 gfx::Size content_size_; |
| 84 |
| 85 ThumbnailImplManager* thumbnail_impl_manager_; |
| 86 content::UIResourceProvider* ui_resource_provider_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(ThumbnailImpl); |
| 89 }; |
| 90 |
| 91 #endif // CHROME_BROWSER_ANDROID_THUMBNAIL_THUMBNAIL_IMPL_H_ |
OLD | NEW |