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

Unified Diff: chrome/browser/android/thumbnail/thumbnail.cc

Issue 262543002: android: add ThumbnailCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@codec
Patch Set: addressed comments Created 6 years, 6 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: chrome/browser/android/thumbnail/thumbnail.cc
diff --git a/chrome/browser/android/thumbnail/thumbnail.cc b/chrome/browser/android/thumbnail/thumbnail.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2dacd966c14015a94ddc62ef528a239610c9f48f
--- /dev/null
+++ b/chrome/browser/android/thumbnail/thumbnail.cc
@@ -0,0 +1,125 @@
+// Copyright 2014 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.
+
+#include "chrome/browser/android/thumbnail/thumbnail.h"
+#include "content/public/browser/android/ui_resource_provider.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "ui/gfx/geometry/size_conversions.h"
+
+namespace {
+
+SkBitmap CreateSmallHolderBitmap() {
+ SkBitmap small_bitmap;
+ SkCanvas canvas(small_bitmap);
+ small_bitmap.setConfig(
+ SkBitmap::kARGB_8888_Config, 1, 1, 0, kOpaque_SkAlphaType);
+ small_bitmap.allocPixels();
+ canvas.drawColor(SK_ColorWHITE);
+ small_bitmap.setImmutable();
+ return small_bitmap;
+}
+
+const SkBitmap kSmallHolderBitmap = CreateSmallHolderBitmap();
+
+} // anonymous namespace
+
+Thumbnail::Thumbnail()
+ : tab_id_(0),
+ scale_(0),
+ bitmap_(kSmallHolderBitmap),
+ ui_resource_id_(0),
+ retrieved_(false),
+ ui_resource_provider_(NULL),
+ thumbnail_manager_(NULL) {
+}
+
+Thumbnail::Thumbnail(TabId tab_id,
+ const base::Time& time_stamp,
+ float scale,
+ content::UIResourceProvider* ui_resource_provider,
+ ThumbnailManager* thumbnail_manager)
+ : tab_id_(tab_id),
+ time_stamp_(time_stamp),
+ scale_(scale),
+ bitmap_(gfx::Size(1, 1), true),
+ ui_resource_id_(0),
+ retrieved_(false),
+ ui_resource_provider_(ui_resource_provider),
+ thumbnail_manager_(thumbnail_manager) {
+}
+
+Thumbnail::~Thumbnail() {
+ ClearUIResourceId();
+}
+
+void Thumbnail::SetBitmap(const SkBitmap& bitmap) {
+ DCHECK(!bitmap.empty());
+ ClearUIResourceId();
+ scaled_content_size_ =
+ gfx::ScaleSize(gfx::Size(bitmap.width(), bitmap.height()), 1.f / scale_);
+ scaled_data_size_ = scaled_content_size_;
+ bitmap_ = cc::UIResourceBitmap(bitmap);
+}
+
+void Thumbnail::SetCompressedBitmap(skia::RefPtr<SkPixelRef> compressed_bitmap,
+ gfx::Size content_size) {
+ DCHECK(compressed_bitmap);
+ DCHECK(!content_size.IsEmpty());
+ ClearUIResourceId();
+ gfx::Size data_size(compressed_bitmap->info().width(),
+ compressed_bitmap->info().height());
+ scaled_content_size_ = gfx::ScaleSize(content_size, 1.f / scale_);
+ scaled_data_size_ = gfx::ScaleSize(data_size, 1.f / scale_);
+ bitmap_ = cc::UIResourceBitmap(compressed_bitmap, data_size);
+}
+
+void Thumbnail::CreateUIResource() {
+ DCHECK(ui_resource_provider_);
+ if (!ui_resource_id_)
+ ui_resource_id_ = ui_resource_provider_->CreateUIResource(this);
+}
+
+cc::UIResourceBitmap Thumbnail::GetBitmap(cc::UIResourceId uid,
+ bool resource_lost) {
+ if (retrieved_)
+ return bitmap_;
+
+ retrieved_ = true;
+
+ cc::UIResourceBitmap old_bitmap(bitmap_);
+ // Return a place holder for all other calls to GetBitmap.
+ bitmap_ = cc::UIResourceBitmap(kSmallHolderBitmap);
David Trainor- moved to gerrit 2014/07/14 20:30:45 Not sure if this is a problem (haven't seen other
powei 2014/07/14 23:56:25 The write task is a ref-holder of the same pixels,
David Trainor- moved to gerrit 2014/07/15 20:08:23 Yeah that's fine with me :). It looks like you ar
powei 2014/07/18 00:51:49 Acknowledged.
+ return old_bitmap;
+}
+
+void Thumbnail::UIResourceIsInvalid() {
+ ui_resource_id_ = 0;
+ if (thumbnail_manager_)
+ thumbnail_manager_->InvalidateCachedThumbnail(*this);
+}
+
+Thumbnail& Thumbnail::operator=(const Thumbnail& rhs) {
+ DCHECK(!rhs.ui_resource_id_);
+ ClearUIResourceId();
+
+ tab_id_ = rhs.tab_id_;
+ time_stamp_ = rhs.time_stamp_;
+ scale_ = rhs.scale_;
+ scaled_content_size_ = rhs.scaled_content_size_;
+ scaled_data_size_ = rhs.scaled_data_size_;
+ bitmap_ = rhs.bitmap_;
+ ui_resource_id_ = rhs.ui_resource_id_;
+ retrieved_ = rhs.retrieved_;
+ ui_resource_provider_ = rhs.ui_resource_provider_;
+ thumbnail_manager_ = rhs.thumbnail_manager_;
+
+ return (*this);
+}
+
+void Thumbnail::ClearUIResourceId() {
+ if (ui_resource_id_ && ui_resource_provider_)
+ ui_resource_provider_->DeleteUIResource(ui_resource_id_);
+ ui_resource_id_ = 0;
+}

Powered by Google App Engine
This is Rietveld 408576698