Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright 2010, 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 TileTexture_h
     27 #define TileTexture_h
     28 
     29 #include "Color.h"
     30 #include "FloatRect.h"
     31 #include "SkBitmap.h"
     32 #include "SkRect.h"
     33 #include "SkSize.h"
     34 #include "TextureInfo.h"
     35 
     36 #include <GLES2/gl2.h>
     37 
     38 class SkCanvas;
     39 
     40 namespace WebCore {
     41 
     42 class TextureOwner;
     43 class Tile;
     44 class TransformationMatrix;
     45 
     46 class TileTexture {
     47 public:
     48     // This object is to be constructed on the consumer's thread and must have
     49     // a width and height greater than 0.
     50     TileTexture(uint32_t w, uint32_t h);
     51     virtual ~TileTexture();
     52 
     53     // allows consumer thread to assign ownership of the texture to the tile. It
     54     // returns false if ownership cannot be transferred because the tile is busy
     55     bool acquire(TextureOwner* owner);
     56     bool release(TextureOwner* owner);
     57 
     58     // set the texture owner if not busy. Return false if busy, true otherwise.
     59     bool setOwner(TextureOwner* owner);
     60 
     61     // private member accessor functions
     62     TextureOwner* owner() { return m_owner; } // only used by the consumer thread
     63 
     64     const SkSize& getSize() const { return m_size; }
     65 
     66     // OpenGL ID of backing texture, 0 when not allocated
     67     GLuint m_ownTextureId;
     68     // these are used for dynamically (de)allocating backing graphics memory
     69     void requireGLTexture();
     70     void discardGLTexture();
     71 
     72     void transferComplete();
     73 
     74     TextureInfo* getTextureInfo() { return &m_ownTextureInfo; }
     75 
     76     // Make sure the following pureColor getter/setter are only read/written
     77     // in UI thread. Therefore no need for a lock.
     78     void setPure(bool pure) { m_isPureColor = pure; }
     79     bool isPureColor() {return m_isPureColor; }
     80     void setPureColor(const Color& color) { m_pureColor = color; setPure(true); }
     81     Color pureColor() { return m_pureColor; }
     82 
     83     void drawGL(bool isLayer, const SkRect& rect, float opacity,
     84                 const TransformationMatrix* transform, bool forceBlending, bool usePointSampling,
     85                 const FloatRect& fillPortion);
     86 private:
     87     TextureInfo m_ownTextureInfo;
     88     SkSize m_size;
     89 
     90     // Tile owning the texture, only modified by UI thread
     91     TextureOwner* m_owner;
     92 
     93     // When the whole tile is single color, skip the transfer queue and draw
     94     // it directly through shader.
     95     bool m_isPureColor;
     96     Color m_pureColor;
     97 };
     98 
     99 } // namespace WebCore
    100 
    101 #endif // TileTexture_h
    102