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

Side by Side Diff: trunk/src/cc/layers/painted_scrollbar_layer.cc

Issue 23740010: Revert 223162 "Update the nine patch layer to use UI resources" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "cc/layers/painted_scrollbar_layer.h" 5 #include "cc/layers/painted_scrollbar_layer.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "cc/layers/painted_scrollbar_layer_impl.h" 10 #include "cc/layers/painted_scrollbar_layer_impl.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 gfx::Rect thumb_rect = OriginThumbRect(); 203 gfx::Rect thumb_rect = OriginThumbRect();
204 204
205 if (scrollbar_->HasThumb() && !thumb_rect.IsEmpty()) { 205 if (scrollbar_->HasThumb() && !thumb_rect.IsEmpty()) {
206 thumb_resource_ = ScopedUIResource::Create( 206 thumb_resource_ = ScopedUIResource::Create(
207 layer_tree_host(), RasterizeScrollbarPart(thumb_rect, THUMB)); 207 layer_tree_host(), RasterizeScrollbarPart(thumb_rect, THUMB));
208 } 208 }
209 209
210 return true; 210 return true;
211 } 211 }
212 212
213 UIResourceBitmap PaintedScrollbarLayer::RasterizeScrollbarPart( 213 scoped_refptr<UIResourceBitmap> PaintedScrollbarLayer::RasterizeScrollbarPart(
214 gfx::Rect rect, 214 gfx::Rect rect,
215 ScrollbarPart part) { 215 ScrollbarPart part) {
216 DCHECK(!rect.size().IsEmpty()); 216 DCHECK(!rect.size().IsEmpty());
217 217
218 scoped_refptr<UIResourceBitmap> bitmap =
219 UIResourceBitmap::Create(new uint8_t[rect.width() * rect.height() * 4],
220 UIResourceBitmap::RGBA8,
221 UIResourceBitmap::CLAMP_TO_EDGE,
222 rect.size());
223
218 SkBitmap skbitmap; 224 SkBitmap skbitmap;
219 skbitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height()); 225 skbitmap.setConfig(SkBitmap::kARGB_8888_Config, rect.width(), rect.height());
220 skbitmap.allocPixels(); 226 skbitmap.setPixels(bitmap->GetPixels());
221 227
222 SkCanvas skcanvas(skbitmap); 228 SkCanvas skcanvas(skbitmap);
223 skcanvas.translate(SkFloatToScalar(-rect.x()), SkFloatToScalar(-rect.y())); 229 skcanvas.translate(SkFloatToScalar(-rect.x()), SkFloatToScalar(-rect.y()));
224 skcanvas.scale(SkFloatToScalar(contents_scale_x()), 230 skcanvas.scale(SkFloatToScalar(contents_scale_x()),
225 SkFloatToScalar(contents_scale_y())); 231 SkFloatToScalar(contents_scale_y()));
226 232
227 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( 233 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect(
228 rect, 1.f / contents_scale_x(), 1.f / contents_scale_y()); 234 rect, 1.f / contents_scale_x(), 1.f / contents_scale_y());
229 SkRect layer_skrect = RectToSkRect(layer_rect); 235 SkRect layer_skrect = RectToSkRect(layer_rect);
230 SkPaint paint; 236 SkPaint paint;
231 paint.setAntiAlias(false); 237 paint.setAntiAlias(false);
232 paint.setXfermodeMode(SkXfermode::kClear_Mode); 238 paint.setXfermodeMode(SkXfermode::kClear_Mode);
233 skcanvas.drawRect(layer_skrect, paint); 239 skcanvas.drawRect(layer_skrect, paint);
234 skcanvas.clipRect(layer_skrect); 240 skcanvas.clipRect(layer_skrect);
235 241
236 scrollbar_->PaintPart(&skcanvas, part, layer_rect); 242 scrollbar_->PaintPart(&skcanvas, part, layer_rect);
237 // Make sure that the pixels are no longer mutable to unavoid unnecessary
238 // allocation and copying.
239 skbitmap.setImmutable();
240 243
241 return UIResourceBitmap(skbitmap); 244 return bitmap;
242 } 245 }
243 246
244 } // namespace cc 247 } // namespace cc
OLDNEW
« no previous file with comments | « trunk/src/cc/layers/painted_scrollbar_layer.h ('k') | trunk/src/cc/layers/scrollbar_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698