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

Side by Side 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: rebased Created 5 years, 3 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 unified diff | Download patch
OLDNEW
(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 // The minimum size increase for tiles (we want them to be multiples of 32).
Wez 2015/09/03 00:49:28 nit: "size increase" doesn't mean much in this con
David Trainor- moved to gerrit 2015/09/03 06:33:21 I'm not sure. I don't think so. I think the tile
19 const int kTileSizeIncrementStepPixels = 32;
20 }
21
22 namespace blimp {
23
24 // static
25 scoped_ptr<BlimpCompositorAndroid> BlimpCompositorAndroid::Create(
26 const gfx::Size& physical_size,
27 const gfx::Size& display_size,
28 float device_scale_factor) {
29 gfx::Size device_size(physical_size);
30 bool real_size_supported = true;
31 if (device_size.IsEmpty()) {
32 real_size_supported = false;
33 device_size = display_size;
34 }
35 return make_scoped_ptr(new BlimpCompositorAndroid(
36 device_size, real_size_supported, device_scale_factor));
37 }
38
39 BlimpCompositorAndroid::BlimpCompositorAndroid(const gfx::Size& device_size,
40 bool real_size_supported,
41 float device_scale_factor)
42 : BlimpCompositor(device_scale_factor),
43 portrait_width_(std::min(device_size.width(), device_size.height())),
44 landscape_width_(std::max(device_size.width(), device_size.height())),
45 real_size_supported_(real_size_supported),
46 window_(nullptr) {}
47
48 BlimpCompositorAndroid::~BlimpCompositorAndroid() {
49 SetSurface(nullptr, 0 /* null surface */);
50 }
51
52 void BlimpCompositorAndroid::SetSurface(JNIEnv* env, jobject jsurface) {
53 if (window_) {
54 SetVisible(false);
55 ANativeWindow_release(window_);
56 window_ = nullptr;
57 }
58
59 if (!jsurface)
60 return;
61
62 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
63 window_ = ANativeWindow_fromSurface(env, jsurface);
64 SetVisible(true);
65 }
66
67 gfx::AcceleratedWidget BlimpCompositorAndroid::GetWindow() {
68 return window_;
69 }
70
71 void BlimpCompositorAndroid::GenerateLayerTreeSettings(
72 cc::LayerTreeSettings* settings,
73 const base::CommandLine& cmd) {
74 BlimpCompositor::GenerateLayerTreeSettings(settings, cmd);
75
76 // Calculate the correct raster tile size to use. Assuming a square tile.
77 DCHECK_EQ(settings->default_tile_size.width(),
78 settings->default_tile_size.height());
79
80 int default_tile_size = settings->default_tile_size.width();
81 if (real_size_supported_) {
82 // Maximum HD dimensions should be 768x1280
83 // Maximum FHD dimensions should be 1200x1920
84 if (portrait_width_ > 768 || landscape_width_ > 1280)
85 default_tile_size = 384;
86 if (portrait_width_ > 1200 || landscape_width_ > 1920)
87 default_tile_size = 512;
88
89 // Adjust for some resolutions that barely straddle an extra
90 // tile when in portrait mode. This helps worst case scroll/raster
91 // by not needing a full extra tile for each row.
92 int right_tile_width = portrait_width_ % default_tile_size;
Wez 2015/09/03 00:49:27 Isn't the rightmost tile width: ((portrait_width_
David Trainor- moved to gerrit 2015/09/03 06:33:21 Good idea. Done.
93 if (right_tile_width != 0 &&
94 right_tile_width < kMinimumTileContentWidthPixels) {
95 int num_full_tiles = portrait_width_ / default_tile_size;
96
97 // Figure out how many increments of kTileSizeIncrementStepPixels are
98 // needed to fill the small remaining gap.
99 int step_increase = std::ceil(
100 static_cast<float>(right_tile_width) /
101 static_cast<float>(num_full_tiles * kTileSizeIncrementStepPixels));
Wez 2015/09/03 00:49:28 It's not clear to me what the connection between t
David Trainor- moved to gerrit 2015/09/03 06:33:21 Done.
102 default_tile_size += step_increase * kTileSizeIncrementStepPixels;
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698