OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #include "blimp/client/compositor/blimp_compositor_android.h" |
| 6 |
| 7 #include <android/native_window_jni.h> |
| 8 |
| 9 #include "base/command_line.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "ui/gfx/geometry/size.h" |
| 12 |
| 13 namespace blimp { |
| 14 |
| 15 // static |
| 16 scoped_ptr<BlimpCompositorAndroid> BlimpCompositorAndroid::Create( |
| 17 const gfx::Size& physical_size, |
| 18 const gfx::Size& display_size, |
| 19 float device_scale_factor) { |
| 20 gfx::Size device_size(physical_size); |
| 21 bool real_size_supported = true; |
| 22 if (device_size.width() == 0 || device_size.height() == 0) { |
| 23 real_size_supported = false; |
| 24 device_size = display_size; |
| 25 } |
| 26 return make_scoped_ptr(new BlimpCompositorAndroid( |
| 27 device_size, real_size_supported, device_scale_factor)); |
| 28 } |
| 29 |
| 30 BlimpCompositorAndroid::BlimpCompositorAndroid(const gfx::Size& device_size, |
| 31 bool real_size_supported, |
| 32 float device_scale_factor) |
| 33 : BlimpCompositor(device_scale_factor), |
| 34 portrait_width_(std::min(device_size.width(), device_size.height())), |
| 35 landscape_width_(std::max(device_size.width(), device_size.height())), |
| 36 real_size_supported_(real_size_supported), |
| 37 window_(nullptr) {} |
| 38 |
| 39 BlimpCompositorAndroid::~BlimpCompositorAndroid() { |
| 40 SetSurface(nullptr, 0 /* null surface */); |
| 41 } |
| 42 |
| 43 void BlimpCompositorAndroid::SetSurface(JNIEnv* env, jobject jsurface) { |
| 44 if (window_) { |
| 45 SetVisible(false); |
| 46 ANativeWindow_release(window_); |
| 47 window_ = nullptr; |
| 48 } |
| 49 |
| 50 if (!jsurface) |
| 51 return; |
| 52 |
| 53 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
| 54 window_ = ANativeWindow_fromSurface(env, jsurface); |
| 55 SetVisible(true); |
| 56 } |
| 57 |
| 58 gfx::AcceleratedWidget BlimpCompositorAndroid::GetWindow() { |
| 59 return window_; |
| 60 } |
| 61 |
| 62 void BlimpCompositorAndroid::GenerateLayerTreeSettings( |
| 63 cc::LayerTreeSettings* settings, |
| 64 const base::CommandLine& cmd) { |
| 65 BlimpCompositor::GenerateLayerTreeSettings(settings, cmd); |
| 66 |
| 67 // Calculate the correct raster tile size to use. Assuming a square tile. |
| 68 DCHECK_EQ(settings->default_tile_size.width(), |
| 69 settings->default_tile_size.height()); |
| 70 |
| 71 int default_tile_size = settings->default_tile_size.width(); |
| 72 if (real_size_supported_) { |
| 73 // Maximum HD dimensions should be 768x1280 |
| 74 // Maximum FHD dimensions should be 1200x1920 |
| 75 if (portrait_width_ > 768 || landscape_width_ > 1280) |
| 76 default_tile_size = 384; |
| 77 if (portrait_width_ > 1200 || landscape_width_ > 1920) |
| 78 default_tile_size = 512; |
| 79 |
| 80 // Adjust for some resolutions that barely straddle an extra |
| 81 // tile when in portrait mode. This helps worst case scroll/raster |
| 82 // by not needing a full extra tile for each row. |
| 83 if (default_tile_size == 256 && portrait_width_ == 768) |
| 84 default_tile_size += 32; |
| 85 if (default_tile_size == 384 && portrait_width_ == 1200) |
| 86 default_tile_size += 32; |
| 87 } else { |
| 88 // We don't know the exact resolution due to screen controls etc., so this |
| 89 // just estimates the values above using tile counts. |
| 90 int numTiles = (portrait_width_ * landscape_width_) / (256 * 256); |
| 91 if (numTiles > 16) |
| 92 default_tile_size = 384; |
| 93 if (numTiles >= 40) |
| 94 default_tile_size = 512; |
| 95 } |
| 96 settings->default_tile_size.SetSize(default_tile_size, default_tile_size); |
| 97 } |
| 98 |
| 99 } // namespace blimp |
OLD | NEW |