| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/android/content_view_render_view.h" | 5 #include "content/browser/android/content_view_render_view.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 // static | 29 // static |
| 30 bool ContentViewRenderView::RegisterContentViewRenderView(JNIEnv* env) { | 30 bool ContentViewRenderView::RegisterContentViewRenderView(JNIEnv* env) { |
| 31 return RegisterNativesImpl(env); | 31 return RegisterNativesImpl(env); |
| 32 } | 32 } |
| 33 | 33 |
| 34 ContentViewRenderView::ContentViewRenderView(JNIEnv* env, | 34 ContentViewRenderView::ContentViewRenderView(JNIEnv* env, |
| 35 jobject obj, | 35 jobject obj, |
| 36 gfx::NativeWindow root_window) | 36 gfx::NativeWindow root_window) |
| 37 : buffers_swapped_during_composite_(false), | 37 : root_window_(root_window), current_surface_format_(0) { |
| 38 root_window_(root_window), | |
| 39 current_surface_format_(0) { | |
| 40 java_obj_.Reset(env, obj); | 38 java_obj_.Reset(env, obj); |
| 41 } | 39 } |
| 42 | 40 |
| 43 ContentViewRenderView::~ContentViewRenderView() { | 41 ContentViewRenderView::~ContentViewRenderView() { |
| 44 } | 42 } |
| 45 | 43 |
| 46 // static | 44 // static |
| 47 static jlong Init(JNIEnv* env, jobject obj, jlong native_root_window) { | 45 static jlong Init(JNIEnv* env, jobject obj, jlong native_root_window) { |
| 48 gfx::NativeWindow root_window = | 46 gfx::NativeWindow root_window = |
| 49 reinterpret_cast<gfx::NativeWindow>(native_root_window); | 47 reinterpret_cast<gfx::NativeWindow>(native_root_window); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 80 | 78 |
| 81 void ContentViewRenderView::SurfaceChanged(JNIEnv* env, jobject obj, | 79 void ContentViewRenderView::SurfaceChanged(JNIEnv* env, jobject obj, |
| 82 jint format, jint width, jint height, jobject surface) { | 80 jint format, jint width, jint height, jobject surface) { |
| 83 if (current_surface_format_ != format) { | 81 if (current_surface_format_ != format) { |
| 84 current_surface_format_ = format; | 82 current_surface_format_ = format; |
| 85 compositor_->SetSurface(surface); | 83 compositor_->SetSurface(surface); |
| 86 } | 84 } |
| 87 compositor_->SetWindowBounds(gfx::Size(width, height)); | 85 compositor_->SetWindowBounds(gfx::Size(width, height)); |
| 88 } | 86 } |
| 89 | 87 |
| 90 jboolean ContentViewRenderView::Composite(JNIEnv* env, jobject obj) { | |
| 91 if (!compositor_) | |
| 92 return false; | |
| 93 | |
| 94 buffers_swapped_during_composite_ = false; | |
| 95 compositor_->Composite(); | |
| 96 return buffers_swapped_during_composite_; | |
| 97 } | |
| 98 | |
| 99 jboolean ContentViewRenderView::CompositeToBitmap(JNIEnv* env, jobject obj, | 88 jboolean ContentViewRenderView::CompositeToBitmap(JNIEnv* env, jobject obj, |
| 100 jobject java_bitmap) { | 89 jobject java_bitmap) { |
| 101 gfx::JavaBitmap bitmap(java_bitmap); | 90 gfx::JavaBitmap bitmap(java_bitmap); |
| 102 if (!compositor_ || bitmap.format() != ANDROID_BITMAP_FORMAT_RGBA_8888) | 91 if (!compositor_ || bitmap.format() != ANDROID_BITMAP_FORMAT_RGBA_8888) |
| 103 return false; | 92 return false; |
| 104 return compositor_->CompositeAndReadback(bitmap.pixels(), | 93 return compositor_->CompositeAndReadback(bitmap.pixels(), |
| 105 gfx::Rect(bitmap.size())); | 94 gfx::Rect(bitmap.size())); |
| 106 } | 95 } |
| 107 | 96 |
| 108 void ContentViewRenderView::SetOverlayVideoMode( | 97 void ContentViewRenderView::SetOverlayVideoMode( |
| 109 JNIEnv* env, jobject obj, bool enabled) { | 98 JNIEnv* env, jobject obj, bool enabled) { |
| 110 compositor_->SetHasTransparentBackground(enabled); | 99 compositor_->SetHasTransparentBackground(enabled); |
| 111 Java_ContentViewRenderView_requestRender(env, obj); | |
| 112 } | |
| 113 | |
| 114 void ContentViewRenderView::ScheduleComposite() { | |
| 115 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 116 Java_ContentViewRenderView_requestRender(env, java_obj_.obj()); | |
| 117 } | 100 } |
| 118 | 101 |
| 119 void ContentViewRenderView::OnSwapBuffersPosted() { | 102 void ContentViewRenderView::OnSwapBuffersPosted() { |
| 120 buffers_swapped_during_composite_ = true; | |
| 121 } | |
| 122 | |
| 123 void ContentViewRenderView::OnSwapBuffersCompleted() { | |
| 124 JNIEnv* env = base::android::AttachCurrentThread(); | 103 JNIEnv* env = base::android::AttachCurrentThread(); |
| 125 Java_ContentViewRenderView_onSwapBuffersCompleted(env, java_obj_.obj()); | 104 Java_ContentViewRenderView_onSwapBuffersPosted(env, java_obj_.obj()); |
| 126 } | 105 } |
| 127 | 106 |
| 128 void ContentViewRenderView::InitCompositor() { | 107 void ContentViewRenderView::InitCompositor() { |
| 129 if (!compositor_) | 108 if (!compositor_) |
| 130 compositor_.reset(Compositor::Create(this, root_window_)); | 109 compositor_.reset(Compositor::Create(this, root_window_)); |
| 131 } | 110 } |
| 132 | 111 |
| 133 } // namespace content | 112 } // namespace content |
| OLD | NEW |