OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/services/native_viewport/native_viewport_android.h" | 5 #include "mojo/services/native_viewport/native_viewport_android.h" |
6 | 6 |
7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
8 #include "gpu/command_buffer/client/gl_in_process_context.h" | |
9 #include "gpu/command_buffer/client/gles2_implementation.h" | |
10 #include "mojo/services/native_viewport/android/mojo_viewport.h" | 8 #include "mojo/services/native_viewport/android/mojo_viewport.h" |
11 #include "mojo/shell/context.h" | 9 #include "mojo/shell/context.h" |
12 | 10 |
13 namespace mojo { | 11 namespace mojo { |
14 namespace services { | 12 namespace services { |
15 | 13 |
16 NativeViewportAndroid::NativeViewportAndroid(NativeViewportDelegate* delegate) | 14 NativeViewportAndroid::NativeViewportAndroid(NativeViewportDelegate* delegate) |
17 : delegate_(delegate), | 15 : NativeViewport(delegate), |
18 window_(NULL), | |
19 weak_factory_(this) { | 16 weak_factory_(this) { |
20 } | 17 } |
21 | 18 |
22 NativeViewportAndroid::~NativeViewportAndroid() { | 19 NativeViewportAndroid::~NativeViewportAndroid() { |
23 if (window_) | 20 if (widget_) |
24 ReleaseWindow(); | 21 ReleaseWindow(); |
25 } | 22 } |
26 | 23 |
27 void NativeViewportAndroid::OnNativeWindowCreated(ANativeWindow* window) { | 24 void NativeViewportAndroid::OnNativeWindowCreated(ANativeWindow* window) { |
28 DCHECK(!window_); | 25 DCHECK(!widget_); |
29 window_ = window; | 26 widget_ = window; |
30 | 27 OnAcceleratedWidgetAvailable(); |
31 gpu::GLInProcessContextAttribs attribs; | |
32 gl_context_.reset(gpu::GLInProcessContext::CreateContext( | |
33 false, window_, size_, false, attribs, gfx::PreferDiscreteGpu)); | |
34 gl_context_->SetContextLostCallback(base::Bind( | |
35 &NativeViewportAndroid::OnGLContextLost, base::Unretained(this))); | |
36 | |
37 delegate_->OnGLContextAvailable(gl_context_->GetImplementation()); | |
38 } | |
39 | |
40 void NativeViewportAndroid::OnGLContextLost() { | |
41 gl_context_.reset(); | |
42 delegate_->OnGLContextLost(); | |
43 } | 28 } |
44 | 29 |
45 void NativeViewportAndroid::OnNativeWindowDestroyed() { | 30 void NativeViewportAndroid::OnNativeWindowDestroyed() { |
46 DCHECK(window_); | 31 DCHECK(widget_); |
47 ReleaseWindow(); | 32 ReleaseWindow(); |
48 } | 33 } |
49 | 34 |
50 void NativeViewportAndroid::OnResized(const gfx::Size& size) { | 35 void NativeViewportAndroid::OnResized(const gfx::Size& size) { |
51 size_ = size; | 36 bounds_ = gfx::Rect(size); |
52 delegate_->OnResized(size); | 37 delegate_->OnResized(size); |
53 } | 38 } |
54 | 39 |
55 void NativeViewportAndroid::ReleaseWindow() { | 40 void NativeViewportAndroid::ReleaseWindow() { |
56 gl_context_.reset(); | 41 gl_context_.reset(); |
57 ANativeWindow_release(window_); | 42 ANativeWindow_release(widget_); |
58 window_ = NULL; | 43 widget_ = NULL; |
59 } | 44 } |
60 | 45 |
61 void NativeViewportAndroid::Close() { | 46 void NativeViewportAndroid::Close() { |
62 // TODO(beng): close activity containing MojoView? | 47 // TODO(beng): close activity containing MojoView? |
63 | 48 |
64 // TODO(beng): perform this in response to view destruction. | 49 // TODO(beng): perform this in response to view destruction. |
65 delegate_->OnDestroyed(); | 50 delegate_->OnDestroyed(); |
66 } | 51 } |
67 | 52 |
68 // static | 53 // static |
(...skipping 10 matching lines...) Expand all Loading... |
79 context->task_runners()->java_runner()->PostTask(FROM_HERE, | 64 context->task_runners()->java_runner()->PostTask(FROM_HERE, |
80 base::Bind(MojoViewport::CreateForActivity, | 65 base::Bind(MojoViewport::CreateForActivity, |
81 context->activity(), | 66 context->activity(), |
82 init)); | 67 init)); |
83 | 68 |
84 return scoped_ptr<NativeViewport>(native_viewport.Pass()); | 69 return scoped_ptr<NativeViewport>(native_viewport.Pass()); |
85 } | 70 } |
86 | 71 |
87 } // namespace services | 72 } // namespace services |
88 } // namespace mojo | 73 } // namespace mojo |
OLD | NEW |