Home | History | Annotate | Download | only in system
      1 /*
      2  * Copyright (C) 2017 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 package com.android.systemui.shared.system;
     17 
     18 import android.graphics.Bitmap;
     19 import android.graphics.GraphicBuffer;
     20 import android.os.Parcel;
     21 import android.os.Parcelable;
     22 
     23 /**
     24  * Wraps the internal graphic buffer.
     25  */
     26 public class GraphicBufferCompat implements Parcelable {
     27 
     28     private GraphicBuffer mBuffer;
     29 
     30     public GraphicBufferCompat(GraphicBuffer buffer) {
     31         mBuffer = buffer;
     32     }
     33 
     34     public GraphicBufferCompat(Parcel in) {
     35         mBuffer = GraphicBuffer.CREATOR.createFromParcel(in);
     36     }
     37 
     38     public Bitmap toBitmap() {
     39         return mBuffer != null
     40                 ? Bitmap.createHardwareBitmap(mBuffer)
     41                 : null;
     42     }
     43 
     44     @Override
     45     public void writeToParcel(Parcel dest, int flags) {
     46         mBuffer.writeToParcel(dest, flags);
     47     }
     48 
     49     public static final Parcelable.Creator<GraphicBufferCompat> CREATOR
     50             = new Parcelable.Creator<GraphicBufferCompat>() {
     51         public GraphicBufferCompat createFromParcel(Parcel in) {
     52             return new GraphicBufferCompat(in);
     53         }
     54 
     55         public GraphicBufferCompat[] newArray(int size) {
     56             return new GraphicBufferCompat[size];
     57         }
     58     };
     59 
     60     @Override
     61     public int describeContents() {
     62         return 0;
     63     }
     64 }
     65