Don't consider a Bluetooth adapter present until it has an address.
[chromium-blink-merge.git] / cc / CCPrioritizedTexture.h
blobec90a49cca67bf7ae86e4f31118c391f945ae750
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.
5 #ifndef CCPrioritizedTexture_h
6 #define CCPrioritizedTexture_h
8 #include "CCPriorityCalculator.h"
9 #include "CCResourceProvider.h"
10 #include "CCTexture.h"
11 #include "GraphicsContext3D.h"
12 #include "IntRect.h"
13 #include "IntSize.h"
15 namespace WebCore {
17 class CCPrioritizedTextureManager;
19 class CCPrioritizedTexture {
20 WTF_MAKE_NONCOPYABLE(CCPrioritizedTexture);
21 public:
22 static PassOwnPtr<CCPrioritizedTexture> create(CCPrioritizedTextureManager* manager, IntSize size, GC3Denum format)
24 return adoptPtr(new CCPrioritizedTexture(manager, size, format));
26 static PassOwnPtr<CCPrioritizedTexture> create(CCPrioritizedTextureManager* manager)
28 return adoptPtr(new CCPrioritizedTexture(manager, IntSize(), 0));
30 ~CCPrioritizedTexture();
32 // Texture properties. Changing these causes the backing texture to be lost.
33 // Setting these to the same value is a no-op.
34 void setTextureManager(CCPrioritizedTextureManager*);
35 CCPrioritizedTextureManager* textureManager() { return m_manager; }
36 void setDimensions(IntSize, GC3Denum format);
37 GC3Denum format() const { return m_format; }
38 IntSize size() const { return m_size; }
39 size_t bytes() const { return m_bytes; }
41 // Set priority for the requested texture.
42 void setRequestPriority(int priority) { m_priority = priority; }
43 int requestPriority() const { return m_priority; }
45 // After CCPrioritizedTexture::prioritizeTextures() is called, this returns
46 // if the the request succeeded and this texture can be acquired for use.
47 bool canAcquireBackingTexture() const { return m_isAbovePriorityCutoff; }
49 // This returns whether we still have a backing texture. This can continue
50 // to be true even after canAcquireBackingTexture() becomes false. In this
51 // case the texture can be used but shouldn't be updated since it will get
52 // taken away "soon".
53 bool haveBackingTexture() const { return !!backing(); }
55 // If canAcquireBackingTexture() is true acquireBackingTexture() will acquire
56 // a backing texture for use. Call this whenever the texture is actually needed.
57 void acquireBackingTexture(CCResourceProvider*);
59 // FIXME: Request late is really a hack for when we are totally out of memory
60 // (all textures are visible) but we can still squeeze into the limit
61 // by not painting occluded textures. In this case the manager
62 // refuses all visible textures and requestLate() will enable
63 // canAcquireBackingTexture() on a call-order basis. We might want to
64 // just remove this in the future (carefully) and just make sure we don't
65 // regress OOMs situations.
66 bool requestLate();
68 // Uploads pixels into the backing resource. This functions will aquire the backing if needed.
69 void upload(CCResourceProvider*, const uint8_t* image, const IntRect& imageRect, const IntRect& sourceRect, const IntSize& destOffset);
71 CCResourceProvider::ResourceId resourceId() const;
73 // Self-managed textures are accounted for when prioritizing other textures,
74 // but they are not allocated/recycled/deleted, so this needs to be done
75 // externally. canAcquireBackingTexture() indicates if the texture would have
76 // been allowed given its priority.
77 void setIsSelfManaged(bool isSelfManaged) { m_isSelfManaged = isSelfManaged; }
78 bool isSelfManaged() { return m_isSelfManaged; }
79 void setToSelfManagedMemoryPlaceholder(size_t bytes);
81 private:
82 friend class CCPrioritizedTextureManager;
84 class Backing : public CCTexture {
85 WTF_MAKE_NONCOPYABLE(Backing);
86 public:
87 Backing(unsigned id, IntSize size, GC3Denum format)
88 : CCTexture(id, size, format), m_owner(0) { }
89 ~Backing() { ASSERT(!m_owner); }
91 CCPrioritizedTexture* owner() { return m_owner; }
92 private:
93 friend class CCPrioritizedTexture;
94 CCPrioritizedTexture* m_owner;
97 CCPrioritizedTexture(CCPrioritizedTextureManager*, IntSize, GC3Denum format);
99 bool isAbovePriorityCutoff() { return m_isAbovePriorityCutoff; }
100 void setAbovePriorityCutoff(bool isAbovePriorityCutoff) { m_isAbovePriorityCutoff = isAbovePriorityCutoff; }
101 void setManagerInternal(CCPrioritizedTextureManager* manager) { m_manager = manager; }
103 Backing* backing() const { return m_backing; }
104 void link(Backing*);
105 void unlink();
107 IntSize m_size;
108 GC3Denum m_format;
109 size_t m_bytes;
111 size_t m_priority;
112 bool m_isAbovePriorityCutoff;
113 bool m_isSelfManaged;
115 Backing* m_backing;
116 CCPrioritizedTextureManager* m_manager;
119 } // WebCore
121 #endif