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

Side by Side Diff: cc/render_surface_filters.cc

Issue 11412255: cc: Use skia::RefPtr in place of raw pointers and SkAutoTUnref. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ref() Created 8 years 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
« no previous file with comments | « cc/render_pass_unittest.cc ('k') | cc/render_surface_impl.cc » ('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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cc/render_surface_filters.h" 5 #include "cc/render_surface_filters.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "skia/ext/refptr.h"
8 #include "third_party/skia/include/core/SkCanvas.h" 9 #include "third_party/skia/include/core/SkCanvas.h"
9 #include "third_party/skia/include/effects/SkBlurImageFilter.h" 10 #include "third_party/skia/include/effects/SkBlurImageFilter.h"
10 #include "third_party/skia/include/effects/SkColorMatrixFilter.h" 11 #include "third_party/skia/include/effects/SkColorMatrixFilter.h"
11 #include "third_party/skia/include/effects/SkMagnifierImageFilter.h" 12 #include "third_party/skia/include/effects/SkMagnifierImageFilter.h"
12 #include "third_party/skia/include/gpu/SkGpuDevice.h" 13 #include "third_party/skia/include/gpu/SkGpuDevice.h"
13 #include "third_party/skia/include/gpu/SkGrPixelRef.h" 14 #include "third_party/skia/include/gpu/SkGrPixelRef.h"
14 #include "ui/gfx/size_f.h" 15 #include "ui/gfx/size_f.h"
15 #include <public/WebFilterOperation.h> 16 #include <public/WebFilterOperation.h>
16 #include <public/WebFilterOperations.h> 17 #include <public/WebFilterOperations.h>
17 #include <public/WebGraphicsContext3D.h> 18 #include <public/WebGraphicsContext3D.h>
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 FilterBufferState(GrContext* grContext, const gfx::SizeF& size, unsigned tex tureId) 240 FilterBufferState(GrContext* grContext, const gfx::SizeF& size, unsigned tex tureId)
240 : m_grContext(grContext) 241 : m_grContext(grContext)
241 , m_currentTexture(0) 242 , m_currentTexture(0)
242 { 243 {
243 // Wrap the source texture in a Ganesh platform texture. 244 // Wrap the source texture in a Ganesh platform texture.
244 GrPlatformTextureDesc platformTextureDescription; 245 GrPlatformTextureDesc platformTextureDescription;
245 platformTextureDescription.fWidth = size.width(); 246 platformTextureDescription.fWidth = size.width();
246 platformTextureDescription.fHeight = size.height(); 247 platformTextureDescription.fHeight = size.height();
247 platformTextureDescription.fConfig = kSkia8888_GrPixelConfig; 248 platformTextureDescription.fConfig = kSkia8888_GrPixelConfig;
248 platformTextureDescription.fTextureHandle = textureId; 249 platformTextureDescription.fTextureHandle = textureId;
249 SkAutoTUnref<GrTexture> texture(grContext->createPlatformTexture(platfor mTextureDescription)); 250 skia::RefPtr<GrTexture> texture = skia::AdoptRef(grContext->createPlatfo rmTexture(platformTextureDescription));
250 // Place the platform texture inside an SkBitmap. 251 // Place the platform texture inside an SkBitmap.
251 m_source.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.heigh t()); 252 m_source.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.heigh t());
252 m_source.setPixelRef(new SkGrPixelRef(texture.get()))->unref(); 253 skia::RefPtr<SkGrPixelRef> pixelRef = skia::AdoptRef(new SkGrPixelRef(te xture.get()));
254 m_source.setPixelRef(pixelRef.get());
253 } 255 }
254 256
255 ~FilterBufferState() { } 257 ~FilterBufferState() { }
256 258
257 bool init(int filterCount) 259 bool init(int filterCount)
258 { 260 {
259 int scratchCount = std::min(2, filterCount); 261 int scratchCount = std::min(2, filterCount);
260 GrTextureDesc desc; 262 GrTextureDesc desc;
261 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagB it; 263 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagB it;
262 desc.fSampleCnt = 0; 264 desc.fSampleCnt = 0;
263 desc.fWidth = m_source.width(); 265 desc.fWidth = m_source.width();
264 desc.fHeight = m_source.height(); 266 desc.fHeight = m_source.height();
265 desc.fConfig = kSkia8888_GrPixelConfig; 267 desc.fConfig = kSkia8888_GrPixelConfig;
266 for (int i = 0; i < scratchCount; ++i) { 268 for (int i = 0; i < scratchCount; ++i) {
267 GrAutoScratchTexture scratchTexture(m_grContext, desc, GrContext::kE xact_ScratchTexMatch); 269 GrAutoScratchTexture scratchTexture(m_grContext, desc, GrContext::kE xact_ScratchTexMatch);
268 m_scratchTextures[i].reset(scratchTexture.detach()); 270 m_scratchTextures[i] = skia::AdoptRef(scratchTexture.detach());
269 if (!m_scratchTextures[i].get()) 271 if (!m_scratchTextures[i])
270 return false; 272 return false;
271 } 273 }
272 return true; 274 return true;
273 } 275 }
274 276
275 SkCanvas* canvas() 277 SkCanvas* canvas()
276 { 278 {
277 if (!m_canvas.get()) 279 if (!m_canvas.get())
278 createCanvas(); 280 createCanvas();
279 return m_canvas.get(); 281 return m_canvas.get();
280 } 282 }
281 283
282 const SkBitmap& source() { return m_source; } 284 const SkBitmap& source() { return m_source; }
283 285
284 void swap() 286 void swap()
285 { 287 {
286 m_canvas->flush(); 288 m_canvas->flush();
287 m_canvas.reset(0); 289 m_canvas.clear();
288 m_device.reset(0); 290 m_device.clear();
289 291
290 m_source.setPixelRef(new SkGrPixelRef(m_scratchTextures[m_currentTexture ].get()))->unref(); 292 skia::RefPtr<SkGrPixelRef> pixelRef = skia::AdoptRef(new SkGrPixelRef(m_ scratchTextures[m_currentTexture].get()));
293 m_source.setPixelRef(pixelRef.get());
291 m_currentTexture = 1 - m_currentTexture; 294 m_currentTexture = 1 - m_currentTexture;
292 } 295 }
293 296
294 private: 297 private:
295 void createCanvas() 298 void createCanvas()
296 { 299 {
297 DCHECK(m_scratchTextures[m_currentTexture].get()); 300 DCHECK(m_scratchTextures[m_currentTexture].get());
298 m_device.reset(new SkGpuDevice(m_grContext, m_scratchTextures[m_currentT exture].get())); 301 m_device = skia::AdoptRef(new SkGpuDevice(m_grContext, m_scratchTextures [m_currentTexture].get()));
299 m_canvas.reset(new SkCanvas(m_device.get())); 302 m_canvas = skia::AdoptRef(new SkCanvas(m_device.get()));
300 m_canvas->clear(0x0); 303 m_canvas->clear(0x0);
301 } 304 }
302 305
303 GrContext* m_grContext; 306 GrContext* m_grContext;
304 SkBitmap m_source; 307 SkBitmap m_source;
305 SkAutoTUnref<GrTexture> m_scratchTextures[2]; 308 skia::RefPtr<GrTexture> m_scratchTextures[2];
306 int m_currentTexture; 309 int m_currentTexture;
307 SkAutoTUnref<SkGpuDevice> m_device; 310 skia::RefPtr<SkGpuDevice> m_device;
308 SkAutoTUnref<SkCanvas> m_canvas; 311 skia::RefPtr<SkCanvas> m_canvas;
309 }; 312 };
310 313
311 } // namespace 314 } // namespace
312 315
313 WebKit::WebFilterOperations RenderSurfaceFilters::optimize(const WebKit::WebFilt erOperations& filters) 316 WebKit::WebFilterOperations RenderSurfaceFilters::optimize(const WebKit::WebFilt erOperations& filters)
314 { 317 {
315 WebKit::WebFilterOperations newList; 318 WebKit::WebFilterOperations newList;
316 319
317 SkScalar accumulatedColorMatrix[20]; 320 SkScalar accumulatedColorMatrix[20];
318 bool haveAccumulatedColorMatrix = false; 321 bool haveAccumulatedColorMatrix = false;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 FilterBufferState state(grContext, size, textureId); 377 FilterBufferState state(grContext, size, textureId);
375 if (!state.init(optimizedFilters.size())) 378 if (!state.init(optimizedFilters.size()))
376 return SkBitmap(); 379 return SkBitmap();
377 380
378 for (unsigned i = 0; i < optimizedFilters.size(); ++i) { 381 for (unsigned i = 0; i < optimizedFilters.size(); ++i) {
379 const WebKit::WebFilterOperation& op = optimizedFilters.at(i); 382 const WebKit::WebFilterOperation& op = optimizedFilters.at(i);
380 SkCanvas* canvas = state.canvas(); 383 SkCanvas* canvas = state.canvas();
381 switch (op.type()) { 384 switch (op.type()) {
382 case WebKit::WebFilterOperation::FilterTypeColorMatrix: { 385 case WebKit::WebFilterOperation::FilterTypeColorMatrix: {
383 SkPaint paint; 386 SkPaint paint;
384 paint.setColorFilter(new SkColorMatrixFilter(op.matrix()))->unref(); 387 skia::RefPtr<SkColorMatrixFilter> filter = skia::AdoptRef(new SkColo rMatrixFilter(op.matrix()));
388 paint.setColorFilter(filter.get());
385 canvas->drawBitmap(state.source(), 0, 0, &paint); 389 canvas->drawBitmap(state.source(), 0, 0, &paint);
386 break; 390 break;
387 } 391 }
388 case WebKit::WebFilterOperation::FilterTypeBlur: { 392 case WebKit::WebFilterOperation::FilterTypeBlur: {
389 float stdDeviation = op.amount(); 393 float stdDeviation = op.amount();
390 SkAutoTUnref<SkImageFilter> filter(new SkBlurImageFilter(stdDeviatio n, stdDeviation)); 394 skia::RefPtr<SkImageFilter> filter = skia::AdoptRef(new SkBlurImageF ilter(stdDeviation, stdDeviation));
391 SkPaint paint; 395 SkPaint paint;
392 paint.setImageFilter(filter.get()); 396 paint.setImageFilter(filter.get());
393 canvas->drawSprite(state.source(), 0, 0, &paint); 397 canvas->drawSprite(state.source(), 0, 0, &paint);
394 break; 398 break;
395 } 399 }
396 case WebKit::WebFilterOperation::FilterTypeDropShadow: { 400 case WebKit::WebFilterOperation::FilterTypeDropShadow: {
397 SkAutoTUnref<SkImageFilter> blurFilter(new SkBlurImageFilter(op.amou nt(), op.amount())); 401 skia::RefPtr<SkImageFilter> blurFilter = skia::AdoptRef(new SkBlurIm ageFilter(op.amount(), op.amount()));
398 SkAutoTUnref<SkColorFilter> colorFilter(SkColorFilter::CreateModeFil ter(op.dropShadowColor(), SkXfermode::kSrcIn_Mode)); 402 skia::RefPtr<SkColorFilter> colorFilter = skia::AdoptRef(SkColorFilt er::CreateModeFilter(op.dropShadowColor(), SkXfermode::kSrcIn_Mode));
399 SkPaint paint; 403 SkPaint paint;
400 paint.setImageFilter(blurFilter.get()); 404 paint.setImageFilter(blurFilter.get());
401 paint.setColorFilter(colorFilter.get()); 405 paint.setColorFilter(colorFilter.get());
402 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); 406 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
403 canvas->saveLayer(0, &paint); 407 canvas->saveLayer(0, &paint);
404 canvas->drawBitmap(state.source(), op.dropShadowOffset().x, -op.drop ShadowOffset().y); 408 canvas->drawBitmap(state.source(), op.dropShadowOffset().x, -op.drop ShadowOffset().y);
405 canvas->restore(); 409 canvas->restore();
406 canvas->drawBitmap(state.source(), 0, 0); 410 canvas->drawBitmap(state.source(), 0, 0);
407 break; 411 break;
408 } 412 }
409 case WebKit::WebFilterOperation::FilterTypeZoom: { 413 case WebKit::WebFilterOperation::FilterTypeZoom: {
410 SkPaint paint; 414 SkPaint paint;
411 SkAutoTUnref<SkImageFilter> zoomFilter( 415 skia::RefPtr<SkImageFilter> zoomFilter = skia::AdoptRef(
412 new SkMagnifierImageFilter( 416 new SkMagnifierImageFilter(
413 SkRect::MakeXYWH(op.zoomRect().x, 417 SkRect::MakeXYWH(op.zoomRect().x,
414 op.zoomRect().y, 418 op.zoomRect().y,
415 op.zoomRect().width, 419 op.zoomRect().width,
416 op.zoomRect().height), 420 op.zoomRect().height),
417 op.amount())); 421 op.amount()));
418 paint.setImageFilter(zoomFilter.get()); 422 paint.setImageFilter(zoomFilter.get());
419 canvas->saveLayer(0, &paint); 423 canvas->saveLayer(0, &paint);
420 canvas->drawBitmap(state.source(), 0, 0); 424 canvas->drawBitmap(state.source(), 0, 0);
421 canvas->restore(); 425 canvas->restore();
(...skipping 10 matching lines...) Expand all
432 NOTREACHED(); 436 NOTREACHED();
433 break; 437 break;
434 } 438 }
435 state.swap(); 439 state.swap();
436 } 440 }
437 context3D->flush(); 441 context3D->flush();
438 return state.source(); 442 return state.source();
439 } 443 }
440 444
441 } // namespace cc 445 } // namespace cc
OLDNEW
« no previous file with comments | « cc/render_pass_unittest.cc ('k') | cc/render_surface_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698