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

Side by Side Diff: ui/gfx/canvas.cc

Issue 2823003002: SkBitmap and SkPixelRef no longer need lock/unlock (Closed)
Patch Set: rebase Created 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/gfx/canvas.h" 5 #include "ui/gfx/canvas.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 shader_scale)); 518 shader_scale));
519 return true; 519 return true;
520 } 520 }
521 521
522 void Canvas::Transform(const gfx::Transform& transform) { 522 void Canvas::Transform(const gfx::Transform& transform) {
523 canvas_->concat(transform.matrix()); 523 canvas_->concat(transform.matrix());
524 } 524 }
525 525
526 SkBitmap Canvas::GetBitmap() const { 526 SkBitmap Canvas::GetBitmap() const {
527 DCHECK(bitmap_); 527 DCHECK(bitmap_);
528 SkBitmap bitmap = bitmap_.value(); 528 return bitmap_.value();
529 // When the bitmap is copied, it shares the underlying pixelref, but doesn't
530 // initialize pixels unless they are locked. Hence, ensure that the returned
531 // bitmap keeps the pixelref alive by locking it. Note that the dtor of
532 // SkBitmap will unlock the pixelrefs, so this won't leak. Also note that
533 // moving SkBitmap retains the same lock as the source, so the caller
534 // will receive a locked-pixels bitmap.
535 bitmap.lockPixels();
536 return bitmap;
537 } 529 }
538 530
539 bool Canvas::IntersectsClipRect(const SkRect& rect) { 531 bool Canvas::IntersectsClipRect(const SkRect& rect) {
540 SkRect clip; 532 SkRect clip;
541 return canvas_->getLocalClipBounds(&clip) && clip.intersects(rect); 533 return canvas_->getLocalClipBounds(&clip) && clip.intersects(rect);
542 } 534 }
543 535
544 void Canvas::DrawImageIntHelper(const ImageSkiaRep& image_rep, 536 void Canvas::DrawImageIntHelper(const ImageSkiaRep& image_rep,
545 int src_x, 537 int src_x,
546 int src_y, 538 int src_y,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 bitmap_.emplace(); 593 bitmap_.emplace();
602 bitmap_->allocPixels(info); 594 bitmap_->allocPixels(info);
603 // Ensure that the bitmap is zeroed, since the code expects that. 595 // Ensure that the bitmap is zeroed, since the code expects that.
604 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); 596 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize());
605 597
606 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); 598 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value());
607 return &owned_canvas_.value(); 599 return &owned_canvas_.value();
608 } 600 }
609 601
610 } // namespace gfx 602 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698