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 { | |
14 // 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. | |
16 const int kMinimumTileContentWidthPixels = 64; | |
17 } | |
18 | |
19 namespace blimp { | |
20 | |
21 // static | |
22 scoped_ptr<BlimpCompositorAndroid> BlimpCompositorAndroid::Create( | |
23 const gfx::Size& physical_size, | |
24 const gfx::Size& display_size, | |
25 float device_scale_factor) { | |
26 gfx::Size device_size(physical_size); | |
27 bool real_size_supported = true; | |
28 if (device_size.IsEmpty()) { | |
29 real_size_supported = false; | |
30 device_size = display_size; | |
31 } | |
32 return make_scoped_ptr(new BlimpCompositorAndroid( | |
33 device_size, real_size_supported, device_scale_factor)); | |
34 } | |
35 | |
36 BlimpCompositorAndroid::BlimpCompositorAndroid(const gfx::Size& device_size, | |
37 bool real_size_supported, | |
38 float device_scale_factor) | |
39 : BlimpCompositor(device_scale_factor), | |
40 portrait_width_(std::min(device_size.width(), device_size.height())), | |
41 landscape_width_(std::max(device_size.width(), device_size.height())), | |
42 real_size_supported_(real_size_supported), | |
43 window_(nullptr) {} | |
44 | |
45 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 | |
68 void BlimpCompositorAndroid::GenerateLayerTreeSettings( | |
69 cc::LayerTreeSettings* settings) { | |
70 BlimpCompositor::GenerateLayerTreeSettings(settings); | |
71 | |
72 // Calculate the correct raster tile size to use. Assuming a square tile. | |
73 DCHECK_EQ(settings->default_tile_size.width(), | |
74 settings->default_tile_size.height()); | |
75 | |
76 int default_tile_size = settings->default_tile_size.width(); | |
77 if (real_size_supported_) { | |
78 // Maximum HD dimensions should be 768x1280 | |
79 // Maximum FHD dimensions should be 1200x1920 | |
80 if (portrait_width_ > 768 || landscape_width_ > 1280) | |
81 default_tile_size = 384; | |
82 if (portrait_width_ > 1200 || landscape_width_ > 1920) | |
83 default_tile_size = 512; | |
84 | |
85 // Adjust for some resolutions that barely straddle an extra | |
86 // tile when in portrait mode. This helps worst case scroll/raster | |
Wez
2015/09/03 18:26:11
Why do we only do this optimization for real_size_
David Trainor- moved to gerrit
2015/09/03 19:06:00
That's the way render_widget_compositor is handlin
Wez
2015/09/03 19:56:07
Acknowledged.
| |
87 // by not needing a full extra tile for each row. | |
88 int right_tile_width = (portrait_width_ - 1) % default_tile_size + 1; | |
Wez
2015/09/03 18:26:11
nit: Brackets around the % to make it clear that i
David Trainor- moved to gerrit
2015/09/03 19:06:01
Done.
| |
89 if (right_tile_width < kMinimumTileContentWidthPixels) { | |
90 // Figure out the new tile count without the small edge tile. | |
91 int new_tile_count = std::ceil(static_cast<float>(portrait_width_) / | |
92 static_cast<float>(default_tile_size)) - | |
93 1; | |
Wez
2015/09/03 18:26:11
Isn't ceil(A/B) - 1 in practice floor(A/B) in this
David Trainor- moved to gerrit
2015/09/03 19:06:01
Yeah that should work. Especially since we alread
| |
94 DCHECK_GT(new_tile_count, 0); | |
95 | |
96 // Calculate the ideal new tile width with the new tile count. | |
97 default_tile_size = std::ceil(static_cast<float>(portrait_width_) / | |
98 static_cast<float>(new_tile_count)); | |
99 | |
100 // Round up to nearest 32. | |
Wez
2015/09/03 18:26:11
nit: Explain why - sounds like this is for GPU eff
David Trainor- moved to gerrit
2015/09/03 19:06:01
Done.
| |
101 if (default_tile_size & 0x1F) | |
102 default_tile_size = (default_tile_size & ~0x1F) + 32; | |
103 } | |
104 } else { | |
105 // We don't know the exact resolution due to screen controls etc., so this | |
106 // just estimates the values above using tile counts. | |
107 int numTiles = (portrait_width_ * landscape_width_) / (256 * 256); | |
108 if (numTiles > 16) | |
109 default_tile_size = 384; | |
110 if (numTiles >= 40) | |
111 default_tile_size = 512; | |
112 } | |
113 settings->default_tile_size.SetSize(default_tile_size, default_tile_size); | |
114 } | |
115 | |
116 } // namespace blimp | |
OLD | NEW |