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

Side by Side Diff: blimp/client/android/blimp_view.cc

Issue 1450423002: Add glue between the client and engine for Blimp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blimp_ipc2
Patch Set: Address comments! Created 5 years, 1 month 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
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/android/blimp_view.h" 5 #include "blimp/client/android/blimp_view.h"
6 6
7 #include <android/native_window_jni.h>
8
7 #include "blimp/client/compositor/blimp_compositor_android.h" 9 #include "blimp/client/compositor/blimp_compositor_android.h"
8 #include "jni/BlimpView_jni.h" 10 #include "jni/BlimpView_jni.h"
9 #include "ui/gfx/geometry/size.h" 11 #include "ui/gfx/geometry/size.h"
10 12
11 namespace blimp { 13 namespace blimp {
12 14
13 // static 15 // static
14 static jlong Init(JNIEnv* env, 16 static jlong Init(JNIEnv* env,
15 const JavaParamRef<jobject>& jobj, 17 const JavaParamRef<jobject>& jobj,
16 jint real_width, 18 jint real_width,
(...skipping 10 matching lines...) Expand all
27 bool BlimpView::RegisterJni(JNIEnv* env) { 29 bool BlimpView::RegisterJni(JNIEnv* env) {
28 return RegisterNativesImpl(env); 30 return RegisterNativesImpl(env);
29 } 31 }
30 32
31 BlimpView::BlimpView(JNIEnv* env, 33 BlimpView::BlimpView(JNIEnv* env,
32 const JavaParamRef<jobject>& jobj, 34 const JavaParamRef<jobject>& jobj,
33 const gfx::Size& real_size, 35 const gfx::Size& real_size,
34 const gfx::Size& size, 36 const gfx::Size& size,
35 float dp_to_px) 37 float dp_to_px)
36 : compositor_(BlimpCompositorAndroid::Create(real_size, size, dp_to_px)), 38 : compositor_(BlimpCompositorAndroid::Create(real_size, size, dp_to_px)),
37 current_surface_format_(0) { 39 current_surface_format_(0),
40 window_(gfx::kNullAcceleratedWidget) {
38 java_obj_.Reset(env, jobj); 41 java_obj_.Reset(env, jobj);
39 } 42 }
40 43
41 BlimpView::~BlimpView() {} 44 BlimpView::~BlimpView() {
45 ReleaseAcceleratedWidget();
46 }
42 47
43 void BlimpView::Destroy(JNIEnv* env, jobject jobj) { 48 void BlimpView::Destroy(JNIEnv* env, jobject jobj) {
44 delete this; 49 delete this;
45 } 50 }
46 51
47 void BlimpView::SetNeedsComposite(JNIEnv* env, jobject jobj) {} 52 void BlimpView::SetNeedsComposite(JNIEnv* env, jobject jobj) {}
48 53
49 void BlimpView::OnSurfaceChanged(JNIEnv* env, 54 void BlimpView::OnSurfaceChanged(JNIEnv* env,
50 jobject jobj, 55 jobject jobj,
51 jint format, 56 jint format,
52 jint width, 57 jint width,
53 jint height, 58 jint height,
54 jobject jsurface) { 59 jobject jsurface) {
55 if (current_surface_format_ != format) { 60 if (current_surface_format_ != format) {
56 current_surface_format_ = format; 61 current_surface_format_ = format;
57 compositor_->SetSurface(env, jsurface); 62 ReleaseAcceleratedWidget();
63
64 if (jsurface) {
65 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
66 window_ = ANativeWindow_fromSurface(env, jsurface);
67 compositor_->SetAcceleratedWidget(window_);
68 compositor_->SetVisible(true);
69 }
58 } 70 }
59 71
60 compositor_->SetSize(gfx::Size(width, height)); 72 compositor_->SetSize(gfx::Size(width, height));
61 } 73 }
62 74
63 void BlimpView::OnSurfaceCreated(JNIEnv* env, jobject jobj) { 75 void BlimpView::OnSurfaceCreated(JNIEnv* env, jobject jobj) {
64 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; 76 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */;
65 } 77 }
66 78
67 void BlimpView::OnSurfaceDestroyed(JNIEnv* env, jobject jobj) { 79 void BlimpView::OnSurfaceDestroyed(JNIEnv* env, jobject jobj) {
68 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; 80 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */;
69 compositor_->SetSurface(env, 0 /** nullptr jobject */); 81 ReleaseAcceleratedWidget();
70 } 82 }
71 83
72 void BlimpView::SetVisibility(JNIEnv* env, jobject jobj, jboolean visible) { 84 void BlimpView::SetVisibility(JNIEnv* env, jobject jobj, jboolean visible) {
73 compositor_->SetVisible(visible); 85 compositor_->SetVisible(visible);
74 } 86 }
75 87
88 void BlimpView::ReleaseAcceleratedWidget() {
89 if (window_ != gfx::kNullAcceleratedWidget) {
nyquist 2015/11/24 08:55:43 Optional nit: == and early return?
David Trainor- moved to gerrit 2015/11/25 17:56:41 Done.
90 compositor_->ReleaseAcceleratedWidget();
91 ANativeWindow_release(window_);
92 window_ = gfx::kNullAcceleratedWidget;
93 }
94 }
95
76 } // namespace blimp 96 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698