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

Side by Side Diff: blimp/client/app/android/blimp_contents_display.cc

Issue 2624903006: Remove all blimp client code. (Closed)
Patch Set: Update buildbot configuration Created 3 years, 11 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/app/android/blimp_contents_display.h"
6
7 #include <android/native_window_jni.h>
8
9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h"
11 #include "blimp/client/app/android/blimp_environment.h"
12 #include "blimp/client/app/compositor/browser_compositor.h"
13 #include "blimp/client/public/compositor/compositor_dependencies.h"
14 #include "blimp/client/public/contents/blimp_contents.h"
15 #include "blimp/client/public/contents/blimp_contents_view.h"
16 #include "blimp/client/support/compositor/compositor_dependencies_impl.h"
17 #include "jni/BlimpContentsDisplay_jni.h"
18 #include "ui/android/view_android.h"
19 #include "ui/events/android/motion_event_android.h"
20 #include "ui/gfx/geometry/size.h"
21
22 namespace blimp {
23 namespace client {
24 namespace app {
25
26 static jlong Init(
27 JNIEnv* env,
28 const base::android::JavaParamRef<jobject>& jobj,
29 const base::android::JavaParamRef<jobject>& jblimp_environment,
30 const base::android::JavaParamRef<jobject>& jblimp_contents,
31 jint real_width,
32 jint real_height,
33 jint width,
34 jint height) {
35 BlimpEnvironment* blimp_environment =
36 BlimpEnvironment::FromJavaObject(env, jblimp_environment);
37 BlimpContents* blimp_contents =
38 BlimpContents::FromJavaObject(env, jblimp_contents);
39 return reinterpret_cast<intptr_t>(new BlimpContentsDisplay(
40 env, jobj, gfx::Size(real_width, real_height), gfx::Size(width, height),
41 blimp_environment, blimp_contents));
42 }
43
44 // static
45 bool BlimpContentsDisplay::RegisterJni(JNIEnv* env) {
46 return RegisterNativesImpl(env);
47 }
48
49 BlimpContentsDisplay::BlimpContentsDisplay(
50 JNIEnv* env,
51 const base::android::JavaParamRef<jobject>& jobj,
52 const gfx::Size& real_size,
53 const gfx::Size& size,
54 BlimpEnvironment* blimp_environment,
55 BlimpContents* blimp_contents)
56 : blimp_contents_(blimp_contents),
57 current_surface_format_(0),
58 window_(gfx::kNullAcceleratedWidget),
59 weak_ptr_factory_(this) {
60 DCHECK(blimp_contents_);
61
62 compositor_dependencies_ = blimp_environment->CreateCompositorDepencencies();
63
64 compositor_ =
65 base::MakeUnique<BrowserCompositor>(compositor_dependencies_.get());
66 compositor_->set_did_complete_swap_buffers_callback(
67 base::Bind(&BlimpContentsDisplay::OnSwapBuffersCompleted,
68 weak_ptr_factory_.GetWeakPtr()));
69
70 compositor_->SetContentLayer(
71 blimp_contents_->GetView()->GetNativeView()->GetLayer());
72
73 java_obj_.Reset(env, jobj);
74 }
75
76 BlimpContentsDisplay::~BlimpContentsDisplay() {
77 SetSurface(nullptr);
78
79 // Destroy the BrowserCompositor before the BlimpCompositorDependencies.
80 compositor_.reset();
81 compositor_dependencies_.reset();
82 }
83
84 void BlimpContentsDisplay::Destroy(
85 JNIEnv* env,
86 const base::android::JavaParamRef<jobject>& jobj) {
87 delete this;
88 }
89
90 void BlimpContentsDisplay::OnContentAreaSizeChanged(
91 JNIEnv* env,
92 const base::android::JavaParamRef<jobject>& jobj,
93 jint width,
94 jint height,
95 jfloat dpToPx) {
96 compositor_->SetSize(gfx::Size(width, height));
97 }
98
99 void BlimpContentsDisplay::OnSurfaceChanged(
100 JNIEnv* env,
101 const base::android::JavaParamRef<jobject>& jobj,
102 jint format,
103 jint width,
104 jint height,
105 const base::android::JavaParamRef<jobject>& jsurface) {
106 if (current_surface_format_ == format) {
107 return;
108 }
109
110 current_surface_format_ = format;
111 SetSurface(nullptr);
112
113 if (jsurface) {
114 SetSurface(jsurface);
115 }
116 }
117
118 void BlimpContentsDisplay::OnSurfaceCreated(
119 JNIEnv* env,
120 const base::android::JavaParamRef<jobject>& jobj) {
121 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */;
122 }
123
124 void BlimpContentsDisplay::OnSurfaceDestroyed(
125 JNIEnv* env,
126 const base::android::JavaParamRef<jobject>& jobj) {
127 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */;
128 SetSurface(nullptr);
129 }
130
131 void BlimpContentsDisplay::SetSurface(jobject surface) {
132 JNIEnv* env = base::android::AttachCurrentThread();
133 // Release all references to the old surface.
134 if (window_ != gfx::kNullAcceleratedWidget) {
135 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
136 blimp_contents_->Hide();
137 ANativeWindow_release(window_);
138 window_ = gfx::kNullAcceleratedWidget;
139 }
140
141 if (surface) {
142 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
143 window_ = ANativeWindow_fromSurface(env, surface);
144 compositor_->SetAcceleratedWidget(window_);
145 blimp_contents_->Show();
146 }
147 }
148
149 void BlimpContentsDisplay::OnSwapBuffersCompleted() {
150 JNIEnv* env = base::android::AttachCurrentThread();
151 Java_BlimpContentsDisplay_onSwapBuffersCompleted(env, java_obj_);
152 }
153
154 } // namespace app
155 } // namespace client
156 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/client/app/android/blimp_contents_display.h ('k') | blimp/client/app/android/blimp_environment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698