| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/client/compositor/blimp_compositor_android.h" | 5 #include "blimp/client/compositor/blimp_compositor_android.h" |
| 6 | 6 |
| 7 #include <android/native_window_jni.h> | |
| 8 | |
| 9 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 10 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 11 #include "ui/gfx/geometry/size.h" | 9 #include "ui/gfx/geometry/size.h" |
| 12 | 10 |
| 13 namespace { | 11 namespace { |
| 14 // The minimum valid content width in a tile. This is used to make sure the | 12 // The minimum valid content width in a tile. This is used to make sure the |
| 15 // width of the content on the rightmost tile isn't a tiny sliver. | 13 // width of the content on the rightmost tile isn't a tiny sliver. |
| 16 const int kMinimumTileContentWidthPixels = 64; | 14 const int kMinimumTileContentWidthPixels = 64; |
| 17 } | 15 } |
| 18 | 16 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 32 return make_scoped_ptr( | 30 return make_scoped_ptr( |
| 33 new BlimpCompositorAndroid(device_size, real_size_supported, dp_to_px)); | 31 new BlimpCompositorAndroid(device_size, real_size_supported, dp_to_px)); |
| 34 } | 32 } |
| 35 | 33 |
| 36 BlimpCompositorAndroid::BlimpCompositorAndroid(const gfx::Size& size, | 34 BlimpCompositorAndroid::BlimpCompositorAndroid(const gfx::Size& size, |
| 37 bool real_size_supported, | 35 bool real_size_supported, |
| 38 float dp_to_px) | 36 float dp_to_px) |
| 39 : BlimpCompositor(dp_to_px), | 37 : BlimpCompositor(dp_to_px), |
| 40 portrait_width_(std::min(size.width(), size.height())), | 38 portrait_width_(std::min(size.width(), size.height())), |
| 41 landscape_width_(std::max(size.width(), size.height())), | 39 landscape_width_(std::max(size.width(), size.height())), |
| 42 real_size_supported_(real_size_supported), | 40 real_size_supported_(real_size_supported) {} |
| 43 window_(nullptr) {} | |
| 44 | 41 |
| 45 BlimpCompositorAndroid::~BlimpCompositorAndroid() { | 42 BlimpCompositorAndroid::~BlimpCompositorAndroid() {} |
| 46 SetSurface(nullptr, 0 /* null surface */); | |
| 47 } | |
| 48 | |
| 49 void BlimpCompositorAndroid::SetSurface(JNIEnv* env, jobject jsurface) { | |
| 50 if (window_) { | |
| 51 SetVisible(false); | |
| 52 ANativeWindow_release(window_); | |
| 53 window_ = nullptr; | |
| 54 } | |
| 55 | |
| 56 if (!jsurface) | |
| 57 return; | |
| 58 | |
| 59 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | |
| 60 window_ = ANativeWindow_fromSurface(env, jsurface); | |
| 61 SetVisible(true); | |
| 62 } | |
| 63 | |
| 64 gfx::AcceleratedWidget BlimpCompositorAndroid::GetWindow() { | |
| 65 return window_; | |
| 66 } | |
| 67 | 43 |
| 68 void BlimpCompositorAndroid::GenerateLayerTreeSettings( | 44 void BlimpCompositorAndroid::GenerateLayerTreeSettings( |
| 69 cc::LayerTreeSettings* settings) { | 45 cc::LayerTreeSettings* settings) { |
| 70 BlimpCompositor::GenerateLayerTreeSettings(settings); | 46 BlimpCompositor::GenerateLayerTreeSettings(settings); |
| 71 | 47 |
| 72 // Calculate the correct raster tile size to use. Assuming a square tile. | 48 // Calculate the correct raster tile size to use. Assuming a square tile. |
| 73 DCHECK_EQ(settings->default_tile_size.width(), | 49 DCHECK_EQ(settings->default_tile_size.width(), |
| 74 settings->default_tile_size.height()); | 50 settings->default_tile_size.height()); |
| 75 | 51 |
| 76 int default_tile_size = settings->default_tile_size.width(); | 52 int default_tile_size = settings->default_tile_size.width(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 105 int numTiles = (portrait_width_ * landscape_width_) / (256 * 256); | 81 int numTiles = (portrait_width_ * landscape_width_) / (256 * 256); |
| 106 if (numTiles > 16) | 82 if (numTiles > 16) |
| 107 default_tile_size = 384; | 83 default_tile_size = 384; |
| 108 if (numTiles >= 40) | 84 if (numTiles >= 40) |
| 109 default_tile_size = 512; | 85 default_tile_size = 512; |
| 110 } | 86 } |
| 111 settings->default_tile_size.SetSize(default_tile_size, default_tile_size); | 87 settings->default_tile_size.SetSize(default_tile_size, default_tile_size); |
| 112 } | 88 } |
| 113 | 89 |
| 114 } // namespace blimp | 90 } // namespace blimp |
| OLD | NEW |