Home | History | Annotate | Download | only in stagefright
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef NATIVE_WINDOW_WRAPPER_H_
     18 
     19 #define NATIVE_WINDOW_WRAPPER_H_
     20 
     21 #include <surfaceflinger/Surface.h>
     22 #include <gui/SurfaceTextureClient.h>
     23 
     24 namespace android {
     25 
     26 // Both Surface and SurfaceTextureClient are RefBase that implement the
     27 // ANativeWindow interface, but at different addresses. ANativeWindow is not
     28 // a RefBase but acts like one for use with sp<>.  This wrapper converts a
     29 // Surface or SurfaceTextureClient into a single reference-counted object
     30 // that holds an sp reference to the underlying Surface or SurfaceTextureClient,
     31 // It provides a method to get the ANativeWindow.
     32 
     33 struct NativeWindowWrapper : RefBase {
     34     NativeWindowWrapper(
     35             const sp<Surface> &surface) :
     36         mSurface(surface) { }
     37 
     38     NativeWindowWrapper(
     39             const sp<SurfaceTextureClient> &surfaceTextureClient) :
     40         mSurfaceTextureClient(surfaceTextureClient) { }
     41 
     42     sp<ANativeWindow> getNativeWindow() const {
     43         if (mSurface != NULL) {
     44             return mSurface;
     45         } else {
     46             return mSurfaceTextureClient;
     47         }
     48     }
     49 
     50     // If needed later we can provide a method to ask what kind of native window
     51 
     52 private:
     53     // At most one of mSurface and mSurfaceTextureClient will be non-NULL
     54     const sp<Surface> mSurface;
     55     const sp<SurfaceTextureClient> mSurfaceTextureClient;
     56 
     57     DISALLOW_EVIL_CONSTRUCTORS(NativeWindowWrapper);
     58 };
     59 
     60 }  // namespace android
     61 
     62 #endif  // NATIVE_WINDOW_WRAPPER_H_
     63