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

Side by Side Diff: Source/core/platform/graphics/Canvas2DLayerBridge.cpp

Issue 104023007: Refactoring ImageBuffer to decouple it from Canvas2DLayerBridge (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: build fixes for win+mac Created 7 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 /* 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 25 matching lines...) Expand all
36 #include "platform/TraceEvent.h" 36 #include "platform/TraceEvent.h"
37 #include "public/platform/Platform.h" 37 #include "public/platform/Platform.h"
38 #include "public/platform/WebCompositorSupport.h" 38 #include "public/platform/WebCompositorSupport.h"
39 #include "public/platform/WebGraphicsContext3D.h" 39 #include "public/platform/WebGraphicsContext3D.h"
40 40
41 using blink::WebExternalTextureLayer; 41 using blink::WebExternalTextureLayer;
42 using blink::WebGraphicsContext3D; 42 using blink::WebGraphicsContext3D;
43 43
44 namespace WebCore { 44 namespace WebCore {
45 45
46 void Canvas2DLayerBridgePtr::clear()
47 {
48 if (m_ptr) {
49 m_ptr->destroy();
50 m_ptr.clear();
51 }
52 }
53
54 Canvas2DLayerBridgePtr& Canvas2DLayerBridgePtr::operator=(const PassRefPtr<Canva s2DLayerBridge>& other)
55 {
56 clear();
57 m_ptr = other;
58 return *this;
59 }
60
61 static SkSurface* createSurface(GraphicsContext3D* context3D, const IntSize& siz e, int msaaSampleCount) 46 static SkSurface* createSurface(GraphicsContext3D* context3D, const IntSize& siz e, int msaaSampleCount)
62 { 47 {
63 ASSERT(!context3D->webContext()->isContextLost()); 48 ASSERT(!context3D->webContext()->isContextLost());
64 GrContext* gr = context3D->grContext(); 49 GrContext* gr = context3D->grContext();
65 if (!gr) 50 if (!gr)
66 return 0; 51 return 0;
67 gr->resetContext(); 52 gr->resetContext();
68 SkImageInfo info; 53 SkImageInfo info;
69 info.fWidth = size.width(); 54 info.fWidth = size.width();
70 info.fHeight = size.height(); 55 info.fHeight = size.height();
71 info.fColorType = kPMColor_SkColorType; 56 info.fColorType = kPMColor_SkColorType;
72 info.fAlphaType = kPremul_SkAlphaType; 57 info.fAlphaType = kPremul_SkAlphaType;
73 return SkSurface::NewRenderTarget(gr, info, msaaSampleCount); 58 return SkSurface::NewRenderTarget(gr, info, msaaSampleCount);
74 } 59 }
75 60
76 PassRefPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(PassRefPtr<GraphicsC ontext3D> context, const IntSize& size, OpacityMode opacityMode, int msaaSampleC ount) 61 PassRefPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(const IntSize& size, OpacityMode opacityMode, int msaaSampleCount)
77 { 62 {
78 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation"); 63 TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation");
79 SkAutoTUnref<SkSurface> surface(createSurface(context.get(), size, msaaSampl eCount)); 64 RefPtr<GraphicsContext3D> context = SharedGraphicsContext3D::get();
80 if (!surface.get()) { 65 RefPtr<SkSurface> surface(createSurface(context.get(), size, msaaSampleCount ));
Stephen White 2013/12/04 21:18:40 Maybe createSurface() should be renamed createSkSu
81 return PassRefPtr<Canvas2DLayerBridge>(); 66 RefPtr<Canvas2DLayerBridge> layerBridge;
67 if (surface) {
68 OwnPtr<SkDeferredCanvas> canvas = adoptPtr(SkDeferredCanvas::Create(surf ace.get()));
69 layerBridge = adoptRef(new Canvas2DLayerBridge(context, canvas.release() , msaaSampleCount, opacityMode));
82 } 70 }
83 RefPtr<SkDeferredCanvas> canvas = adoptRef(SkDeferredCanvas::Create(surface. get()));
84 RefPtr<Canvas2DLayerBridge> layerBridge = adoptRef(new Canvas2DLayerBridge(c ontext, canvas.release(), msaaSampleCount, opacityMode));
85 return layerBridge.release(); 71 return layerBridge.release();
86 } 72 }
87 73
88 Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, PassRefPtr<SkDeferredCanvas> canvas, int msaaSampleCount, OpacityMode opacityMod e) 74 Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, PassOwnPtr<SkDeferredCanvas> canvas, int msaaSampleCount, OpacityMode opacityMod e)
89 : m_canvas(canvas) 75 : m_canvas(canvas)
90 , m_context(context) 76 , m_context(context)
91 , m_msaaSampleCount(msaaSampleCount) 77 , m_msaaSampleCount(msaaSampleCount)
92 , m_bytesAllocated(0) 78 , m_bytesAllocated(0)
93 , m_didRecordDrawCommand(false) 79 , m_didRecordDrawCommand(false)
94 , m_surfaceIsValid(true) 80 , m_surfaceIsValid(true)
95 , m_framesPending(0) 81 , m_framesPending(0)
96 , m_destructionInProgress(false) 82 , m_destructionInProgress(false)
97 , m_rateLimitingEnabled(false) 83 , m_rateLimitingEnabled(false)
98 , m_next(0) 84 , m_next(0)
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 // Trigger Canvas2DLayerBridge self-destruction if this is the 364 // Trigger Canvas2DLayerBridge self-destruction if this is the
379 // last live mailbox and the layer bridge is not externally 365 // last live mailbox and the layer bridge is not externally
380 // referenced. 366 // referenced.
381 ASSERT(mailboxInfo->m_parentLayerBridge.get() == this); 367 ASSERT(mailboxInfo->m_parentLayerBridge.get() == this);
382 mailboxInfo->m_parentLayerBridge.clear(); 368 mailboxInfo->m_parentLayerBridge.clear();
383 return; 369 return;
384 } 370 }
385 } 371 }
386 } 372 }
387 373
388 blink::WebLayer* Canvas2DLayerBridge::layer() 374 blink::WebLayer* Canvas2DLayerBridge::layer() const
389 { 375 {
390 ASSERT(m_layer); 376 ASSERT(m_layer);
391 return m_layer->layer(); 377 return m_layer->layer();
392 } 378 }
393 379
394 void Canvas2DLayerBridge::contextAcquired() 380 void Canvas2DLayerBridge::aboutToUse()
395 { 381 {
396 ASSERT(!m_destructionInProgress); 382 ASSERT(!m_destructionInProgress);
397 Canvas2DLayerManager::get().layerDidDraw(this); 383 Canvas2DLayerManager::get().layerDidDraw(this);
398 m_didRecordDrawCommand = true; 384 m_didRecordDrawCommand = true;
399 } 385 }
400 386
401 unsigned Canvas2DLayerBridge::backBufferTexture() 387 Platform3DObject Canvas2DLayerBridge::getBackingTexture()
402 { 388 {
403 ASSERT(!m_destructionInProgress); 389 ASSERT(!m_destructionInProgress);
404 if (!isValid()) 390 if (!isValid())
405 return 0; 391 return 0;
406 contextAcquired(); 392 aboutToUse();
407 m_canvas->flush(); 393 m_canvas->flush();
408 m_context->flush(); 394 m_context->flush();
409 GrRenderTarget* renderTarget = reinterpret_cast<GrRenderTarget*>(m_canvas->g etDevice()->accessRenderTarget()); 395 GrRenderTarget* renderTarget = m_canvas->getTopDevice()->accessRenderTarget( );
410 if (renderTarget) { 396 if (renderTarget) {
411 return renderTarget->asTexture()->getTextureHandle(); 397 return renderTarget->asTexture()->getTextureHandle();
412 } 398 }
413 return 0; 399 return 0;
414 } 400 }
415 401
416 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) { 402 Canvas2DLayerBridge::MailboxInfo::MailboxInfo(const MailboxInfo& other) {
417 // This copy constructor should only be used for Vector reallocation 403 // This copy constructor should only be used for Vector reallocation
418 // Assuming 'other' is to be destroyed, we swap m_image ownership 404 // Assuming 'other' is to be destroyed, we swap m_image ownership
419 // rather than do a refcount dance. 405 // rather than do a refcount dance.
420 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox)); 406 memcpy(&m_mailbox, &other.m_mailbox, sizeof(m_mailbox));
421 m_image.swap(const_cast<SkAutoTUnref<SkImage>*>(&other.m_image)); 407 m_image.swap(const_cast<SkAutoTUnref<SkImage>*>(&other.m_image));
422 m_status = other.m_status; 408 m_status = other.m_status;
423 } 409 }
424 410
425 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698