[email protected] | 192093059 | 2012-01-11 14:54:48 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c797cd4 | 2011-03-15 02:18:36 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 5 | #include "ui/compositor/compositor.h" |
[email protected] | ed8de92d | 2011-09-14 04:16:48 | [diff] [blame] | 6 | |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 8 | #include "base/threading/thread_restrictions.h" |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 9 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h" |
| 10 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoint.h" |
| 11 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| 12 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
[email protected] | 46a519fba | 2012-04-23 00:40:35 | [diff] [blame] | 13 | #include "third_party/skia/include/core/SkBitmap.h" |
| 14 | #include "third_party/skia/include/images/SkImageEncoder.h" |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 15 | #include "ui/compositor/compositor_observer.h" |
| 16 | #include "ui/compositor/compositor_switches.h" |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 17 | #include "ui/compositor/dip_util.h" |
[email protected] | 116302fc | 2012-05-05 21:45:41 | [diff] [blame] | 18 | #include "ui/compositor/layer.h" |
| 19 | #include "ui/compositor/test_web_graphics_context_3d.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame^] | 20 | #include "ui/gl/gl_context.h" |
| 21 | #include "ui/gl/gl_implementation.h" |
| 22 | #include "ui/gl/gl_surface.h" |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 23 | #include "webkit/glue/webthread_impl.h" |
| 24 | #include "webkit/gpu/webgraphicscontext3d_in_process_impl.h" |
| 25 | |
| 26 | namespace { |
| 27 | |
| 28 | const double kDefaultRefreshRate = 60.0; |
| 29 | const double kTestRefreshRate = 100.0; |
| 30 | |
| 31 | webkit_glue::WebThreadImpl* g_compositor_thread = NULL; |
| 32 | |
| 33 | bool test_compositor_enabled = false; |
| 34 | |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 35 | ui::ContextFactory* g_context_factory = NULL; |
| 36 | |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 37 | } // anonymous namespace |
[email protected] | c797cd4 | 2011-03-15 02:18:36 | [diff] [blame] | 38 | |
| 39 | namespace ui { |
| 40 | |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 41 | // static |
| 42 | ContextFactory* ContextFactory::GetInstance() { |
| 43 | // We leak the shared resources so that we don't race with |
| 44 | // the tear down of the gl_bindings. |
| 45 | if (!g_context_factory) { |
[email protected] | 46a519fba | 2012-04-23 00:40:35 | [diff] [blame] | 46 | DVLOG(1) << "Using DefaultSharedResource"; |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 47 | scoped_ptr<DefaultContextFactory> instance( |
| 48 | new DefaultContextFactory()); |
| 49 | if (instance->Initialize()) |
| 50 | g_context_factory = instance.release(); |
| 51 | } |
| 52 | return g_context_factory; |
[email protected] | ca80663 | 2012-02-16 02:15:59 | [diff] [blame] | 53 | } |
| 54 | |
[email protected] | 58b4b6d | 2012-02-16 01:40:24 | [diff] [blame] | 55 | // static |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 56 | void ContextFactory::SetInstance(ContextFactory* instance) { |
| 57 | g_context_factory = instance; |
[email protected] | ca80663 | 2012-02-16 02:15:59 | [diff] [blame] | 58 | } |
| 59 | |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 60 | DefaultContextFactory::DefaultContextFactory() { |
| 61 | } |
[email protected] | ca80663 | 2012-02-16 02:15:59 | [diff] [blame] | 62 | |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 63 | DefaultContextFactory::~DefaultContextFactory() { |
| 64 | } |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 65 | |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 66 | bool DefaultContextFactory::Initialize() { |
| 67 | // The following line of code exists soley to disable IO restrictions |
| 68 | // on this thread long enough to perform the GL bindings. |
| 69 | // TODO(wjmaclean) Remove this when GL initialisation cleaned up. |
| 70 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 71 | if (!gfx::GLSurface::InitializeOneOff() || |
| 72 | gfx::GetGLImplementation() == gfx::kGLImplementationNone) { |
| 73 | LOG(ERROR) << "Could not load the GL bindings"; |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 74 | return false; |
| 75 | } |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 76 | return true; |
| 77 | } |
| 78 | |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 79 | WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContext( |
| 80 | Compositor* compositor) { |
[email protected] | 84dba8ca | 2012-04-10 03:27:39 | [diff] [blame] | 81 | return CreateContextCommon(compositor, false); |
| 82 | } |
| 83 | |
| 84 | WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateOffscreenContext( |
| 85 | Compositor* compositor) { |
| 86 | return CreateContextCommon(compositor, true); |
| 87 | } |
| 88 | |
| 89 | void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { |
| 90 | } |
| 91 | |
| 92 | WebKit::WebGraphicsContext3D* DefaultContextFactory::CreateContextCommon( |
| 93 | Compositor* compositor, |
| 94 | bool offscreen) { |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 95 | WebKit::WebGraphicsContext3D::Attributes attrs; |
| 96 | attrs.shareResources = true; |
| 97 | WebKit::WebGraphicsContext3D* context = |
[email protected] | 84dba8ca | 2012-04-10 03:27:39 | [diff] [blame] | 98 | offscreen ? |
| 99 | webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWebView( |
| 100 | attrs, false) : |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 101 | webkit::gpu::WebGraphicsContext3DInProcessImpl::CreateForWindow( |
| 102 | attrs, compositor->widget(), share_group_.get()); |
| 103 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 104 | if (!command_line->HasSwitch(switches::kDisableUIVsync)) { |
| 105 | context->makeContextCurrent(); |
| 106 | gfx::GLContext* gl_context = gfx::GLContext::GetCurrent(); |
| 107 | gl_context->SetSwapInterval(1); |
| 108 | gl_context->ReleaseCurrent(NULL); |
| 109 | } |
| 110 | return context; |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 111 | } |
| 112 | |
[email protected] | 7359d13 | 2012-02-10 00:31:43 | [diff] [blame] | 113 | Texture::Texture(bool flipped, const gfx::Size& size) |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 114 | : texture_id_(0), |
[email protected] | 7359d13 | 2012-02-10 00:31:43 | [diff] [blame] | 115 | flipped_(flipped), |
| 116 | size_(size) { |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | Texture::~Texture() { |
| 120 | } |
| 121 | |
| 122 | Compositor::Compositor(CompositorDelegate* delegate, |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 123 | gfx::AcceleratedWidget widget) |
[email protected] | 82a01ac | 2011-09-08 16:00:18 | [diff] [blame] | 124 | : delegate_(delegate), |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 125 | root_layer_(NULL), |
| 126 | widget_(widget), |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 127 | root_web_layer_(WebKit::WebLayer::create()), |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 128 | swap_posted_(false), |
| 129 | device_scale_factor_(0.0f) { |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 130 | WebKit::WebLayerTreeView::Settings settings; |
| 131 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 132 | settings.showFPSCounter = |
| 133 | command_line->HasSwitch(switches::kUIShowFPSCounter); |
| 134 | settings.showPlatformLayerTree = |
| 135 | command_line->HasSwitch(switches::kUIShowLayerTree); |
| 136 | settings.refreshRate = test_compositor_enabled ? |
| 137 | kTestRefreshRate : kDefaultRefreshRate; |
| 138 | settings.partialSwapEnabled = |
| 139 | command_line->HasSwitch(switches::kUIEnablePartialSwap); |
[email protected] | e570b93c | 2012-02-15 16:50:48 | [diff] [blame] | 140 | settings.perTilePainting = |
| 141 | command_line->HasSwitch(switches::kUIEnablePerTilePainting); |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 142 | |
[email protected] | ba7aeb8 | 2012-02-24 23:36:13 | [diff] [blame] | 143 | host_.initialize(this, root_web_layer_, settings); |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 144 | root_web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); |
[email protected] | 82a01ac | 2011-09-08 16:00:18 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | Compositor::~Compositor() { |
[email protected] | e332a1b | 2012-05-10 20:32:27 | [diff] [blame] | 148 | // Don't call |CompositorDelegate::ScheduleDraw| from this point. |
| 149 | delegate_ = NULL; |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 150 | // There's a cycle between |root_web_layer_| and |host_|, which results in |
| 151 | // leaking and/or crashing. Explicitly set the root layer to NULL so the cycle |
| 152 | // is broken. |
| 153 | host_.setRootLayer(NULL); |
[email protected] | 7ab3f27 | 2011-11-16 00:51:56 | [diff] [blame] | 154 | if (root_layer_) |
| 155 | root_layer_->SetCompositor(NULL); |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 156 | if (!test_compositor_enabled) |
| 157 | ContextFactory::GetInstance()->RemoveCompositor(this); |
[email protected] | 82a01ac | 2011-09-08 16:00:18 | [diff] [blame] | 158 | } |
| 159 | |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 160 | void Compositor::Initialize(bool use_thread) { |
| 161 | if (use_thread) |
| 162 | g_compositor_thread = new webkit_glue::WebThreadImpl("Browser Compositor"); |
| 163 | WebKit::WebCompositor::initialize(g_compositor_thread); |
| 164 | } |
| 165 | |
| 166 | void Compositor::Terminate() { |
| 167 | WebKit::WebCompositor::shutdown(); |
| 168 | if (g_compositor_thread) { |
| 169 | delete g_compositor_thread; |
| 170 | g_compositor_thread = NULL; |
| 171 | } |
| 172 | } |
| 173 | |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 174 | void Compositor::ScheduleDraw() { |
[email protected] | f78649ea | 2012-02-23 18:39:04 | [diff] [blame] | 175 | if (g_compositor_thread) { |
| 176 | // TODO(nduca): Temporary while compositor calls |
| 177 | // compositeImmediately() directly. |
| 178 | layout(); |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 179 | host_.composite(); |
[email protected] | e332a1b | 2012-05-10 20:32:27 | [diff] [blame] | 180 | } else if (delegate_) { |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 181 | delegate_->ScheduleDraw(); |
[email protected] | f78649ea | 2012-02-23 18:39:04 | [diff] [blame] | 182 | } |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 183 | } |
| 184 | |
[email protected] | 993d6b32 | 2011-09-27 19:14:38 | [diff] [blame] | 185 | void Compositor::SetRootLayer(Layer* root_layer) { |
[email protected] | 12233c36 | 2011-11-21 16:09:25 | [diff] [blame] | 186 | if (root_layer_ == root_layer) |
| 187 | return; |
[email protected] | 7ab3f27 | 2011-11-16 00:51:56 | [diff] [blame] | 188 | if (root_layer_) |
| 189 | root_layer_->SetCompositor(NULL); |
[email protected] | 993d6b32 | 2011-09-27 19:14:38 | [diff] [blame] | 190 | root_layer_ = root_layer; |
[email protected] | 7ab3f27 | 2011-11-16 00:51:56 | [diff] [blame] | 191 | if (root_layer_ && !root_layer_->GetCompositor()) |
[email protected] | 993d6b32 | 2011-09-27 19:14:38 | [diff] [blame] | 192 | root_layer_->SetCompositor(this); |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 193 | root_web_layer_.removeAllChildren(); |
| 194 | if (root_layer_) |
| 195 | root_web_layer_.addChild(root_layer_->web_layer()); |
[email protected] | 993d6b32 | 2011-09-27 19:14:38 | [diff] [blame] | 196 | } |
| 197 | |
[email protected] | ed8de92d | 2011-09-14 04:16:48 | [diff] [blame] | 198 | void Compositor::Draw(bool force_clear) { |
| 199 | if (!root_layer_) |
| 200 | return; |
| 201 | |
[email protected] | f78649ea | 2012-02-23 18:39:04 | [diff] [blame] | 202 | // TODO(nduca): Temporary while compositor calls |
| 203 | // compositeImmediately() directly. |
| 204 | layout(); |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 205 | host_.composite(); |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 206 | if (!g_compositor_thread && !swap_posted_) |
[email protected] | 192093059 | 2012-01-11 14:54:48 | [diff] [blame] | 207 | NotifyEnd(); |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 208 | } |
| 209 | |
[email protected] | 7df588fbd | 2012-02-10 14:15:56 | [diff] [blame] | 210 | void Compositor::ScheduleFullDraw() { |
| 211 | host_.setNeedsRedraw(); |
| 212 | } |
| 213 | |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 214 | bool Compositor::ReadPixels(SkBitmap* bitmap, |
| 215 | const gfx::Rect& bounds_in_pixel) { |
| 216 | if (bounds_in_pixel.right() > size().width() || |
| 217 | bounds_in_pixel.bottom() > size().height()) |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 218 | return false; |
| 219 | // Convert to OpenGL coordinates. |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 220 | gfx::Point new_origin( |
| 221 | bounds_in_pixel.x(), |
| 222 | size().height() - bounds_in_pixel.height() - bounds_in_pixel.y()); |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 223 | |
| 224 | bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 225 | bounds_in_pixel.width(), bounds_in_pixel.height()); |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 226 | bitmap->allocPixels(); |
| 227 | SkAutoLockPixels lock_image(*bitmap); |
| 228 | unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels()); |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 229 | if (host_.compositeAndReadback( |
| 230 | pixels, gfx::Rect(new_origin, bounds_in_pixel.size()))) { |
| 231 | SwizzleRGBAToBGRAAndFlip(pixels, bounds_in_pixel.size()); |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 232 | return true; |
[email protected] | 192093059 | 2012-01-11 14:54:48 | [diff] [blame] | 233 | } |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 234 | return false; |
| 235 | } |
| 236 | |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 237 | void Compositor::SetScaleAndSize(float scale, const gfx::Size& size_in_pixel) { |
| 238 | DCHECK(scale > 0); |
| 239 | if (size_in_pixel.IsEmpty() || scale <= 0) |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 240 | return; |
[email protected] | cd9a61c7 | 2012-05-08 19:16:59 | [diff] [blame] | 241 | size_ = size_in_pixel; |
| 242 | host_.setViewportSize(size_in_pixel); |
| 243 | root_web_layer_.setBounds(size_in_pixel); |
| 244 | |
| 245 | if (device_scale_factor_ != scale && IsDIPEnabled()) { |
| 246 | device_scale_factor_ = scale; |
| 247 | if (root_layer_) |
| 248 | root_layer_->OnDeviceScaleFactorChanged(scale); |
| 249 | } |
[email protected] | ed8de92d | 2011-09-14 04:16:48 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | void Compositor::AddObserver(CompositorObserver* observer) { |
| 253 | observer_list_.AddObserver(observer); |
| 254 | } |
| 255 | |
| 256 | void Compositor::RemoveObserver(CompositorObserver* observer) { |
| 257 | observer_list_.RemoveObserver(observer); |
| 258 | } |
| 259 | |
[email protected] | 3ce2feb | 2011-09-19 18:44:23 | [diff] [blame] | 260 | bool Compositor::HasObserver(CompositorObserver* observer) { |
| 261 | return observer_list_.HasObserver(observer); |
| 262 | } |
| 263 | |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 264 | void Compositor::OnSwapBuffersPosted() { |
| 265 | swap_posted_ = true; |
| 266 | } |
| 267 | |
| 268 | void Compositor::OnSwapBuffersComplete() { |
| 269 | DCHECK(swap_posted_); |
| 270 | swap_posted_ = false; |
| 271 | NotifyEnd(); |
| 272 | } |
| 273 | |
| 274 | void Compositor::OnSwapBuffersAborted() { |
| 275 | if (swap_posted_) { |
| 276 | swap_posted_ = false; |
| 277 | NotifyEnd(); |
| 278 | } |
| 279 | } |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 280 | |
| 281 | void Compositor::updateAnimations(double frameBeginTime) { |
| 282 | } |
| 283 | |
| 284 | void Compositor::layout() { |
[email protected] | f78649ea | 2012-02-23 18:39:04 | [diff] [blame] | 285 | if (root_layer_) |
[email protected] | cedc395 | 2012-03-06 06:15:55 | [diff] [blame] | 286 | root_layer_->SendDamagedRects(); |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void Compositor::applyScrollAndScale(const WebKit::WebSize& scrollDelta, |
| 290 | float scaleFactor) { |
| 291 | } |
| 292 | |
| 293 | WebKit::WebGraphicsContext3D* Compositor::createContext3D() { |
[email protected] | ca80663 | 2012-02-16 02:15:59 | [diff] [blame] | 294 | if (test_compositor_enabled) { |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 295 | ui::TestWebGraphicsContext3D* test_context = |
| 296 | new ui::TestWebGraphicsContext3D(); |
| 297 | test_context->Initialize(); |
| 298 | return test_context; |
[email protected] | ca80663 | 2012-02-16 02:15:59 | [diff] [blame] | 299 | } else { |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 300 | return ContextFactory::GetInstance()->CreateContext(this); |
[email protected] | ca80663 | 2012-02-16 02:15:59 | [diff] [blame] | 301 | } |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 302 | } |
| 303 | |
[email protected] | ba7aeb8 | 2012-02-24 23:36:13 | [diff] [blame] | 304 | void Compositor::didRebindGraphicsContext(bool success) { |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 305 | } |
| 306 | |
[email protected] | ba7aeb8 | 2012-02-24 23:36:13 | [diff] [blame] | 307 | void Compositor::didCommitAndDrawFrame() { |
[email protected] | a8f677c | 2012-03-23 01:36:06 | [diff] [blame] | 308 | FOR_EACH_OBSERVER(CompositorObserver, |
| 309 | observer_list_, |
| 310 | OnCompositingStarted(this)); |
[email protected] | ba7aeb8 | 2012-02-24 23:36:13 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | void Compositor::didCompleteSwapBuffers() { |
| 314 | NotifyEnd(); |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void Compositor::scheduleComposite() { |
[email protected] | 33274903 | 2011-10-22 00:32:46 | [diff] [blame] | 318 | ScheduleDraw(); |
| 319 | } |
| 320 | |
[email protected] | 6f83e4f | 2011-11-15 21:25:33 | [diff] [blame] | 321 | void Compositor::SwizzleRGBAToBGRAAndFlip(unsigned char* pixels, |
| 322 | const gfx::Size& image_size) { |
| 323 | // Swizzle from RGBA to BGRA |
| 324 | size_t bitmap_size = 4 * image_size.width() * image_size.height(); |
| 325 | for(size_t i = 0; i < bitmap_size; i += 4) |
| 326 | std::swap(pixels[i], pixels[i + 2]); |
| 327 | |
| 328 | // Vertical flip to transform from GL co-ords |
| 329 | size_t row_size = 4 * image_size.width(); |
| 330 | scoped_array<unsigned char> tmp_row(new unsigned char[row_size]); |
| 331 | for(int row = 0; row < image_size.height() / 2; row++) { |
| 332 | memcpy(tmp_row.get(), |
| 333 | &pixels[row * row_size], |
| 334 | row_size); |
| 335 | memcpy(&pixels[row * row_size], |
| 336 | &pixels[bitmap_size - (row + 1) * row_size], |
| 337 | row_size); |
| 338 | memcpy(&pixels[bitmap_size - (row + 1) * row_size], |
| 339 | tmp_row.get(), |
| 340 | row_size); |
| 341 | } |
| 342 | } |
| 343 | |
[email protected] | a8f2115 | 2011-09-08 15:30:02 | [diff] [blame] | 344 | void Compositor::NotifyEnd() { |
[email protected] | a8f2115 | 2011-09-08 15:30:02 | [diff] [blame] | 345 | FOR_EACH_OBSERVER(CompositorObserver, |
| 346 | observer_list_, |
[email protected] | 3ce2feb | 2011-09-19 18:44:23 | [diff] [blame] | 347 | OnCompositingEnded(this)); |
[email protected] | a8f2115 | 2011-09-08 15:30:02 | [diff] [blame] | 348 | } |
| 349 | |
[email protected] | ab662737 | 2012-01-29 21:22:13 | [diff] [blame] | 350 | COMPOSITOR_EXPORT void SetupTestCompositor() { |
| 351 | if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 352 | switches::kDisableTestCompositor)) { |
| 353 | test_compositor_enabled = true; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | COMPOSITOR_EXPORT void DisableTestCompositor() { |
| 358 | test_compositor_enabled = false; |
[email protected] | 192093059 | 2012-01-11 14:54:48 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | 894e8fc | 2012-02-24 13:29:50 | [diff] [blame] | 361 | COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { |
| 362 | return test_compositor_enabled; |
| 363 | } |
| 364 | |
[email protected] | c797cd4 | 2011-03-15 02:18:36 | [diff] [blame] | 365 | } // namespace ui |