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

Side by Side Diff: cc/render_surface_filters.cc

Issue 11418217: Add skia::RefPtr class to wrap ref counted classes from Skia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Drop TNoRef 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
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(grContext->createPlatformTexture(platfor mTextureDescription));
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 = new SkGrPixelRef(texture.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;
(...skipping 17 matching lines...) Expand all
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.reset(0);
288 m_device.reset(0); 290 m_device.reset(0);
289 291
290 m_source.setPixelRef(new SkGrPixelRef(m_scratchTextures[m_currentTexture ].get()))->unref(); 292 skia::RefPtr<SkGrPixelRef> pixelRef = 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.reset(new SkGpuDevice(m_grContext, m_scratchTextures[m_currentT exture].get()));
299 m_canvas.reset(new SkCanvas(m_device.get())); 302 m_canvas.reset(new SkCanvas(m_device.get()));
300 m_canvas->clear(0x0); 303 m_canvas->clear(0x0);
(...skipping 73 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 = new SkColorMatrixFilter(o p.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 SkAutoTUnref<SkImageFilter> filter(new SkBlurImageFilter(stdDeviatio n, 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;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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') | skia/ext/refptr.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698