Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / blimp / client / android / blimp_view.cc
blobde27258a9817a49cfbc6079cfd254909538a0c66
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.
5 #include "blimp/client/android/blimp_view.h"
7 #include "blimp/client/compositor/blimp_compositor_android.h"
8 #include "jni/BlimpView_jni.h"
9 #include "ui/gfx/geometry/size.h"
11 namespace blimp {
13 // static
14 static jlong Init(JNIEnv* env,
15 const JavaParamRef<jobject>& jobj,
16 jint real_width,
17 jint real_height,
18 jint width,
19 jint height,
20 jfloat dp_to_px) {
21 return reinterpret_cast<intptr_t>(
22 new BlimpView(env, jobj, gfx::Size(real_width, real_height),
23 gfx::Size(width, height), dp_to_px));
26 // static
27 bool BlimpView::RegisterJni(JNIEnv* env) {
28 return RegisterNativesImpl(env);
31 BlimpView::BlimpView(JNIEnv* env,
32 const JavaParamRef<jobject>& jobj,
33 const gfx::Size& real_size,
34 const gfx::Size& size,
35 float dp_to_px)
36 : compositor_(BlimpCompositorAndroid::Create(real_size, size, dp_to_px)),
37 current_surface_format_(0) {
38 java_obj_.Reset(env, jobj);
41 BlimpView::~BlimpView() {}
43 void BlimpView::Destroy(JNIEnv* env, jobject jobj) {
44 delete this;
47 void BlimpView::SetNeedsComposite(JNIEnv* env, jobject jobj) {}
49 void BlimpView::OnSurfaceChanged(JNIEnv* env,
50 jobject jobj,
51 jint format,
52 jint width,
53 jint height,
54 jobject jsurface) {
55 if (current_surface_format_ != format) {
56 current_surface_format_ = format;
57 compositor_->SetSurface(env, jsurface);
60 compositor_->SetSize(gfx::Size(width, height));
63 void BlimpView::OnSurfaceCreated(JNIEnv* env, jobject jobj) {
64 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */;
67 void BlimpView::OnSurfaceDestroyed(JNIEnv* env, jobject jobj) {
68 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */;
69 compositor_->SetSurface(env, 0 /** nullptr jobject */);
72 void BlimpView::SetVisibility(JNIEnv* env, jobject jobj, jboolean visible) {
73 compositor_->SetVisible(visible);
76 } // namespace blimp