Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium 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 "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/browser_trial.h" | 10 #include "chrome/browser/browser_trial.h" |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 DCHECK(renderWidgetHostView_->render_widget_host_->process()->HasConnection()) ; | 542 DCHECK(renderWidgetHostView_->render_widget_host_->process()->HasConnection()) ; |
| 543 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_); | 543 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_); |
| 544 | 544 |
| 545 renderWidgetHostView_->invalid_rect_ = dirtyRect; | 545 renderWidgetHostView_->invalid_rect_ = dirtyRect; |
| 546 renderWidgetHostView_->about_to_validate_and_paint_ = true; | 546 renderWidgetHostView_->about_to_validate_and_paint_ = true; |
| 547 BackingStore* backing_store = | 547 BackingStore* backing_store = |
| 548 renderWidgetHostView_->render_widget_host_->GetBackingStore(true); | 548 renderWidgetHostView_->render_widget_host_->GetBackingStore(true); |
| 549 renderWidgetHostView_->about_to_validate_and_paint_ = false; | 549 renderWidgetHostView_->about_to_validate_and_paint_ = false; |
| 550 dirtyRect = renderWidgetHostView_->invalid_rect_; | 550 dirtyRect = renderWidgetHostView_->invalid_rect_; |
| 551 | 551 |
| 552 if (backing_store && backing_store->cg_layer()) { | 552 if (backing_store) { |
| 553 NSRect view_bounds = [self bounds]; | 553 NSRect view_bounds = [self bounds]; |
| 554 gfx::Rect damaged_rect([self NSRectToRect:dirtyRect]); | 554 gfx::Rect damaged_rect([self NSRectToRect:dirtyRect]); |
| 555 | 555 |
| 556 gfx::Rect bitmap_rect(0, 0, | 556 gfx::Rect bitmap_rect(0, 0, |
| 557 backing_store->size().width(), | 557 backing_store->size().width(), |
| 558 backing_store->size().height()); | 558 backing_store->size().height()); |
| 559 | 559 |
| 560 gfx::Rect paint_rect = bitmap_rect.Intersect(damaged_rect); | 560 gfx::Rect paint_rect = bitmap_rect.Intersect(damaged_rect); |
| 561 if (!paint_rect.IsEmpty()) { | 561 if (!paint_rect.IsEmpty()) { |
| 562 CGContextRef context = static_cast<CGContextRef>( | 562 // if we have a CGLayer, draw that into the window |
| 563 [[NSGraphicsContext currentContext] graphicsPort]); | 563 if (backing_store->cg_layer()) { |
| 564 CGContextRef context = static_cast<CGContextRef>( | |
| 565 [[NSGraphicsContext currentContext] graphicsPort]); | |
| 564 | 566 |
| 565 // TODO: add clipping to dirtyRect if it improves drawing performance. | 567 // TODO: add clipping to dirtyRect if it improves drawing performance. |
| 566 CGContextDrawLayerAtPoint(context, CGPointMake(0.0, 0.0), | 568 CGContextDrawLayerAtPoint(context, CGPointMake(0.0, 0.0), |
| 567 backing_store->cg_layer()); | 569 backing_store->cg_layer()); |
| 570 } else { | |
| 571 // if we haven't created a layer yet, draw the cached bitmap into | |
| 572 // the window. The CGLayer will be created the next time the renderer | |
| 573 // paints. | |
| 574 CGContextRef context = static_cast<CGContextRef>( | |
| 575 [[NSGraphicsContext currentContext] graphicsPort]); | |
| 576 scoped_cftyperef<CGImageRef> image( | |
| 577 CGBitmapContextCreateImage(backing_store->cg_bitmap())); | |
|
rohitrao (ping after 24h)
2009/08/31 21:18:13
What will happen if cg_bitmap() returns NULL? Do
Amanda Walker
2009/08/31 21:22:30
Since one or the other always gets created in the
| |
| 578 CGContextDrawImage(context, bitmap_rect.ToCGRect(), image); | |
| 579 } | |
| 568 } | 580 } |
| 569 | 581 |
| 570 // Fill the remaining portion of the damaged_rect with white | 582 // Fill the remaining portion of the damaged_rect with white |
| 571 if (damaged_rect.right() > bitmap_rect.right()) { | 583 if (damaged_rect.right() > bitmap_rect.right()) { |
| 572 int x = std::max(bitmap_rect.right(), damaged_rect.x()); | 584 int x = std::max(bitmap_rect.right(), damaged_rect.x()); |
| 573 int y = std::min(bitmap_rect.bottom(), damaged_rect.bottom()); | 585 int y = std::min(bitmap_rect.bottom(), damaged_rect.bottom()); |
| 574 int width = damaged_rect.right() - x; | 586 int width = damaged_rect.right() - x; |
| 575 int height = damaged_rect.y() - y; | 587 int height = damaged_rect.y() - y; |
| 576 | 588 |
| 577 // Extra fun to get around the fact that gfx::Rects can't have | 589 // Extra fun to get around the fact that gfx::Rects can't have |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1082 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 1094 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
| 1083 } else { | 1095 } else { |
| 1084 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( | 1096 renderWidgetHostView_->render_widget_host_->ImeConfirmComposition( |
| 1085 UTF8ToUTF16([im_text UTF8String])); | 1097 UTF8ToUTF16([im_text UTF8String])); |
| 1086 } | 1098 } |
| 1087 renderWidgetHostView_->im_composing_ = false; | 1099 renderWidgetHostView_->im_composing_ = false; |
| 1088 } | 1100 } |
| 1089 | 1101 |
| 1090 @end | 1102 @end |
| 1091 | 1103 |
| OLD | NEW |