• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 The Android Open Source Project
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *  * Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  *  * Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef VideoLayerAndroid_h
27 #define VideoLayerAndroid_h
28 
29 #if USE(ACCELERATED_COMPOSITING)
30 
31 #include "GLUtils.h"
32 #include "LayerAndroid.h"
33 #include <jni.h>
34 
35 namespace android {
36 class SurfaceTexture;
37 }
38 
39 namespace WebCore {
40 
41 // state get from UI thread to decide which image to draw.
42 // PREPARING should be the progressing image
43 // PLAYING will be the Video (Surface Texture).
44 // Otherwise will draw a static image.
45 // NOTE: These values are matching the ones in HTML5VideoView.java
46 // Please keep them in sync when changed here.
47 typedef enum {INITIALIZED, PREPARING, PREPARED, PLAYING, RESETTED, RELEASED} PlayerState;
48 
49 class VideoLayerAndroid : public LayerAndroid {
50 
51 public:
52     VideoLayerAndroid();
53     explicit VideoLayerAndroid(const VideoLayerAndroid& layer);
54 
isVideo()55     virtual bool isVideo() const { return true; }
copy()56     virtual LayerAndroid* copy() const { return new VideoLayerAndroid(*this); }
57 
58     // The following functions are called in UI thread only.
59     virtual bool drawGL(bool layerTilesDisabled);
60     void setSurfaceTexture(sp<SurfaceTexture> texture, int textureName, PlayerState playerState);
needsIsolatedSurface()61     virtual bool needsIsolatedSurface() { return true; }
62 
63 private:
64     void init();
65     void showPreparingAnimation(const SkRect& rect,
66                                 const SkRect innerRect);
67     SkRect calVideoRect(const SkRect& rect);
68     // Surface texture for showing the video is actually allocated in Java side
69     // and passed into this native code.
70     sp<android::SurfaceTexture> m_surfaceTexture;
71 
72     PlayerState m_playerState;
73 
74     static double m_rotateDegree;
75 
76     static const int ROTATESTEP = 12;
77 };
78 
79 } // namespace WebCore
80 
81 #endif // USE(ACCELERATED_COMPOSITING)
82 
83 #endif // VideoLayerAndroid_h
84