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

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

Issue 2823003002: SkBitmap and SkPixelRef no longer need lock/unlock (Closed)
Patch Set: win fix after 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
« no previous file with comments | « ui/gfx/blit_unittest.cc ('k') | ui/gfx/codec/png_codec.h » ('j') | 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) 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 shader_scale)); 507 shader_scale));
508 return true; 508 return true;
509 } 509 }
510 510
511 void Canvas::Transform(const gfx::Transform& transform) { 511 void Canvas::Transform(const gfx::Transform& transform) {
512 canvas_->concat(transform.matrix()); 512 canvas_->concat(transform.matrix());
513 } 513 }
514 514
515 SkBitmap Canvas::GetBitmap() const { 515 SkBitmap Canvas::GetBitmap() const {
516 DCHECK(bitmap_); 516 DCHECK(bitmap_);
517 SkBitmap bitmap = bitmap_.value(); 517 return bitmap_.value();
518 // When the bitmap is copied, it shares the underlying pixelref, but doesn't
519 // initialize pixels unless they are locked. Hence, ensure that the returned
520 // bitmap keeps the pixelref alive by locking it. Note that the dtor of
521 // SkBitmap will unlock the pixelrefs, so this won't leak. Also note that
522 // moving SkBitmap retains the same lock as the source, so the caller
523 // will receive a locked-pixels bitmap.
524 bitmap.lockPixels();
525 return bitmap;
526 } 518 }
527 519
528 bool Canvas::IntersectsClipRect(const SkRect& rect) { 520 bool Canvas::IntersectsClipRect(const SkRect& rect) {
529 SkRect clip; 521 SkRect clip;
530 return canvas_->getLocalClipBounds(&clip) && clip.intersects(rect); 522 return canvas_->getLocalClipBounds(&clip) && clip.intersects(rect);
531 } 523 }
532 524
533 void Canvas::DrawImageIntHelper(const ImageSkiaRep& image_rep, 525 void Canvas::DrawImageIntHelper(const ImageSkiaRep& image_rep,
534 int src_x, 526 int src_x,
535 int src_y, 527 int src_y,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 bitmap_.emplace(); 582 bitmap_.emplace();
591 bitmap_->allocPixels(info); 583 bitmap_->allocPixels(info);
592 // Ensure that the bitmap is zeroed, since the code expects that. 584 // Ensure that the bitmap is zeroed, since the code expects that.
593 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); 585 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize());
594 586
595 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); 587 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value());
596 return &owned_canvas_.value(); 588 return &owned_canvas_.value();
597 } 589 }
598 590
599 } // namespace gfx 591 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/blit_unittest.cc ('k') | ui/gfx/codec/png_codec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698