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

Side by Side Diff: cc/nine_patch_layer.cc

Issue 12603013: Part 10 of cc/ directory shuffles: layers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « cc/nine_patch_layer.h ('k') | cc/nine_patch_layer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #include "cc/nine_patch_layer.h"
6
7 #include "cc/nine_patch_layer_impl.h"
8 #include "cc/resources/prioritized_resource.h"
9 #include "cc/resources/resource_update.h"
10 #include "cc/resources/resource_update_queue.h"
11 #include "cc/trees/layer_tree_host.h"
12
13 namespace cc {
14
15 scoped_refptr<NinePatchLayer> NinePatchLayer::Create() {
16 return make_scoped_refptr(new NinePatchLayer());
17 }
18
19 NinePatchLayer::NinePatchLayer()
20 : bitmap_dirty_(false) {}
21
22 NinePatchLayer::~NinePatchLayer() {}
23
24 scoped_ptr<LayerImpl> NinePatchLayer::CreateLayerImpl(
25 LayerTreeImpl* tree_impl) {
26 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
27 }
28
29 void NinePatchLayer::SetTexturePriorities(
30 const PriorityCalculator& priority_calc) {
31 if (resource_ && !resource_->texture()->resourceManager()) {
32 // Release the resource here, as it is no longer tied to a resource manager.
33 resource_.reset();
34 if (!bitmap_.isNull())
35 CreateResource();
36 } else if (needs_display_ && bitmap_dirty_ && DrawsContent()) {
37 CreateResource();
38 }
39
40 if (resource_) {
41 resource_->texture()->setRequestPriority(
42 PriorityCalculator::UIPriority(true));
43 // FIXME: Need to support swizzle in the shader for
44 // !PlatformColor::sameComponentOrder(texture_format)
45 GLenum texture_format =
46 layer_tree_host()->GetRendererCapabilities().best_texture_format;
47 resource_->texture()->setDimensions(
48 gfx::Size(bitmap_.width(), bitmap_.height()), texture_format);
49 }
50 }
51
52 void NinePatchLayer::SetBitmap(const SkBitmap& bitmap, gfx::Rect aperture) {
53 bitmap_ = bitmap;
54 image_aperture_ = aperture;
55 bitmap_dirty_ = true;
56 SetNeedsDisplay();
57 }
58
59 void NinePatchLayer::Update(ResourceUpdateQueue* queue,
60 const OcclusionTracker* occlusion,
61 RenderingStats* stats) {
62 CreateUpdaterIfNeeded();
63
64 if (resource_ && (bitmap_dirty_ || resource_->texture()->resourceId() == 0)) {
65 gfx::Rect contentRect(gfx::Point(),
66 gfx::Size(bitmap_.width(), bitmap_.height()));
67 ResourceUpdate upload = ResourceUpdate::Create(resource_->texture(),
68 &bitmap_,
69 contentRect,
70 contentRect,
71 gfx::Vector2d());
72 queue->appendFullUpload(upload);
73 bitmap_dirty_ = false;
74 }
75 }
76
77 void NinePatchLayer::CreateUpdaterIfNeeded() {
78 if (updater_)
79 return;
80
81 updater_ = ImageLayerUpdater::Create();
82 }
83
84 void NinePatchLayer::CreateResource() {
85 DCHECK(!bitmap_.isNull());
86 CreateUpdaterIfNeeded();
87 updater_->set_bitmap(bitmap_);
88 needs_display_ = false;
89
90 if (!resource_) {
91 resource_ = updater_->CreateResource(
92 layer_tree_host()->contents_texture_manager());
93 }
94 }
95
96 bool NinePatchLayer::DrawsContent() const {
97 bool draws = !bitmap_.isNull() &&
98 Layer::DrawsContent() &&
99 bitmap_.width() &&
100 bitmap_.height();
101 return draws;
102 }
103
104 void NinePatchLayer::PushPropertiesTo(LayerImpl* layer) {
105 Layer::PushPropertiesTo(layer);
106 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
107
108 if (resource_) {
109 DCHECK(!bitmap_.isNull());
110 layer_impl->SetResourceId(resource_->texture()->resourceId());
111 layer_impl->SetLayout(
112 gfx::Size(bitmap_.width(), bitmap_.height()), image_aperture_);
113 }
114 }
115
116 }
OLDNEW
« no previous file with comments | « cc/nine_patch_layer.h ('k') | cc/nine_patch_layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698