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

Unified Diff: blimp/client/compositor/blimp_compositor_android.cc

Issue 1295243003: Initial commit of the blimp/ folder and target (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaned it up, addressed nyquist@ nits Created 5 years, 4 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: blimp/client/compositor/blimp_compositor_android.cc
diff --git a/blimp/client/compositor/blimp_compositor_android.cc b/blimp/client/compositor/blimp_compositor_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ce258af0be317a6282f03e2db02f6acf49b2fc6c
--- /dev/null
+++ b/blimp/client/compositor/blimp_compositor_android.cc
@@ -0,0 +1,99 @@
+// 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.
+
+#include "blimp/client/compositor/blimp_compositor_android.h"
+
+#include <android/native_window_jni.h>
+
+#include "base/command_line.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace blimp {
+
+// static
+scoped_ptr<BlimpCompositorAndroid> BlimpCompositorAndroid::Create(
+ const gfx::Size& physical_size,
+ const gfx::Size& display_size,
+ float device_scale_factor) {
+ gfx::Size device_size(physical_size);
+ bool real_size_supported = true;
+ if (device_size.width() == 0 || device_size.height() == 0) {
+ real_size_supported = false;
+ device_size = display_size;
+ }
+ return make_scoped_ptr(new BlimpCompositorAndroid(
+ device_size, real_size_supported, device_scale_factor));
+}
+
+BlimpCompositorAndroid::BlimpCompositorAndroid(const gfx::Size& device_size,
+ bool real_size_supported,
+ float device_scale_factor)
+ : BlimpCompositor(device_scale_factor),
+ portrait_width_(std::min(device_size.width(), device_size.height())),
+ landscape_width_(std::max(device_size.width(), device_size.height())),
+ real_size_supported_(real_size_supported),
+ window_(nullptr) {}
+
+BlimpCompositorAndroid::~BlimpCompositorAndroid() {
+ SetSurface(nullptr, 0 /* null surface */);
+}
+
+void BlimpCompositorAndroid::SetSurface(JNIEnv* env, jobject jsurface) {
+ if (window_) {
+ SetVisible(false);
+ ANativeWindow_release(window_);
+ window_ = nullptr;
+ }
+
+ if (!jsurface)
+ return;
+
+ base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
+ window_ = ANativeWindow_fromSurface(env, jsurface);
+ SetVisible(true);
+}
+
+gfx::AcceleratedWidget BlimpCompositorAndroid::GetWindow() {
+ return window_;
+}
+
+void BlimpCompositorAndroid::GenerateLayerTreeSettings(
+ cc::LayerTreeSettings& settings,
+ const base::CommandLine& cmd) {
+ BlimpCompositor::GenerateLayerTreeSettings(settings, cmd);
+
+ // Calculate the correct raster tile size to use. Assuming a square tile.
+ DCHECK_EQ(settings.default_tile_size.width(),
+ settings.default_tile_size.height());
+
+ int default_tile_size = settings.default_tile_size.width();
+ if (real_size_supported_) {
+ // Maximum HD dimensions should be 768x1280
+ // Maximum FHD dimensions should be 1200x1920
+ if (portrait_width_ > 768 || landscape_width_ > 1280)
+ default_tile_size = 384;
+ if (portrait_width_ > 1200 || landscape_width_ > 1920)
+ default_tile_size = 512;
+
+ // Adjust for some resolutions that barely straddle an extra
Kevin Marshall 2015/08/21 18:46:35 How about computing the size tweaks mathematically
David Trainor- moved to gerrit 2015/08/28 01:23:44 Done.
+ // tile when in portrait mode. This helps worst case scroll/raster
+ // by not needing a full extra tile for each row.
+ if (default_tile_size == 256 && portrait_width_ == 768)
+ default_tile_size += 32;
+ if (default_tile_size == 384 && portrait_width_ == 1200)
+ default_tile_size += 32;
+ } else {
+ // We don't know the exact resolution due to screen controls etc., so this
+ // just estimates the values above using tile counts.
+ int numTiles = (portrait_width_ * landscape_width_) / (256 * 256);
+ if (numTiles > 16)
+ default_tile_size = 384;
+ if (numTiles >= 40)
+ default_tile_size = 512;
+ }
+ settings.default_tile_size.SetSize(default_tile_size, default_tile_size);
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698