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

Side by Side Diff: cc/prioritized_resource.h

Issue 12471007: Part 8 of cc/ directory shuffles: resources (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/platform_color.h ('k') | cc/prioritized_resource.cc » ('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 #ifndef CC_PRIORITIZED_RESOURCE_H_
6 #define CC_PRIORITIZED_RESOURCE_H_
7
8 #include "base/basictypes.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/priority_calculator.h"
13 #include "cc/resource.h"
14 #include "cc/resource_provider.h"
15 #include "third_party/khronos/GLES2/gl2.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/gfx/size.h"
18 #include "ui/gfx/vector2d.h"
19
20 namespace cc {
21
22 class PrioritizedResourceManager;
23 class Proxy;
24
25 class CC_EXPORT PrioritizedResource {
26 public:
27 static scoped_ptr<PrioritizedResource> create(PrioritizedResourceManager* ma nager, gfx::Size size, GLenum format)
28 {
29 return make_scoped_ptr(new PrioritizedResource(manager, size, format));
30 }
31 static scoped_ptr<PrioritizedResource> create(PrioritizedResourceManager* ma nager)
32 {
33 return make_scoped_ptr(new PrioritizedResource(manager, gfx::Size(), 0)) ;
34 }
35 ~PrioritizedResource();
36
37 // Texture properties. Changing these causes the backing texture to be lost.
38 // Setting these to the same value is a no-op.
39 void setTextureManager(PrioritizedResourceManager*);
40 PrioritizedResourceManager* resourceManager() { return m_manager; }
41 void setDimensions(gfx::Size, GLenum format);
42 GLenum format() const { return m_format; }
43 gfx::Size size() const { return m_size; }
44 size_t bytes() const { return m_bytes; }
45 bool contentsSwizzled() const { return m_contentsSwizzled; }
46
47 // Set priority for the requested texture.
48 void setRequestPriority(int priority) { m_priority = priority; }
49 int requestPriority() const { return m_priority; }
50
51 // After PrioritizedResource::prioritizeTextures() is called, this returns
52 // if the the request succeeded and this texture can be acquired for use.
53 bool canAcquireBackingTexture() const { return m_isAbovePriorityCutoff; }
54
55 // This returns whether we still have a backing texture. This can continue
56 // to be true even after canAcquireBackingTexture() becomes false. In this
57 // case the texture can be used but shouldn't be updated since it will get
58 // taken away "soon".
59 bool haveBackingTexture() const { return !!backing(); }
60
61 bool backingResourceWasEvicted() const;
62
63 // If canAcquireBackingTexture() is true acquireBackingTexture() will acquir e
64 // a backing texture for use. Call this whenever the texture is actually nee ded.
65 void acquireBackingTexture(ResourceProvider*);
66
67 // FIXME: Request late is really a hack for when we are totally out of memor y
68 // (all textures are visible) but we can still squeeze into the limit
69 // by not painting occluded textures. In this case the manager
70 // refuses all visible textures and requestLate() will enable
71 // canAcquireBackingTexture() on a call-order basis. We might want to
72 // just remove this in the future (carefully) and just make sure we d on't
73 // regress OOMs situations.
74 bool requestLate();
75
76 // Update pixels of backing resource from image. This functions will aquire the backing if needed.
77 void setPixels(ResourceProvider*, const uint8_t* image, const gfx::Rect& ima geRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset);
78
79 ResourceProvider::ResourceId resourceId() const;
80
81 // Self-managed textures are accounted for when prioritizing other textures,
82 // but they are not allocated/recycled/deleted, so this needs to be done
83 // externally. canAcquireBackingTexture() indicates if the texture would hav e
84 // been allowed given its priority.
85 void setIsSelfManaged(bool isSelfManaged) { m_isSelfManaged = isSelfManaged; }
86 bool isSelfManaged() { return m_isSelfManaged; }
87 void setToSelfManagedMemoryPlaceholder(size_t bytes);
88
89 void returnBackingTexture();
90
91 private:
92 friend class PrioritizedResourceManager;
93 friend class PrioritizedResourceTest;
94
95 class Backing : public Resource {
96 public:
97 Backing(unsigned id, ResourceProvider*, gfx::Size, GLenum format);
98 ~Backing();
99 void updatePriority();
100 void updateInDrawingImplTree();
101
102 PrioritizedResource* owner() { return m_owner; }
103 bool canBeRecycled() const;
104 int requestPriorityAtLastPriorityUpdate() const { return m_priorityAtLas tPriorityUpdate; }
105 bool wasAbovePriorityCutoffAtLastPriorityUpdate() const { return m_wasAb ovePriorityCutoffAtLastPriorityUpdate; }
106 bool inDrawingImplTree() const { return m_inDrawingImplTree; }
107
108 void deleteResource(ResourceProvider*);
109 bool resourceHasBeenDeleted() const;
110
111 private:
112 const Proxy* proxy() const;
113
114 friend class PrioritizedResource;
115 friend class PrioritizedResourceManager;
116 PrioritizedResource* m_owner;
117 int m_priorityAtLastPriorityUpdate;
118 bool m_wasAbovePriorityCutoffAtLastPriorityUpdate;
119
120 // Set if this is currently-drawing impl tree.
121 bool m_inDrawingImplTree;
122
123 bool m_resourceHasBeenDeleted;
124
125 #ifndef NDEBUG
126 ResourceProvider* m_resourceProvider;
127 #endif
128 DISALLOW_COPY_AND_ASSIGN(Backing);
129 };
130
131 PrioritizedResource(PrioritizedResourceManager*, gfx::Size, GLenum format);
132
133 bool isAbovePriorityCutoff() { return m_isAbovePriorityCutoff; }
134 void setAbovePriorityCutoff(bool isAbovePriorityCutoff) { m_isAbovePriorityC utoff = isAbovePriorityCutoff; }
135 void setManagerInternal(PrioritizedResourceManager* manager) { m_manager = m anager; }
136
137 Backing* backing() const { return m_backing; }
138 void link(Backing*);
139 void unlink();
140
141 gfx::Size m_size;
142 GLenum m_format;
143 size_t m_bytes;
144 bool m_contentsSwizzled;
145
146 int m_priority;
147 bool m_isAbovePriorityCutoff;
148 bool m_isSelfManaged;
149
150 Backing* m_backing;
151 PrioritizedResourceManager* m_manager;
152
153 DISALLOW_COPY_AND_ASSIGN(PrioritizedResource);
154 };
155
156 } // namespace cc
157
158 #endif // CC_PRIORITIZED_RESOURCE_H_
OLDNEW
« no previous file with comments | « cc/platform_color.h ('k') | cc/prioritized_resource.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698