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

Side by Side Diff: ui/cc/ManagedTexture.cpp

Issue 10701016: Initial import attempt, just to play with. Many things disabled/removed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | « ui/cc/ManagedTexture.h ('k') | ui/cc/PlatformColor.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 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25 #include "config.h"
26
27 #if USE(ACCELERATED_COMPOSITING)
28
29 #include "ManagedTexture.h"
30
31 #include "GraphicsContext3D.h"
32 #include "cc/CCGraphicsContext.h"
33 #include <public/WebGraphicsContext3D.h>
34
35 using WebKit::WebGraphicsContext3D;
36
37 namespace WebCore {
38
39 ManagedTexture::ManagedTexture(TextureManager* manager)
40 : m_textureManager(manager)
41 , m_token(0)
42 , m_format(0)
43 , m_textureId(0)
44 {
45 m_textureManager->registerTexture(this);
46 }
47
48 ManagedTexture::ManagedTexture(TextureManager* manager, TextureToken token, IntS ize size, unsigned format, unsigned textureId)
49 : m_textureManager(manager)
50 , m_token(token)
51 , m_size(size)
52 , m_format(format)
53 , m_textureId(textureId)
54 {
55 m_textureManager->registerTexture(this);
56 }
57
58 ManagedTexture::~ManagedTexture()
59 {
60 if (!m_textureManager)
61 return;
62 m_textureManager->unregisterTexture(this);
63 if (m_token)
64 m_textureManager->releaseToken(m_token);
65 }
66
67 void ManagedTexture::setTextureManager(TextureManager* manager)
68 {
69 if (manager == m_textureManager)
70 return;
71
72 if (m_textureManager)
73 m_textureManager->unregisterTexture(this);
74 m_textureManager = manager;
75 clear();
76 if (m_textureManager)
77 m_textureManager->registerTexture(this);
78 }
79
80 bool ManagedTexture::isValid(const IntSize& size, unsigned format)
81 {
82 return m_token && size == m_size && format == m_format && m_textureManager & & m_textureManager->hasTexture(m_token);
83 }
84
85 bool ManagedTexture::reserve(const IntSize& size, unsigned format)
86 {
87 if (!m_textureManager)
88 return false;
89
90 if (!m_token)
91 m_token = m_textureManager->getToken();
92
93 bool reserved = true;
94 if (size == m_size && format == m_format && m_textureManager->hasTexture(m_t oken))
95 m_textureManager->protectTexture(m_token);
96 else {
97 m_textureId = 0;
98 reserved = m_textureManager->requestTexture(m_token, size, format);
99 if (reserved) {
100 m_size = size;
101 m_format = format;
102 }
103 }
104
105 return reserved;
106 }
107
108 void ManagedTexture::unreserve()
109 {
110 if (!m_token || !m_textureManager)
111 return;
112
113 m_textureManager->unprotectTexture(m_token);
114 }
115
116 void ManagedTexture::allocate(TextureAllocator* allocator)
117 {
118 ASSERT(m_textureManager->hasTexture(m_token));
119 if (!m_textureId)
120 m_textureId = m_textureManager->allocateTexture(allocator, m_token);
121 }
122
123 void ManagedTexture::bindTexture(CCGraphicsContext* context, TextureAllocator* a llocator)
124 {
125 allocate(allocator);
126 WebGraphicsContext3D* context3d = context->context3D();
127 if (!context3d) {
128 // FIXME: Implement this path for software compositing.
129 return;
130 }
131 context3d->bindTexture(GL_TEXTURE_2D, m_textureId);
132 }
133
134 PassOwnPtr<ManagedTexture> ManagedTexture::steal()
135 {
136 OwnPtr<ManagedTexture> texture = adoptPtr(new ManagedTexture(m_textureManage r, m_token, m_size, m_format, m_textureId));
137 clear();
138 return texture.release();
139 }
140
141 void ManagedTexture::clear()
142 {
143 m_token = 0;
144 m_size = IntSize();
145 m_format = 0;
146 m_textureId = 0;
147 }
148
149 }
150
151 #endif // USE(ACCELERATED_COMPOSITING)
OLDNEW
« no previous file with comments | « ui/cc/ManagedTexture.h ('k') | ui/cc/PlatformColor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698