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

Side by Side Diff: compositor/mock_compositor.cc

Issue 6691037: wm: Fix an uncommon memory leak in the compositor code. (Closed) Base URL: ssh://gitrw.chromium.org:9222/window_manager.git@master
Patch Set: update another arg to be a const ref Created 9 years, 8 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 | « compositor/mock_compositor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "window_manager/compositor/mock_compositor.h" 5 #include "window_manager/compositor/mock_compositor.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "window_manager/image_container.h" 8 #include "window_manager/image_container.h"
9 #include "window_manager/util.h" 9 #include "window_manager/util.h"
10 #include "window_manager/x11/x_connection.h" 10 #include "window_manager/x11/x_connection.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 139 }
140 140
141 void MockCompositor::ImageActor::SetImageData( 141 void MockCompositor::ImageActor::SetImageData(
142 const ImageContainer& image_container) { 142 const ImageContainer& image_container) {
143 SetSizeInternal(image_container.width(), image_container.height()); 143 SetSizeInternal(image_container.width(), image_container.height());
144 } 144 }
145 145
146 146
147 MockCompositor::TexturePixmapActor::TexturePixmapActor(XConnection* xconn) 147 MockCompositor::TexturePixmapActor::TexturePixmapActor(XConnection* xconn)
148 : xconn_(xconn), 148 : xconn_(xconn),
149 alpha_mask_bytes_(NULL),
150 pixmap_(0), 149 pixmap_(0),
151 num_texture_updates_(0), 150 num_texture_updates_(0),
152 damaged_region_() { 151 damaged_region_() {
153 SetSizeInternal(0, 0); 152 SetSizeInternal(0, 0);
154 } 153 }
155 154
156 MockCompositor::TexturePixmapActor::~TexturePixmapActor() { 155 MockCompositor::TexturePixmapActor::~TexturePixmapActor() {
157 ClearAlphaMask();
158 } 156 }
159 157
160 void MockCompositor::TexturePixmapActor::SetPixmap(XWindow pixmap) { 158 void MockCompositor::TexturePixmapActor::SetPixmap(XWindow pixmap) {
161 pixmap_ = pixmap; 159 pixmap_ = pixmap;
162 XConnection::WindowGeometry geometry; 160 XConnection::WindowGeometry geometry;
163 if (xconn_->GetWindowGeometry(pixmap_, &geometry)) { 161 if (xconn_->GetWindowGeometry(pixmap_, &geometry)) {
164 SetSizeInternal(geometry.bounds.width, geometry.bounds.height); 162 SetSizeInternal(geometry.bounds.width, geometry.bounds.height);
165 } else { 163 } else {
166 SetSizeInternal(0, 0); 164 SetSizeInternal(0, 0);
167 } 165 }
168 } 166 }
169 167
170 void MockCompositor::TexturePixmapActor::SetAlphaMask( 168 void MockCompositor::TexturePixmapActor::SetAlphaMask(
171 const uint8_t* bytes, int width, int height) { 169 const uint8_t* bytes, int width, int height) {
172 ClearAlphaMask(); 170 ClearAlphaMask();
173 size_t size = width * height; 171 size_t size = width * height;
174 alpha_mask_bytes_ = new unsigned char[size]; 172 alpha_mask_bytes_.reset(new uint8_t[size]);
175 memcpy(alpha_mask_bytes_, bytes, size); 173 memcpy(alpha_mask_bytes_.get(), bytes, size);
176 } 174 }
177 175
178 void MockCompositor::TexturePixmapActor::ClearAlphaMask() { 176 void MockCompositor::TexturePixmapActor::ClearAlphaMask() {
179 delete[] alpha_mask_bytes_; 177 alpha_mask_bytes_.reset();
180 alpha_mask_bytes_ = NULL;
181 } 178 }
182 179
183 MockCompositor::ImageActor* MockCompositor::CreateImageFromFile( 180 MockCompositor::ImageActor* MockCompositor::CreateImageFromFile(
184 const std::string& filename) { 181 const std::string& filename) {
185 ImageActor* actor = new ImageActor; 182 ImageActor* actor = new ImageActor;
186 InMemoryImageContainer container( 183 InMemoryImageContainer container(
187 new uint8_t[1], 1, 1, IMAGE_FORMAT_RGBA_32, false); // malloc=false 184 new uint8_t[1], 1, 1, IMAGE_FORMAT_RGBA_32, false); // malloc=false
188 actor->SetImageData(container); 185 actor->SetImageData(container);
189 return actor; 186 return actor;
190 } 187 }
191 188
192 void MockCompositor::TexturePixmapActor::MergeDamagedRegion( 189 void MockCompositor::TexturePixmapActor::MergeDamagedRegion(
193 const Rect& region) { 190 const Rect& region) {
194 damaged_region_.merge(region); 191 damaged_region_.merge(region);
195 } 192 }
196 193
197 const Rect& MockCompositor::TexturePixmapActor::GetDamagedRegion() const { 194 const Rect& MockCompositor::TexturePixmapActor::GetDamagedRegion() const {
198 return damaged_region_; 195 return damaged_region_;
199 } 196 }
200 197
201 void MockCompositor::TexturePixmapActor::ResetDamagedRegion() { 198 void MockCompositor::TexturePixmapActor::ResetDamagedRegion() {
202 damaged_region_.reset(0, 0, 0, 0); 199 damaged_region_.reset(0, 0, 0, 0);
203 } 200 }
204 201
205 } // namespace window_manager 202 } // namespace window_manager
OLDNEW
« no previous file with comments | « compositor/mock_compositor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698