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