Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: cc/image_layer.cc

Issue 11304020: cc: Nine patch layer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add unit tests and address code review Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 6
7 #include "cc/image_layer.h" 7 #include "cc/image_layer.h"
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "cc/image_layer_updater.h"
10 #include "cc/layer_updater.h" 11 #include "cc/layer_updater.h"
11 #include "cc/layer_tree_host.h" 12 #include "cc/layer_tree_host.h"
12 #include "cc/resource_update_queue.h" 13 #include "cc/resource_update_queue.h"
13 14
14 namespace cc { 15 namespace cc {
15 16
16 class ImageLayerUpdater : public LayerUpdater {
17 public:
18 class Resource : public LayerUpdater::Resource {
19 public:
20 Resource(ImageLayerUpdater* updater, scoped_ptr<PrioritizedTexture> text ure)
21 : LayerUpdater::Resource(texture.Pass())
22 , m_updater(updater)
23 {
24 }
25
26 virtual void update(ResourceUpdateQueue& queue, const gfx::Rect& sourceR ect, const gfx::Vector2d& destOffset, bool partialUpdate, RenderingStats&) OVERR IDE
27 {
28 updater()->updateTexture(queue, texture(), sourceRect, destOffset, p artialUpdate);
29 }
30
31 private:
32 ImageLayerUpdater* updater() { return m_updater; }
33
34 ImageLayerUpdater* m_updater;
35 };
36
37 static scoped_refptr<ImageLayerUpdater> create()
38 {
39 return make_scoped_refptr(new ImageLayerUpdater());
40 }
41
42 virtual scoped_ptr<LayerUpdater::Resource> createResource(
43 PrioritizedTextureManager* manager) OVERRIDE
44 {
45 return scoped_ptr<LayerUpdater::Resource>(new Resource(this, Prioritized Texture::create(manager)));
46 }
47
48 void updateTexture(ResourceUpdateQueue& queue, PrioritizedTexture* texture, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset, bool partialUpdate )
49 {
50 // Source rect should never go outside the image pixels, even if this
51 // is requested because the texture extends outside the image.
52 gfx::Rect clippedSourceRect = sourceRect;
53 gfx::Rect imageRect = gfx::Rect(0, 0, m_bitmap.width(), m_bitmap.height( ));
54 clippedSourceRect.Intersect(imageRect);
55
56 gfx::Vector2d clippedDestOffset = destOffset + (clippedSourceRect.origin () - sourceRect.origin());
57
58 ResourceUpdate upload = ResourceUpdate::Create(texture,
59 &m_bitmap,
60 imageRect,
61 clippedSourceRect,
62 clippedDestOffset);
63 if (partialUpdate)
64 queue.appendPartialUpload(upload);
65 else
66 queue.appendFullUpload(upload);
67 }
68
69 void setBitmap(const SkBitmap& bitmap)
70 {
71 m_bitmap = bitmap;
72 }
73
74 private:
75 ImageLayerUpdater() { }
76 virtual ~ImageLayerUpdater() { }
77
78 SkBitmap m_bitmap;
79 };
80
81 scoped_refptr<ImageLayer> ImageLayer::create() 17 scoped_refptr<ImageLayer> ImageLayer::create()
82 { 18 {
83 return make_scoped_refptr(new ImageLayer()); 19 return make_scoped_refptr(new ImageLayer());
84 } 20 }
85 21
86 ImageLayer::ImageLayer() 22 ImageLayer::ImageLayer()
87 : TiledLayer() 23 : TiledLayer()
88 { 24 {
89 } 25 }
90 26
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 94 }
159 95
160 float ImageLayer::contentsScaleY() const 96 float ImageLayer::contentsScaleY() const
161 { 97 {
162 if (bounds().IsEmpty() || contentBounds().IsEmpty()) 98 if (bounds().IsEmpty() || contentBounds().IsEmpty())
163 return 1; 99 return 1;
164 return static_cast<float>(m_bitmap.height()) / bounds().height(); 100 return static_cast<float>(m_bitmap.height()) / bounds().height();
165 } 101 }
166 102
167 } 103 }
OLDNEW
« no previous file with comments | « cc/cc_tests.gyp ('k') | cc/image_layer_updater.h » ('j') | cc/nine_patch_layer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698