Home | History | Annotate | Download | only in layers
      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_NINE_PATCH_LAYER_H_
      6 #define CC_LAYERS_NINE_PATCH_LAYER_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "cc/base/cc_export.h"
     10 #include "cc/layers/layer.h"
     11 #include "cc/resources/image_layer_updater.h"
     12 #include "third_party/skia/include/core/SkBitmap.h"
     13 #include "ui/gfx/rect.h"
     14 
     15 namespace cc {
     16 
     17 class ResourceUpdateQueue;
     18 
     19 class CC_EXPORT NinePatchLayer : public Layer {
     20  public:
     21   static scoped_refptr<NinePatchLayer> Create();
     22 
     23   virtual bool DrawsContent() const OVERRIDE;
     24   virtual void SetTexturePriorities(const PriorityCalculator& priority_calc)
     25       OVERRIDE;
     26   virtual bool Update(ResourceUpdateQueue* queue,
     27                       const OcclusionTracker* occlusion) OVERRIDE;
     28   virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
     29 
     30   // aperture is in the pixel space of the bitmap resource and refers to
     31   // the center patch of the ninepatch (which is unused in this
     32   // implementation). We split off eight rects surrounding it and stick them
     33   // on the edges of the layer. The corners are unscaled, the top and bottom
     34   // rects are x-stretched to fit, and the left and right rects are
     35   // y-stretched to fit.
     36   void SetBitmap(const SkBitmap& bitmap, gfx::Rect aperture);
     37 
     38  private:
     39   NinePatchLayer();
     40   virtual ~NinePatchLayer();
     41   virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
     42       OVERRIDE;
     43 
     44   void CreateUpdaterIfNeeded();
     45   void CreateResource();
     46 
     47   scoped_refptr<ImageLayerUpdater> updater_;
     48   scoped_ptr<LayerUpdater::Resource> resource_;
     49 
     50   SkBitmap bitmap_;
     51   bool bitmap_dirty_;
     52 
     53   // The transparent center region that shows the parent layer's contents in
     54   // image space.
     55   gfx::Rect image_aperture_;
     56 
     57   DISALLOW_COPY_AND_ASSIGN(NinePatchLayer);
     58 };
     59 
     60 }  // namespace cc
     61 
     62 #endif  // CC_LAYERS_NINE_PATCH_LAYER_H_
     63