1 // Copyright 2012 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. 4 5 #ifndef CC_LAYERS_TEXTURE_LAYER_IMPL_H_ 6 #define CC_LAYERS_TEXTURE_LAYER_IMPL_H_ 7 8 #include <string> 9 10 #include "base/callback.h" 11 #include "cc/base/cc_export.h" 12 #include "cc/layers/layer_impl.h" 13 14 namespace cc { 15 class SingleReleaseCallback; 16 class ScopedResource; 17 18 class CC_EXPORT TextureLayerImpl : public LayerImpl { 19 public: 20 static scoped_ptr<TextureLayerImpl> Create(LayerTreeImpl* tree_impl, 21 int id, 22 bool uses_mailbox) { 23 return make_scoped_ptr(new TextureLayerImpl(tree_impl, id, uses_mailbox)); 24 } 25 virtual ~TextureLayerImpl(); 26 27 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* layer_tree_impl) 28 OVERRIDE; 29 virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE; 30 31 virtual bool WillDraw(DrawMode draw_mode, 32 ResourceProvider* resource_provider) OVERRIDE; 33 virtual void AppendQuads(QuadSink* quad_sink, 34 AppendQuadsData* append_quads_data) OVERRIDE; 35 virtual void DidDraw(ResourceProvider* resource_provider) OVERRIDE; 36 virtual Region VisibleContentOpaqueRegion() const OVERRIDE; 37 virtual void DidLoseOutputSurface() OVERRIDE; 38 39 unsigned texture_id() const { return texture_id_; } 40 void set_texture_id(unsigned id) { texture_id_ = id; } 41 void set_premultiplied_alpha(bool premultiplied_alpha) { 42 premultiplied_alpha_ = premultiplied_alpha; 43 } 44 void set_blend_background_color(bool blend) { 45 blend_background_color_ = blend; 46 } 47 void set_flipped(bool flipped) { flipped_ = flipped; } 48 void set_uv_top_left(gfx::PointF top_left) { uv_top_left_ = top_left; } 49 void set_uv_bottom_right(gfx::PointF bottom_right) { 50 uv_bottom_right_ = bottom_right; 51 } 52 53 // 1--2 54 // | | 55 // 0--3 56 void set_vertex_opacity(const float vertex_opacity[4]) { 57 vertex_opacity_[0] = vertex_opacity[0]; 58 vertex_opacity_[1] = vertex_opacity[1]; 59 vertex_opacity_[2] = vertex_opacity[2]; 60 vertex_opacity_[3] = vertex_opacity[3]; 61 } 62 63 void SetTextureMailbox(const TextureMailbox& mailbox, 64 scoped_ptr<SingleReleaseCallback> release_callback); 65 66 private: 67 TextureLayerImpl(LayerTreeImpl* tree_impl, int id, bool uses_mailbox); 68 69 virtual const char* LayerTypeAsString() const OVERRIDE; 70 void FreeTextureMailbox(); 71 72 unsigned texture_id_; 73 ResourceProvider::ResourceId external_texture_resource_; 74 bool premultiplied_alpha_; 75 bool blend_background_color_; 76 bool flipped_; 77 gfx::PointF uv_top_left_; 78 gfx::PointF uv_bottom_right_; 79 float vertex_opacity_[4]; 80 // This is a resource that's a GL copy of a software texture mailbox. 81 scoped_ptr<ScopedResource> texture_copy_; 82 83 TextureMailbox texture_mailbox_; 84 scoped_ptr<SingleReleaseCallback> release_callback_; 85 bool uses_mailbox_; 86 bool own_mailbox_; 87 bool valid_texture_copy_; 88 89 DISALLOW_COPY_AND_ASSIGN(TextureLayerImpl); 90 }; 91 92 } // namespace cc 93 94 #endif // CC_LAYERS_TEXTURE_LAYER_IMPL_H_ 95