| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 Canvas2DLayerBridgePtr& Canvas2DLayerBridgePtr::operator=(const PassRefPtr<Canva
s2DLayerBridge>& other) | 55 Canvas2DLayerBridgePtr& Canvas2DLayerBridgePtr::operator=(const PassRefPtr<Canva
s2DLayerBridge>& other) |
| 56 { | 56 { |
| 57 clear(); | 57 clear(); |
| 58 m_ptr = other; | 58 m_ptr = other; |
| 59 return *this; | 59 return *this; |
| 60 } | 60 } |
| 61 | 61 |
| 62 static SkSurface* createSurface(GraphicsContext3D* context3D, const IntSize& siz
e) | 62 static SkSurface* createSurface(GraphicsContext3D* context3D, const IntSize& siz
e, int msaaSampleCount) |
| 63 { | 63 { |
| 64 ASSERT(!context3D->webContext()->isContextLost()); | 64 ASSERT(!context3D->webContext()->isContextLost()); |
| 65 GrContext* gr = context3D->grContext(); | 65 GrContext* gr = context3D->grContext(); |
| 66 if (!gr) | 66 if (!gr) |
| 67 return 0; | 67 return 0; |
| 68 gr->resetContext(); | 68 gr->resetContext(); |
| 69 SkImage::Info info; | 69 SkImage::Info info; |
| 70 info.fWidth = size.width(); | 70 info.fWidth = size.width(); |
| 71 info.fHeight = size.height(); | 71 info.fHeight = size.height(); |
| 72 info.fColorType = SkImage::kPMColor_ColorType; | 72 info.fColorType = SkImage::kPMColor_ColorType; |
| 73 info.fAlphaType = kPremul_SkAlphaType; | 73 info.fAlphaType = kPremul_SkAlphaType; |
| 74 return SkSurface::NewRenderTarget(gr, info); | 74 return SkSurface::NewRenderTarget(gr, info, msaaSampleCount); |
| 75 } | 75 } |
| 76 | 76 |
| 77 PassRefPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(PassRefPtr<GraphicsC
ontext3D> context, const IntSize& size, OpacityMode opacityMode) | 77 PassRefPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(PassRefPtr<GraphicsC
ontext3D> context, const IntSize& size, OpacityMode opacityMode, int msaaSampleC
ount) |
| 78 { | 78 { |
| 79 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); | 79 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); |
| 80 SkAutoTUnref<SkSurface> surface(createSurface(context.get(), size)); | 80 SkAutoTUnref<SkSurface> surface(createSurface(context.get(), size, msaaSampl
eCount)); |
| 81 if (!surface.get()) { | 81 if (!surface.get()) { |
| 82 return PassRefPtr<Canvas2DLayerBridge>(); | 82 return PassRefPtr<Canvas2DLayerBridge>(); |
| 83 } | 83 } |
| 84 RefPtr<SkDeferredCanvas> canvas = adoptRef(SkDeferredCanvas::Create(surface.
get())); | 84 RefPtr<SkDeferredCanvas> canvas = adoptRef(SkDeferredCanvas::Create(surface.
get())); |
| 85 RefPtr<Canvas2DLayerBridge> layerBridge = adoptRef(new Canvas2DLayerBridge(c
ontext, canvas.release(), opacityMode)); | 85 RefPtr<Canvas2DLayerBridge> layerBridge = adoptRef(new Canvas2DLayerBridge(c
ontext, canvas.release(), opacityMode)); |
| 86 return layerBridge.release(); | 86 return layerBridge.release(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context,
PassRefPtr<SkDeferredCanvas> canvas, OpacityMode opacityMode) | 89 Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context,
PassRefPtr<SkDeferredCanvas> canvas, OpacityMode opacityMode) |
| 90 : m_canvas(canvas) | 90 : m_canvas(canvas) |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 if (m_context->webContext()->isContextLost() || !m_surfaceIsValid) { | 250 if (m_context->webContext()->isContextLost() || !m_surfaceIsValid) { |
| 251 // Attempt to recover. | 251 // Attempt to recover. |
| 252 m_layer->clearTexture(); | 252 m_layer->clearTexture(); |
| 253 m_mailboxes.clear(); | 253 m_mailboxes.clear(); |
| 254 RefPtr<GraphicsContext3D> sharedContext = SharedGraphicsContext3D::get()
; | 254 RefPtr<GraphicsContext3D> sharedContext = SharedGraphicsContext3D::get()
; |
| 255 if (!sharedContext || sharedContext->webContext()->isContextLost()) { | 255 if (!sharedContext || sharedContext->webContext()->isContextLost()) { |
| 256 m_surfaceIsValid = false; | 256 m_surfaceIsValid = false; |
| 257 } else { | 257 } else { |
| 258 m_context = sharedContext; | 258 m_context = sharedContext; |
| 259 IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevi
ce()->height()); | 259 IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevi
ce()->height()); |
| 260 SkAutoTUnref<SkSurface> surface(createSurface(m_context.get(), size)
); | 260 int msaaSampleCount = m_canvas->getTopDevice()->accessRenderTarget()
->desc().fSampleCnt; |
| 261 SkAutoTUnref<SkSurface> surface(createSurface(m_context.get(), size,
msaaSampleCount)); |
| 261 if (surface.get()) { | 262 if (surface.get()) { |
| 262 m_canvas->setSurface(surface.get()); | 263 m_canvas->setSurface(surface.get()); |
| 263 m_surfaceIsValid = true; | 264 m_surfaceIsValid = true; |
| 264 // FIXME: draw sad canvas picture into new buffer crbug.com/2438
42 | 265 // FIXME: draw sad canvas picture into new buffer crbug.com/2438
42 |
| 265 } else { | 266 } else { |
| 266 // Surface allocation failed. Set m_surfaceIsValid to false to | 267 // Surface allocation failed. Set m_surfaceIsValid to false to |
| 267 // trigger subsequent retry. | 268 // trigger subsequent retry. |
| 268 m_surfaceIsValid = false; | 269 m_surfaceIsValid = false; |
| 269 } | 270 } |
| 270 } | 271 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { | 417 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { |
| 417 // This copy constructor should only be used for Vector reallocation | 418 // This copy constructor should only be used for Vector reallocation |
| 418 // Assuming 'other' is to be destroyed, we swap m_image ownership | 419 // Assuming 'other' is to be destroyed, we swap m_image ownership |
| 419 // rather than do a refcount dance. | 420 // rather than do a refcount dance. |
| 420 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); | 421 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); |
| 421 m_image.swap(const_cast<SkAutoTUnref<SkImage>*>(&other.m_image)); | 422 m_image.swap(const_cast<SkAutoTUnref<SkImage>*>(&other.m_image)); |
| 422 m_status = other.m_status; | 423 m_status = other.m_status; |
| 423 } | 424 } |
| 424 | 425 |
| 425 } | 426 } |
| OLD | NEW |